From 95764b98d1eedee02509adeaebe8751471881fcb Mon Sep 17 00:00:00 2001 From: Toure Dunnon Date: Tue, 26 Jan 2021 19:45:22 -0500 Subject: [PATCH 1/3] Add a few more functional test. Signed-off-by: Toure Dunnon --- tests/functional/test_evaluate.py | 21 +++++++++++++++++ tests/functional/test_event.py | 18 +++++++++++++++ tests/functional/test_images.py | 33 +++++++++++++++++++++++++++ tests/functional/test_policy.py | 21 +++++++++++++++++ tests/functional/test_query.py | 15 ++++++++++++ tests/functional/test_registry.py | 0 tests/functional/test_repo.py | 0 tests/functional/test_subscription.py | 0 tests/functional/test_system.py | 31 +++++++++++++++++++++++++ 9 files changed, 139 insertions(+) create mode 100644 tests/functional/test_evaluate.py create mode 100644 tests/functional/test_event.py create mode 100644 tests/functional/test_images.py create mode 100644 tests/functional/test_policy.py create mode 100644 tests/functional/test_query.py create mode 100644 tests/functional/test_registry.py create mode 100644 tests/functional/test_repo.py create mode 100644 tests/functional/test_subscription.py create mode 100644 tests/functional/test_system.py diff --git a/tests/functional/test_evaluate.py b/tests/functional/test_evaluate.py new file mode 100644 index 0000000..a97ba2f --- /dev/null +++ b/tests/functional/test_evaluate.py @@ -0,0 +1,21 @@ +# evaluation datastructure [ {digest: { input_image: [ { detail: {}, last_eval: "", policyid: "", status: "" } ] } ] +import pytest +import json +from conftest import ExitCode + +input_image = "centos:latest" + + +@pytest.fixture +def eval_command(admin_call): + def apply(sub_command, flags): + out, err, code = admin_call(["--json", "evaluate", sub_command] + flags) + return out, err, code + + return apply + + +def test_check(eval_command): + res, err, code = eval_command("check", [input_image]) + result = json.loads(res) + print(result) diff --git a/tests/functional/test_event.py b/tests/functional/test_event.py new file mode 100644 index 0000000..748caa1 --- /dev/null +++ b/tests/functional/test_event.py @@ -0,0 +1,18 @@ +import pytest +import json + + +input_image = "alpine:latest" + + +@pytest.fixture +def event_command(admin_call): + def apply(sub_command, flags): + output, _, _ = admin_call(["--json", "event", sub_command] + flags) + return json.loads(output) + return apply + + +class TestEvents: + + def test_ diff --git a/tests/functional/test_images.py b/tests/functional/test_images.py new file mode 100644 index 0000000..ea463fa --- /dev/null +++ b/tests/functional/test_images.py @@ -0,0 +1,33 @@ +from conftest import call, ExitCode +import pytest +import json +import ipdb + + +input_image = "centos:latest" + + +@pytest.fixture +def image_command(admin_call): + def apply(sub_command, flags): + out, _, _ = admin_call(["--json", "image", sub_command] + flags) + return json.loads(out) + + return apply +https://github.com/anchore/syft/actions/runs/426001921 + +def test_image_add(image_command): + result = image_command("add", [input_image]) + assert result[0]["image_status"] == "active" + assert result[0]["image_detail"][0]["fulltag"] == "docker.io/centos:latest" + + +def test_image_list(image_command): + result = image_command("list", []) + assert result[0]["image_status"] == "active" + assert result[0]["image_detail"][0]["fulltag"] == "docker.io/centos:latest" + + +def test_image_get(image_command): + result = image_command("get", [input_image]) + assert result[0]["image_detail"][0]["fulltag"] == "docker.io/centos:latest" diff --git a/tests/functional/test_policy.py b/tests/functional/test_policy.py new file mode 100644 index 0000000..7a48442 --- /dev/null +++ b/tests/functional/test_policy.py @@ -0,0 +1,21 @@ +import pytest +import json + +input_policy = "foo" + +@pytest.fixture +def policy_command(admin_call): + def apply(sub_command, flags): + out, _, _ = admin_call(["--json", "policy", sub_command] + flags) + return json.loads(out) + return apply + + +class TestPolicyCMD: + + def test_policy_add(self, policy_command): + result = policy_command("add", input_policy) + print(result) + + def test_policy_get(self, policy_command): + result = policy_command("get", input_policy_id) diff --git a/tests/functional/test_query.py b/tests/functional/test_query.py new file mode 100644 index 0000000..0d7b08f --- /dev/null +++ b/tests/functional/test_query.py @@ -0,0 +1,15 @@ +import pytest +import json + + +@pytest.fixture +def query_command(admin_call): + def apply(sub_command, flags): + out, _, _ = admin_call(["--json", "query", sub_command] + flags) + return json.loads(out) + + return apply + + +def test_image_by_vulnerability(query_command): + pass diff --git a/tests/functional/test_registry.py b/tests/functional/test_registry.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/functional/test_repo.py b/tests/functional/test_repo.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/functional/test_subscription.py b/tests/functional/test_subscription.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/functional/test_system.py b/tests/functional/test_system.py new file mode 100644 index 0000000..d7d8198 --- /dev/null +++ b/tests/functional/test_system.py @@ -0,0 +1,31 @@ +import pytest +import json + + +@pytest.fixture +def system_command(admin_call): + def apply(sub_command, flags): + out, _, _ = admin_call(["--json", "system", sub_command] + flags) + return json.loads(out) + + return apply + + +class TestSystemStatus: + + @staticmethod + def _search_dict(name, col): + for entry in col: + if entry["servicename"] == name: + return entry + + def test_system_status(self, system_command): + services = ["apiext", "catalog", "analyzer", "policy_engine", "simplequeue"] + result = system_command("status", []) + for srv_name in services: + asset = self._search_dict(srv_name, result['service_states']) + assert asset["servicename"] == srv_name + assert asset["service_detail"]["message"] == "all good" + assert asset["service_detail"]["available"] + assert asset["status_message"] == "available" + assert asset["service_detail"]["up"] From 4fd83acf88d3bdd17bc3aa8f9b847e5b488547f3 Mon Sep 17 00:00:00 2001 From: Toure Dunnon Date: Tue, 26 Jan 2021 19:51:06 -0500 Subject: [PATCH 2/3] fixed: stubbed out event test Signed-off-by: Toure Dunnon --- tests/functional/test_event.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/functional/test_event.py b/tests/functional/test_event.py index 748caa1..6801311 100644 --- a/tests/functional/test_event.py +++ b/tests/functional/test_event.py @@ -10,9 +10,16 @@ def event_command(admin_call): def apply(sub_command, flags): output, _, _ = admin_call(["--json", "event", sub_command] + flags) return json.loads(output) + return apply class TestEvents: + def test_event_list(self): + pass + + def test_event_get(self): + pass - def test_ + def test_event_delete(self): + pass From 7a0bccb16d6ac8fb3f955cd02c8d8eebffe5aa06 Mon Sep 17 00:00:00 2001 From: Toure Dunnon Date: Tue, 26 Jan 2021 19:55:50 -0500 Subject: [PATCH 3/3] fixed: linter issues Signed-off-by: Toure Dunnon --- tests/functional/test_images.py | 2 +- tests/functional/test_policy.py | 3 ++- tests/functional/test_system.py | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/functional/test_images.py b/tests/functional/test_images.py index ea463fa..02e7d35 100644 --- a/tests/functional/test_images.py +++ b/tests/functional/test_images.py @@ -14,7 +14,7 @@ def apply(sub_command, flags): return json.loads(out) return apply -https://github.com/anchore/syft/actions/runs/426001921 + def test_image_add(image_command): result = image_command("add", [input_image]) diff --git a/tests/functional/test_policy.py b/tests/functional/test_policy.py index 7a48442..fde5d1a 100644 --- a/tests/functional/test_policy.py +++ b/tests/functional/test_policy.py @@ -3,16 +3,17 @@ input_policy = "foo" + @pytest.fixture def policy_command(admin_call): def apply(sub_command, flags): out, _, _ = admin_call(["--json", "policy", sub_command] + flags) return json.loads(out) + return apply class TestPolicyCMD: - def test_policy_add(self, policy_command): result = policy_command("add", input_policy) print(result) diff --git a/tests/functional/test_system.py b/tests/functional/test_system.py index d7d8198..2709d8c 100644 --- a/tests/functional/test_system.py +++ b/tests/functional/test_system.py @@ -12,7 +12,6 @@ def apply(sub_command, flags): class TestSystemStatus: - @staticmethod def _search_dict(name, col): for entry in col: @@ -23,7 +22,7 @@ def test_system_status(self, system_command): services = ["apiext", "catalog", "analyzer", "policy_engine", "simplequeue"] result = system_command("status", []) for srv_name in services: - asset = self._search_dict(srv_name, result['service_states']) + asset = self._search_dict(srv_name, result["service_states"]) assert asset["servicename"] == srv_name assert asset["service_detail"]["message"] == "all good" assert asset["service_detail"]["available"]