diff options
| author | Colin Wilk <colin@wilk.cx> | 2026-07-21 19:58:10 +0200 |
|---|---|---|
| committer | Colin Wilk <colin@wilk.cx> | 2026-07-21 19:58:10 +0200 |
| commit | c33948c219032977779a7ef6d82c16e84f37b81a (patch) | |
| tree | f5a897d933639cdf97da2564d976610259115159 /molecule/default/tests/test_lineinfile_strategy.py | |
| parent | 0055971afd5524f0df00fc8d2203a80f828885f7 (diff) | |
| download | ansible-role-prometheus-target-c33948c219032977779a7ef6d82c16e84f37b81a.tar.gz ansible-role-prometheus-target-c33948c219032977779a7ef6d82c16e84f37b81a.zip | |
test: expand Molecule coverage for exporter behavior
Cover lineinfile and YAML behavior for default exporters, skipped
defaults, exporters without IDs, duplicate definitions, path and host
overrides, path-prefix precedence, and inherited label overrides.
Verify YAML handling of null documents, multiple files, labeled and
unlabeled groups, and duplicate targets.
Add test coverage for command and shell handlers using run-once,
per-host, disabled, and non-become configurations.
Diffstat (limited to 'molecule/default/tests/test_lineinfile_strategy.py')
| -rw-r--r-- | molecule/default/tests/test_lineinfile_strategy.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/molecule/default/tests/test_lineinfile_strategy.py b/molecule/default/tests/test_lineinfile_strategy.py index b75a656..770459e 100644 --- a/molecule/default/tests/test_lineinfile_strategy.py +++ b/molecule/default/tests/test_lineinfile_strategy.py @@ -92,3 +92,41 @@ def test_lineinfile_hooks_still_run(host): assert host.file("/opt/hook1").exists assert host.file("/opt/hook2").content_string == "hello\nhello\nhello\nhello\n" + + +def test_lineinfile_exporter_defaults_overrides_and_duplicates(host): + assert read_yaml_file(host, "/opt/lineinfile_defaults.yml") == [ + "inherited-default", + "appended-default", + ] + assert read_yaml_file(host, "/opt/lineinfile_no_id.yml") == ["no-id"] + assert read_yaml_file(host, "/opt/lineinfile_override.yml") == ["item-override"] + assert read_yaml_file(host, "/opt/lineinfile-prefix/default-prefix.yml") == [ + "prefixed-default" + ] + + +def test_lineinfile_skip_default_exporters(host): + assert read_file(host, "/opt/lineinfile_skipped.yml").content_string == "" + + +def test_handler_run_once_and_per_host_modes(host): + for application in ["application", "application2", "application3", "application4"]: + assert host.file(f"/tmp/command-handler-{application}").exists + + assert host.file("/tmp/shell-handler-run-once").exists + + +def test_disabled_handlers_do_not_run(host): + assert not host.file("/tmp/disabled-command-handler").exists + assert not host.file("/tmp/disabled-shell-handler").exists + + +def test_future_lineinfile_removal_fixture_is_untouched(host): + assert read_yaml_file(host, "/opt/lineinfile_state_removal.yml") == [ + { + "labels": {"job": "shared"}, + "targets": ["keep:9100", "remove:9100"], + }, + {"labels": {"job": "remove_last"}, "targets": ["remove:9200"]}, + ] |