mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-07 05:22:39 +00:00
Add unit and sanity tests to GHA (#614)
* Add unit and sanity tests to GHA Signed-off-by: GomathiselviS <gomathiselvi@gmail.com> * Fix sanity issues * Add sanity non voting * Add changelog * Fix typo * Fix typo * Use pytest-ansible * Add support for pytest-ansible --------- Signed-off-by: GomathiselviS <gomathiselvi@gmail.com>
This commit is contained in:
@@ -16,11 +16,13 @@ plugins/module_utils/k8sdynamicclient.py import-3.8!skip
|
||||
plugins/module_utils/k8sdynamicclient.py import-3.9!skip
|
||||
plugins/module_utils/k8sdynamicclient.py import-3.10!skip
|
||||
plugins/module_utils/k8sdynamicclient.py import-3.11!skip
|
||||
plugins/module_utils/version.py pylint!skip
|
||||
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
|
||||
plugins/modules/k8s_scale.py validate-modules:parameter-type-not-in-doc
|
||||
plugins/modules/k8s_service.py validate-modules:parameter-type-not-in-doc
|
||||
tests/unit/module_utils/fixtures/definitions.yml yamllint!skip
|
||||
tests/unit/module_utils/fixtures/deployments.yml yamllint!skip
|
||||
tests/integration/targets/k8s_delete/files/deployments.yaml yamllint!skip
|
||||
tests/unit/module_utils/fixtures/pods.yml yamllint!skip
|
||||
tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap.yaml yamllint!skip
|
||||
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
|
||||
|
||||
35
tests/sanity/ignore-2.6.txt
Normal file
35
tests/sanity/ignore-2.6.txt
Normal file
@@ -0,0 +1,35 @@
|
||||
plugins/module_utils/client/discovery.py import-3.6!skip
|
||||
plugins/module_utils/client/discovery.py import-3.7!skip
|
||||
plugins/module_utils/client/discovery.py import-3.8!skip
|
||||
plugins/module_utils/client/discovery.py import-3.9!skip
|
||||
plugins/module_utils/client/discovery.py import-3.10!skip
|
||||
plugins/module_utils/client/discovery.py import-3.11!skip
|
||||
plugins/module_utils/client/resource.py import-3.6!skip
|
||||
plugins/module_utils/client/resource.py import-3.7!skip
|
||||
plugins/module_utils/client/resource.py import-3.8!skip
|
||||
plugins/module_utils/client/resource.py import-3.9!skip
|
||||
plugins/module_utils/client/resource.py import-3.10!skip
|
||||
plugins/module_utils/client/resource.py import-3.11!skip
|
||||
plugins/module_utils/k8sdynamicclient.py import-3.6!skip
|
||||
plugins/module_utils/k8sdynamicclient.py import-3.7!skip
|
||||
plugins/module_utils/k8sdynamicclient.py import-3.8!skip
|
||||
plugins/module_utils/k8sdynamicclient.py import-3.9!skip
|
||||
plugins/module_utils/k8sdynamicclient.py import-3.10!skip
|
||||
plugins/module_utils/k8sdynamicclient.py import-3.11!skip
|
||||
plugins/modules/k8s.py validate-modules:parameter-type-not-in-doc
|
||||
plugins/modules/k8s_scale.py validate-modules:parameter-type-not-in-doc
|
||||
plugins/modules/k8s_service.py validate-modules:parameter-type-not-in-doc
|
||||
tests/unit/module_utils/fixtures/definitions.yml yamllint!skip
|
||||
tests/unit/module_utils/fixtures/deployments.yml yamllint!skip
|
||||
tests/unit/module_utils/fixtures/pods.yml yamllint!skip
|
||||
tests/integration/targets/helm/files/appversionless-chart-v2/templates/configmap.yaml yamllint!skip
|
||||
tests/integration/targets/helm/files/appversionless-chart/templates/configmap.yaml yamllint!skip
|
||||
tests/integration/targets/helm/files/test-chart-v2/templates/configmap.yaml yamllint!skip
|
||||
tests/integration/targets/helm/files/test-chart/templates/configmap.yaml yamllint!skip
|
||||
tests/integration/targets/helm_diff/files/test-chart/templates/configmap.yaml yamllint!skip
|
||||
tests/integration/targets/k8s_scale/files/deployment.yaml yamllint!skip
|
||||
tests/sanity/refresh_ignore_files shebang!skip
|
||||
plugins/modules/k8s.py validate-modules:return-syntax-error
|
||||
plugins/modules/k8s_scale.py validate-modules:return-syntax-error
|
||||
plugins/modules/k8s_service.py validate-modules:return-syntax-error
|
||||
plugins/modules/k8s_taint.py validate-modules:return-syntax-error
|
||||
@@ -22,7 +22,7 @@ import string
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def ansible_helm_module():
|
||||
def _ansible_helm_module():
|
||||
module = MagicMock()
|
||||
module.params = {
|
||||
"api_key": None,
|
||||
@@ -139,31 +139,31 @@ def test_module_get_helm_binary_from_system():
|
||||
assert helm_module.get_helm_binary() == helm_sys_binary_path
|
||||
|
||||
|
||||
def test_module_get_helm_plugin_list(ansible_helm_module):
|
||||
def test_module_get_helm_plugin_list(_ansible_helm_module):
|
||||
|
||||
ansible_helm_module.run_helm_command = MagicMock()
|
||||
ansible_helm_module.run_helm_command.return_value = (0, "output", "error")
|
||||
_ansible_helm_module.run_helm_command = MagicMock()
|
||||
_ansible_helm_module.run_helm_command.return_value = (0, "output", "error")
|
||||
|
||||
rc, out, err, command = ansible_helm_module.get_helm_plugin_list()
|
||||
rc, out, err, command = _ansible_helm_module.get_helm_plugin_list()
|
||||
|
||||
assert (rc, out, err) == (0, "output", "error")
|
||||
assert command == "some/path/to/helm/executable plugin list"
|
||||
|
||||
ansible_helm_module.get_helm_binary.assert_called_once()
|
||||
ansible_helm_module.run_helm_command.assert_called_once_with(
|
||||
_ansible_helm_module.get_helm_binary.assert_called_once()
|
||||
_ansible_helm_module.run_helm_command.assert_called_once_with(
|
||||
"some/path/to/helm/executable plugin list"
|
||||
)
|
||||
|
||||
|
||||
def test_module_get_helm_plugin_list_failure(ansible_helm_module):
|
||||
def test_module_get_helm_plugin_list_failure(_ansible_helm_module):
|
||||
|
||||
ansible_helm_module.run_helm_command = MagicMock()
|
||||
ansible_helm_module.run_helm_command.return_value = (-1, "output", "error")
|
||||
_ansible_helm_module.run_helm_command = MagicMock()
|
||||
_ansible_helm_module.run_helm_command.return_value = (-1, "output", "error")
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
ansible_helm_module.get_helm_plugin_list()
|
||||
_ansible_helm_module.get_helm_plugin_list()
|
||||
|
||||
ansible_helm_module.fail_json.assert_called_once_with(
|
||||
_ansible_helm_module.fail_json.assert_called_once_with(
|
||||
msg="Failed to get Helm plugin info",
|
||||
command="some/path/to/helm/executable plugin list",
|
||||
stdout="output",
|
||||
@@ -174,7 +174,7 @@ def test_module_get_helm_plugin_list_failure(ansible_helm_module):
|
||||
|
||||
@pytest.mark.parametrize("no_values", [True, False])
|
||||
@pytest.mark.parametrize("get_all", [True, False])
|
||||
def test_module_get_values(ansible_helm_module, no_values, get_all):
|
||||
def test_module_get_values(_ansible_helm_module, no_values, get_all):
|
||||
|
||||
expected = {"test": "units"}
|
||||
output = "---\ntest: units\n"
|
||||
@@ -183,19 +183,19 @@ def test_module_get_values(ansible_helm_module, no_values, get_all):
|
||||
expected = {}
|
||||
output = "null"
|
||||
|
||||
ansible_helm_module.run_helm_command = MagicMock()
|
||||
ansible_helm_module.run_helm_command.return_value = (0, output, "error")
|
||||
_ansible_helm_module.run_helm_command = MagicMock()
|
||||
_ansible_helm_module.run_helm_command.return_value = (0, output, "error")
|
||||
|
||||
release_name = "".join(
|
||||
random.choice(string.ascii_letters + string.digits) for x in range(10)
|
||||
)
|
||||
result = ansible_helm_module.get_values(release_name, get_all=get_all)
|
||||
result = _ansible_helm_module.get_values(release_name, get_all=get_all)
|
||||
|
||||
ansible_helm_module.get_helm_binary.assert_called_once()
|
||||
_ansible_helm_module.get_helm_binary.assert_called_once()
|
||||
command = f"some/path/to/helm/executable get values --output=yaml {release_name}"
|
||||
if get_all:
|
||||
command += " -a"
|
||||
ansible_helm_module.run_helm_command.assert_called_once_with(command)
|
||||
_ansible_helm_module.run_helm_command.assert_called_once_with(command)
|
||||
assert result == expected
|
||||
|
||||
|
||||
@@ -210,20 +210,20 @@ def test_module_get_values(ansible_helm_module, no_values, get_all):
|
||||
('Client: &version.Version{SemVer:"v3.12.3"', None),
|
||||
],
|
||||
)
|
||||
def test_module_get_helm_version(ansible_helm_module, output, expected):
|
||||
def test_module_get_helm_version(_ansible_helm_module, output, expected):
|
||||
|
||||
ansible_helm_module.run_command = MagicMock()
|
||||
ansible_helm_module.run_command.return_value = (0, output, "error")
|
||||
_ansible_helm_module.run_command = MagicMock()
|
||||
_ansible_helm_module.run_command.return_value = (0, output, "error")
|
||||
|
||||
result = ansible_helm_module.get_helm_version()
|
||||
result = _ansible_helm_module.get_helm_version()
|
||||
|
||||
ansible_helm_module.get_helm_binary.assert_called_once()
|
||||
_ansible_helm_module.get_helm_binary.assert_called_once()
|
||||
command = "some/path/to/helm/executable version"
|
||||
ansible_helm_module.run_command.assert_called_once_with(command)
|
||||
_ansible_helm_module.run_command.assert_called_once_with(command)
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_module_run_helm_command(ansible_helm_module):
|
||||
def test_module_run_helm_command(_ansible_helm_module):
|
||||
|
||||
error = "".join(
|
||||
random.choice(string.ascii_letters + string.digits) for x in range(10)
|
||||
@@ -232,26 +232,26 @@ def test_module_run_helm_command(ansible_helm_module):
|
||||
random.choice(string.ascii_letters + string.digits) for x in range(10)
|
||||
)
|
||||
|
||||
ansible_helm_module.run_command.return_value = (0, output, error)
|
||||
_ansible_helm_module.run_command.return_value = (0, output, error)
|
||||
|
||||
ansible_helm_module._prepare_helm_environment = MagicMock()
|
||||
_ansible_helm_module._prepare_helm_environment = MagicMock()
|
||||
env_update = {x: random.choice(string.ascii_letters) for x in range(10)}
|
||||
ansible_helm_module._prepare_helm_environment.return_value = env_update
|
||||
_ansible_helm_module._prepare_helm_environment.return_value = env_update
|
||||
|
||||
command = "".join(
|
||||
random.choice(string.ascii_letters + string.digits) for x in range(10)
|
||||
)
|
||||
rc, out, err = ansible_helm_module.run_helm_command(command)
|
||||
rc, out, err = _ansible_helm_module.run_helm_command(command)
|
||||
|
||||
assert (rc, out, err) == (0, output, error)
|
||||
|
||||
ansible_helm_module.run_command.assert_called_once_with(
|
||||
_ansible_helm_module.run_command.assert_called_once_with(
|
||||
command, environ_update=env_update
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("fails_on_error", [True, False])
|
||||
def test_module_run_helm_command_failure(ansible_helm_module, fails_on_error):
|
||||
def test_module_run_helm_command_failure(_ansible_helm_module, fails_on_error):
|
||||
|
||||
error = "".join(
|
||||
random.choice(string.ascii_letters + string.digits) for x in range(10)
|
||||
@@ -260,9 +260,9 @@ def test_module_run_helm_command_failure(ansible_helm_module, fails_on_error):
|
||||
random.choice(string.ascii_letters + string.digits) for x in range(10)
|
||||
)
|
||||
return_code = random.randint(1, 10)
|
||||
ansible_helm_module.run_command.return_value = (return_code, output, error)
|
||||
_ansible_helm_module.run_command.return_value = (return_code, output, error)
|
||||
|
||||
ansible_helm_module._prepare_environment = MagicMock()
|
||||
_ansible_helm_module._prepare_environment = MagicMock()
|
||||
|
||||
command = "".join(
|
||||
random.choice(string.ascii_letters + string.digits) for x in range(10)
|
||||
@@ -270,10 +270,10 @@ def test_module_run_helm_command_failure(ansible_helm_module, fails_on_error):
|
||||
|
||||
if fails_on_error:
|
||||
with pytest.raises(SystemExit):
|
||||
rc, out, err = ansible_helm_module.run_helm_command(
|
||||
rc, out, err = _ansible_helm_module.run_helm_command(
|
||||
command, fails_on_error=fails_on_error
|
||||
)
|
||||
ansible_helm_module.fail_json.assert_called_with(
|
||||
_ansible_helm_module.fail_json.assert_called_with(
|
||||
msg="Failure when executing Helm command. Exited {0}.\nstdout: {1}\nstderr: {2}".format(
|
||||
return_code, output, error
|
||||
),
|
||||
@@ -282,7 +282,7 @@ def test_module_run_helm_command_failure(ansible_helm_module, fails_on_error):
|
||||
command=command,
|
||||
)
|
||||
else:
|
||||
rc, out, err = ansible_helm_module.run_helm_command(
|
||||
rc, out, err = _ansible_helm_module.run_helm_command(
|
||||
command, fails_on_error=fails_on_error
|
||||
)
|
||||
assert (rc, out, err) == (return_code, output, error)
|
||||
|
||||
Reference in New Issue
Block a user