From 3f4fd0a6ea7e8eb5f91eb9aa1a87d892c82a4cbe Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Tue, 13 Jun 2023 22:43:23 +0200 Subject: [PATCH] migrated default test to ansible --- molecule/default/molecule.yml | 2 +- molecule/default/tests/conftest.py | 22 ---------------------- molecule/default/tests/test_default.py | 14 -------------- molecule/default/verify.yml | 12 ++++++++++++ 4 files changed, 13 insertions(+), 37 deletions(-) delete mode 100644 molecule/default/tests/conftest.py delete mode 100644 molecule/default/tests/test_default.py diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 7a62eb2..49efc7f 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -20,7 +20,7 @@ provisioner: defaults: remote_tmp: /tmp/.ansible verifier: - name: testinfra + name: ansible scenario: name: default test_sequence: diff --git a/molecule/default/tests/conftest.py b/molecule/default/tests/conftest.py deleted file mode 100644 index f7ddb3f..0000000 --- a/molecule/default/tests/conftest.py +++ /dev/null @@ -1,22 +0,0 @@ -"""PyTest Fixtures.""" -from __future__ import absolute_import - -import os - -import pytest - - -def pytest_runtest_setup(item): - """Run tests only when under molecule with testinfra installed.""" - try: - import testinfra - except ImportError: - pytest.skip("Test requires testinfra", allow_module_level=True) - if "MOLECULE_INVENTORY_FILE" in os.environ: - pytest.testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( - os.environ["MOLECULE_INVENTORY_FILE"] - ).get_hosts("all") - else: - pytest.skip( - "Test should run only from inside molecule.", allow_module_level=True - ) diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py deleted file mode 100644 index 39ad68f..0000000 --- a/molecule/default/tests/test_default.py +++ /dev/null @@ -1,14 +0,0 @@ -"""Role testing files using testinfra.""" - - -def test_hosts_file(host): - """Validate /etc/hosts file.""" - etc_hosts = host.file("/etc/hosts") - assert etc_hosts.exists - assert etc_hosts.user == "root" - assert etc_hosts.group == "root" - -def test_packages_not_installed(host): - """Validate vim is installed""" - apt_package_vim = host.package("vim") - assert apt_package_vim.is_installed diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index bf52da2..ec18dd5 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -17,3 +17,15 @@ - stat_etc_hosts.stat.isreg - stat_etc_hosts.stat.pw_name == 'root' - stat_etc_hosts.stat.gr_name == 'root' + + - name: "Test: package vim" + block: + - name: "Command apt list vim" + ansible.builtin.command: "apt list vim" + changed_when: false + register: apt_list_vim + + - name: "Verify package vim" + ansible.builtin.assert: + that: + - "'[installed]' in apt_list_vim.stdout"