From ae7810f0d39c6e8c5cb7c0883818a6de7c550c46 Mon Sep 17 00:00:00 2001 From: dwertent Date: Mon, 1 Nov 2021 11:44:07 +0200 Subject: [PATCH] support input from file --- .github/workflows/build.yaml | 2 +- .github/workflows/build_dev.yaml | 2 +- .gitignore | 1 + smoke_testing/init.py | 9 ++++++--- smoke_testing/smoke_utils.py | 4 ++++ smoke_testing/test_command.py | 20 ++++++++++---------- smoke_testing/test_version.py | 7 ++++--- 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index bf538710..6b3b76dc 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -50,7 +50,7 @@ jobs: env: RELEASE: v1.0.${{ github.run_number }} KUBESCAPE_SKIP_UPDATE_CHECK: "true" - run: python3 smoke_testing/init.py + run: python3 smoke_testing/init.py ${PWD}/build/${{ matrix.os }}/kubescape - name: Upload Release binaries id: upload-release-asset diff --git a/.github/workflows/build_dev.yaml b/.github/workflows/build_dev.yaml index 8f5f552d..eff77b8b 100644 --- a/.github/workflows/build_dev.yaml +++ b/.github/workflows/build_dev.yaml @@ -34,7 +34,7 @@ jobs: env: RELEASE: v1.0.${{ github.run_number }} KUBESCAPE_SKIP_UPDATE_CHECK: "true" - run: python3 smoke_testing/init.py + run: python3 smoke_testing/init.py ${PWD}/build/${{ matrix.os }}/kubescape - name: Upload build artifacts uses: actions/upload-artifact@v2 diff --git a/.gitignore b/.gitignore index bf33394d..3c3ed147 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ *kubescape* *debug* *vender* +*.pyc* .idea \ No newline at end of file diff --git a/smoke_testing/init.py b/smoke_testing/init.py index e1a5e1f5..3f88c756 100644 --- a/smoke_testing/init.py +++ b/smoke_testing/init.py @@ -1,3 +1,6 @@ +import sys +import smoke_utils + tests_pkg = [ "test_command" @@ -5,11 +8,11 @@ tests_pkg = [ ] -def run(): +def run(**kwargs): for i in tests_pkg: m = __import__(i) - m.run() + m.run(**kwargs) if __name__ == "__main__": - run() + run(kubescape_exec=smoke_utils.get_exec_from_args(sys.argv)) diff --git a/smoke_testing/smoke_utils.py b/smoke_testing/smoke_utils.py index 93b9eeac..528193a7 100644 --- a/smoke_testing/smoke_utils.py +++ b/smoke_testing/smoke_utils.py @@ -28,3 +28,7 @@ def check_status(status, msg): stderr.write(msg) exit(status) + +def get_exec_from_args(args: list): + return args[1] + diff --git a/smoke_testing/test_command.py b/smoke_testing/test_command.py index 1bd7b587..43277e5f 100644 --- a/smoke_testing/test_command.py +++ b/smoke_testing/test_command.py @@ -1,5 +1,6 @@ import subprocess import smoke_utils +import sys def test_command(command: list): @@ -12,20 +13,19 @@ def test_command(command: list): print(f"Done testing \"{' '.join(command[1:])}\" command") -def run(): +def run(kubescape_exec:str): 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"]) + test_command(command=[kubescape_exec, "version"]) + test_command(command=[kubescape_exec, "download"]) + test_command(command=[kubescape_exec, "config"]) + test_command(command=[kubescape_exec, "help"]) + test_command(command=[kubescape_exec, "scan"]) + test_command(command=[kubescape_exec, "scan", "framework"]) + test_command(command=[kubescape_exec, "scan", "control"]) print("Done testing commands") if __name__ == "__main__": - run() + run(kubescape_exec=smoke_utils.get_exec_from_args(sys.argv)) diff --git a/smoke_testing/test_version.py b/smoke_testing/test_version.py index 739e3784..689e3934 100644 --- a/smoke_testing/test_version.py +++ b/smoke_testing/test_version.py @@ -1,17 +1,18 @@ import os import subprocess import smoke_utils +import sys -def run(): +def run(kubescape_exec:str): print("Testing version") ver = os.getenv("RELEASE") - msg = str(subprocess.check_output([smoke_utils.get_bin_cli(), "version"])) + msg = str(subprocess.check_output([kubescape_exec, "version"])) assert ver in msg, f"expected version: {ver}, found: {msg}" print("Done testing version") if __name__ == "__main__": - run() + run(kubescape_exec=smoke_utils.get_exec_from_args(sys.argv))