diff --git a/smoke_testing/smoke_utils.py b/smoke_testing/smoke_utils.py index 528193a7..3a3fda9f 100644 --- a/smoke_testing/smoke_utils.py +++ b/smoke_testing/smoke_utils.py @@ -1,34 +1,14 @@ -import platform -from os import path from sys import stderr - - -def get_build_dir(): - current_platform = platform.system() - build_dir = "build/" - - if current_platform == "Windows": build_dir += "windows-latest" - elif current_platform == "Linux": build_dir += "ubuntu-latest" - elif current_platform == "Darwin": build_dir += "macos-latest" - else: raise OSError(f"Platform {current_platform} is not supported!") - - return build_dir - - -def get_package_name(): - return "kubescape" - - -def get_bin_cli(): - return path.abspath(path.join(get_build_dir(), get_package_name())) - - -def check_status(status, msg): - if status != 0: - stderr.write(msg) - exit(status) +import subprocess def get_exec_from_args(args: list): return args[1] + +def run_command(command): + try: + return str(subprocess.check_output(command)) + except Exception as e: + return e + diff --git a/smoke_testing/test_command.py b/smoke_testing/test_command.py index 43277e5f..20be67ea 100644 --- a/smoke_testing/test_command.py +++ b/smoke_testing/test_command.py @@ -1,4 +1,3 @@ -import subprocess import smoke_utils import sys @@ -6,7 +5,7 @@ import sys def test_command(command: list): print(f"Testing \"{' '.join(command[1:])}\" command") - msg = str(subprocess.check_output(command)) + msg = smoke_utils.run_command(command) assert "unknown command" not in msg, f"{command[1:]} is missing: {msg}" assert "invalid parameter" not in msg, f"{command[1:]} is invalid: {msg}" diff --git a/smoke_testing/test_version.py b/smoke_testing/test_version.py index 689e3934..2092abeb 100644 --- a/smoke_testing/test_version.py +++ b/smoke_testing/test_version.py @@ -4,11 +4,11 @@ import smoke_utils import sys -def run(kubescape_exec:str): +def run(kubescape_exec: str): print("Testing version") ver = os.getenv("RELEASE") - msg = str(subprocess.check_output([kubescape_exec, "version"])) + msg = smoke_utils.run_command(command=[kubescape_exec, "version"]) assert ver in msg, f"expected version: {ver}, found: {msg}" print("Done testing version")