migrated default test to ansible

This commit is contained in:
Bertrand Lanson 2023-06-13 22:43:23 +02:00
parent 23e366f8df
commit 3f4fd0a6ea
4 changed files with 13 additions and 37 deletions

View File

@ -20,7 +20,7 @@ provisioner:
defaults:
remote_tmp: /tmp/.ansible
verifier:
name: testinfra
name: ansible
scenario:
name: default
test_sequence:

View File

@ -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
)

View File

@ -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

View File

@ -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"