diff --git a/molecule/ini-configuration-tests/collections.yml b/molecule/ini-configuration-tests/collections.yml new file mode 100644 index 00000000..bed6991a --- /dev/null +++ b/molecule/ini-configuration-tests/collections.yml @@ -0,0 +1,4 @@ +collections: + - name: community.docker + - name: community.general + version: ">=2,<3" diff --git a/molecule/ini-configuration-tests/converge.yml b/molecule/ini-configuration-tests/converge.yml new file mode 100644 index 00000000..8595be5e --- /dev/null +++ b/molecule/ini-configuration-tests/converge.yml @@ -0,0 +1,42 @@ +--- + +- name: Converge + hosts: all + vars: + test_cases: + - name: string + _i2_config_hash: + section: + test: string + - name: number + _i2_config_hash: + section: + test: 10 + - name: advanced_filter + _i2_config_hash: + section: + test: '(objectClass=user)' + test2: "!(objectClass=user)" + test3: "!attribute" + - name: list + _i2_config_hash: + section: + test: + - "foo" + - bar + - 'baz' + - name: equal_sign + _i2_config_hash: + section: + test: 'equal=sign' + + + collections: + - icinga.icinga + tasks: + - ansible.builtin.template: + src: "{{ lookup('ansible.builtin.env', 'MOLECULE_PROJECT_DIRECTORY', default=Undefined) }}/roles/icingaweb2/templates/modules_config.ini.j2" + dest: "/tmp/{{ item.name }}" + loop: "{{ test_cases }}" + vars: + _i2_config_hash: "{{ item._i2_config_hash }}" diff --git a/molecule/ini-configuration-tests/molecule.yml b/molecule/ini-configuration-tests/molecule.yml new file mode 100644 index 00000000..734354fd --- /dev/null +++ b/molecule/ini-configuration-tests/molecule.yml @@ -0,0 +1,26 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: icinga-default + image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + cgroupns_mode: host + privileged: true + pre_build_image: true +provisioner: + name: ansible + inventory: + link: + host_vars: host_vars/ +verifier: + name: testinfra + directory: tests/integration/ +lint: | + set -e + yamllint --no-warnings roles/ + ansible-lint roles/ diff --git a/molecule/ini-configuration-tests/tests/integration/test_ini_config.py b/molecule/ini-configuration-tests/tests/integration/test_ini_config.py new file mode 100644 index 00000000..732b0334 --- /dev/null +++ b/molecule/ini-configuration-tests/tests/integration/test_ini_config.py @@ -0,0 +1,29 @@ +def test_string(host): + i2_file = host.file("/tmp/string") + print(i2_file.content_string) + assert i2_file.is_file + assert i2_file.content_string == "\n[section]\ntest = string" + +def test_number(host): + i2_file = host.file("/tmp/number") + print(i2_file.content_string) + assert i2_file.is_file + assert i2_file.content_string == '\n[section]\ntest = "10"' + +def test_list(host): + i2_file = host.file("/tmp/list") + print(i2_file.content_string) + assert i2_file.is_file + assert i2_file.content_string == '\n[section]\ntest = "foo, bar, baz"' + +def test_advanced_filter(host): + i2_file = host.file("/tmp/advanced_filter") + print(i2_file.content_string) + assert i2_file.is_file + assert i2_file.content_string == "\n[section]\ntest = '!(objectClass=user)'\ntest2 = '!(objectClass=user)'\ntest3 = '!attribute'" + +def test_equal_sign(host): + i2_file = host.file("/tmp/equal_sign") + print(i2_file.content_string) + assert i2_file.is_file + assert i2_file.content_string == "\n[section]\ntest = 'equal=sign'"