From 8cec56d4a51996b23c3f25db41748265530b0393 Mon Sep 17 00:00:00 2001 From: Adam Dyess Date: Thu, 22 Aug 2024 14:35:48 -0500 Subject: [PATCH] Add Sanity tests --- tests/.copyright.tmpl | 1 + tests/requirements-dev.txt | 5 ++++ tests/requirements-test.txt | 5 ++++ tests/sanity/test_rock.py | 18 +++++++++++ tests/tox.ini | 59 +++++++++++++++++++++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 tests/.copyright.tmpl create mode 100644 tests/requirements-dev.txt create mode 100644 tests/requirements-test.txt create mode 100644 tests/sanity/test_rock.py create mode 100644 tests/tox.ini diff --git a/tests/.copyright.tmpl b/tests/.copyright.tmpl new file mode 100644 index 0000000..ecbed6c --- /dev/null +++ b/tests/.copyright.tmpl @@ -0,0 +1 @@ +Copyright ${years} ${owner}. diff --git a/tests/requirements-dev.txt b/tests/requirements-dev.txt new file mode 100644 index 0000000..f117d33 --- /dev/null +++ b/tests/requirements-dev.txt @@ -0,0 +1,5 @@ +black==24.3.0 +codespell==2.2.4 +flake8==6.0.0 +isort==5.12.0 +licenseheaders==0.8.8 \ No newline at end of file diff --git a/tests/requirements-test.txt b/tests/requirements-test.txt new file mode 100644 index 0000000..81b355e --- /dev/null +++ b/tests/requirements-test.txt @@ -0,0 +1,5 @@ +coverage[toml]==7.2.5 +pytest==7.3.1 +PyYAML==6.0.1 +tenacity==8.2.3 +git+https://github.com/canonical/k8s-test-harness.git@main \ No newline at end of file diff --git a/tests/sanity/test_rock.py b/tests/sanity/test_rock.py new file mode 100644 index 0000000..dd18a9b --- /dev/null +++ b/tests/sanity/test_rock.py @@ -0,0 +1,18 @@ +# +# Copyright 2024 Canonical, Ltd. +# + +import pytest +from k8s_test_harness.util import docker_util, env_util + + +@pytest.mark.parametrize("image_version", ["0.8.0"]) +def test_sanity(image_version): + rock = env_util.get_build_meta_info_for_rock_version( + "rawfile-localpv", image_version, "amd64" + ) + image = rock.image + entrypoint = "/python3" + + process = docker_util.run_in_docker(image, [entrypoint, "--version"]) + assert image_version in process.stdout diff --git a/tests/tox.ini b/tests/tox.ini new file mode 100644 index 0000000..fb838d5 --- /dev/null +++ b/tests/tox.ini @@ -0,0 +1,59 @@ +[tox] +no_package = True +skip_missing_interpreters = True +env_list = format, lint, integration +min_version = 4.0.0 + +[testenv] +set_env = + PYTHONBREAKPOINT=pdb.set_trace + PY_COLORS=1 +pass_env = + PYTHONPATH + +[testenv:format] +description = Apply coding style standards to code +deps = -r {tox_root}/requirements-dev.txt +commands = + licenseheaders -t {tox_root}/.copyright.tmpl -cy -o 'Canonical, Ltd' -d {tox_root}/sanity + isort {tox_root}/sanity --profile=black + black {tox_root}/sanity + +[testenv:lint] +description = Check code against coding style standards +deps = -r {tox_root}/requirements-dev.txt +commands = + codespell {tox_root}/sanity + flake8 {tox_root}/sanity + licenseheaders -t {tox_root}/.copyright.tmpl -cy -o 'Canonical, Ltd' -d {tox_root}/sanity --dry + +[testenv:sanity] +description = Run sanity tests +deps = + -r {tox_root}/requirements-test.txt +commands = + pytest -v \ + --maxfail 1 \ + --tb native \ + --log-cli-level DEBUG \ + --disable-warnings \ + {posargs} \ + {tox_root}/sanity +pass_env = + TEST_* + ROCK_* + BUILT_ROCKS_METADATA + +[testenv: integration] +allowlist_externals = + echo +commands = +# TODO: Implement integration tests here + echo "WARNING: This is a placeholder test - no test is implemented here." + +[flake8] +max-line-length = 120 +select = E,W,F,C,N +ignore = W503 +exclude = venv,.git,.tox,.tox_env,.venv,build,dist,*.egg_info +show-source = true \ No newline at end of file