mirror of
https://github.com/kubescape/kubescape.git
synced 2026-02-14 09:59:54 +00:00
adding smoke tests
This commit is contained in:
15
smoke_testing/init.py
Normal file
15
smoke_testing/init.py
Normal 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()
|
||||
30
smoke_testing/smoke_utils.py
Normal file
30
smoke_testing/smoke_utils.py
Normal 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)
|
||||
|
||||
31
smoke_testing/test_command.py
Normal file
31
smoke_testing/test_command.py
Normal 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()
|
||||
27
smoke_testing/test_version.py
Normal file
27
smoke_testing/test_version.py
Normal 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()
|
||||
Reference in New Issue
Block a user