adding smoke tests

This commit is contained in:
dwertent
2021-10-31 15:05:22 +02:00
parent 9fd2bf3480
commit 959b25e8b7
7 changed files with 116 additions and 11 deletions

15
smoke_testing/init.py Normal file
View File

@@ -0,0 +1,15 @@
tests_pkg = [
"test_command"
, "test_version"
]
def run():
for i in tests_pkg:
m = __import__(i)
m.run()
if __name__ == "__main__":
run()

View File

@@ -0,0 +1,30 @@
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)

View File

@@ -0,0 +1,31 @@
import subprocess
import smoke_utils
def test_command(command: list):
print(f"Testing \"{' '.join(command[1:])}\" command")
msg = str(subprocess.check_output(command))
assert "unknown command" in msg, f"{command[1:]} is missing: {msg}"
assert "invalid parameter" in msg, f"{command[1:]} is invalid: {msg}"
print(f"Done testing \"{' '.join(command[1:])}\" command")
def run():
print("Testing supported commands")
bin_cli = smoke_utils.get_bin_cli()
test_command(command=[bin_cli, "version"])
test_command(command=[bin_cli, "download"])
test_command(command=[bin_cli, "config"])
test_command(command=[bin_cli, "help"])
test_command(command=[bin_cli, "scan"])
test_command(command=[bin_cli, "scan", "framework"])
test_command(command=[bin_cli, "scan", "control"])
print("Done testing commands")
if __name__ == "__main__":
run()

View File

@@ -0,0 +1,27 @@
import os
import subprocess
import smoke_utils
def test_command(command: list):
print(f"Testing \"{' '.join(command[1:])}\" command")
msg = str(subprocess.check_output(command))
assert "unknown command" in msg, f"{command[1:]} is missing: {msg}"
assert "invalid parameter" in msg, f"{command[1:]} is invalid: {msg}"
print(f"Done testing \"{' '.join(command[1:])}\" command")
def run():
print("Testing version")
ver = os.getenv("RELEASE")
msg = str(subprocess.check_output([smoke_utils.get_bin_cli(), "version"]))
assert ver in msg, f"expected version: {ver}, found: {msg}"
print("Done testing version")
if __name__ == "__main__":
run()