Skip to content

Commit

Permalink
test: add some checks
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoparker committed Jan 15, 2019
1 parent e43d317 commit 3a35b62
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions tests/system_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
]

binaries_must_be_installed = [
'jq',
'dialog',
'dnsmasq',
'git',
Expand All @@ -52,6 +53,11 @@
'/usr/local/etc/ncp-version',
]

files_must_not_exist = [
'/.ncp-image',
]


class tc:
"terminal colors"
brown='\033[33m'
Expand Down Expand Up @@ -84,6 +90,16 @@ def file_exists(file):
print(tc.red + "error" + tc.normal)
return result.returncode == 0

def file_not_exists(file):
"check that a file doesn't exist"
print("[nexists] " + tc.brown + "{:16}".format(file) + tc.normal, end=' ')
result = run(pre_cmd + ['test', '-f', file], stdout=PIPE, stderr=PIPE)
if result.returncode != 0:
print(tc.green + "ok" + tc.normal)
else:
print(tc.red + "error" + tc.normal)
return result.returncode == 0

def check_processes_running(processes):
"check that all processes are running"
ret = True
Expand Down Expand Up @@ -118,6 +134,14 @@ def check_files_exist(files):
ret = False
return ret

def check_files_dont_exist(files):
"check that all the files don't exist"
ret = True
for file in files:
if file_not_exists(file):
ret = False
return ret

def signal_handler(sig, frame):
sys.exit(0)

Expand Down Expand Up @@ -194,9 +218,10 @@ def signal_handler(sig, frame):
print("-------------------------")
running_result = check_processes_running(processes_must_be_running)
install_result = check_binaries_installed(binaries_must_be_installed)
files_result = check_files_exist(files_must_exist)
files1_result = check_files_exist(files_must_exist)
files2_result = check_files_dont_exist(files_must_not_exist)

if running_result and install_result and files_result:
if running_result and install_result and files1_result and files2_result:
sys.exit(0)
else:
sys.exit(1)
Expand Down

0 comments on commit 3a35b62

Please sign in to comment.