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:
5
.github/workflows/build.yaml
vendored
5
.github/workflows/build.yaml
vendored
@@ -46,6 +46,11 @@ jobs:
|
||||
CGO_ENABLED: 0
|
||||
run: python3 --version && python3 build.py
|
||||
|
||||
- name: Smoke Testing
|
||||
env:
|
||||
RELEASE: v1.0.${{ github.run_number }}
|
||||
run: python3 smoke_testing/init.py
|
||||
|
||||
- name: Upload Release binaries
|
||||
id: upload-release-asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
|
||||
6
.github/workflows/build_dev.yaml
vendored
6
.github/workflows/build_dev.yaml
vendored
@@ -30,6 +30,12 @@ jobs:
|
||||
CGO_ENABLED: 0
|
||||
run: python3 --version && python3 build.py
|
||||
|
||||
- name: Smoke Testing
|
||||
env:
|
||||
RELEASE: v1.0.${{ github.run_number }}
|
||||
KUBESCAPE_SKIP_UPDATE_CHECK: "true"
|
||||
run: python3 smoke_testing/init.py
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
|
||||
13
build.py
13
build.py
@@ -60,9 +60,6 @@ def main():
|
||||
status = subprocess.call(["go", "build", "-o", "%s/%s" % (buildDir, packageName), "-ldflags" ,ldflags])
|
||||
checkStatus(status, "Failed to build kubescape")
|
||||
|
||||
test_cli_prints(buildDir,packageName)
|
||||
|
||||
|
||||
sha1 = hashlib.sha1()
|
||||
with open(buildDir + "/" + packageName, "rb") as kube:
|
||||
sha1.update(kube.read())
|
||||
@@ -70,13 +67,7 @@ def main():
|
||||
kube_sha.write(sha1.hexdigest())
|
||||
|
||||
print("Build Done")
|
||||
|
||||
def test_cli_prints(buildDir,packageName):
|
||||
bin_cli = os.path.abspath(os.path.join(buildDir,packageName))
|
||||
|
||||
print(f"testing CLI prints on {bin_cli}")
|
||||
status = str(subprocess.check_output([bin_cli, "-h"]))
|
||||
assert "download" in status, "download is missing: " + status
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
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