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_yaml_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_yaml_strategy.py')
| -rw-r--r-- | molecule/default/tests/test_yaml_strategy.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/molecule/default/tests/test_yaml_strategy.py b/molecule/default/tests/test_yaml_strategy.py index 7ba834e..c3d0dd9 100644 --- a/molecule/default/tests/test_yaml_strategy.py +++ b/molecule/default/tests/test_yaml_strategy.py @@ -92,6 +92,12 @@ def test_yaml_output_remains_parseable_after_all_operations(host): "/opt/yaml_branch_matrix.yml", "/opt/yaml_missing_labeled.yml", "/opt/yaml_missing_unlabeled.yml", + "/opt/yaml_defaults.yml", + "/opt/yaml_no_id.yml", + "/opt/yaml_override.yml", + "/opt/yaml_null.yml", + "/opt/yaml-prefix/default-prefix.yml", + "/opt/yaml_state_removal.yml", ]: assert read_yaml_file(host, path) is not None @@ -154,3 +160,48 @@ def test_yaml_branch_matrix_creates_missing_file_groups_for_labeled_and_unlabele assert read_yaml_file(host, "/opt/yaml_missing_unlabeled.yml") == [ {"targets": ["application4:9601"]} ] + + +def test_yaml_exporter_defaults_merge_labels_and_deduplicate(host): + groups = read_yaml_file(host, "/opt/yaml_defaults.yml") + + assert get_group_by_labels( + groups, {"job": "inherited", "environment": "staging"} + )["targets"] == ["application:9700"] + assert get_group_by_labels(groups, {"job": "default"})["targets"] == [ + "appended-default:9701" + ] + + +def test_yaml_exporter_without_id_and_item_overrides(host): + assert read_yaml_file(host, "/opt/yaml_no_id.yml") == [ + {"labels": {"job": "no-id"}, "targets": ["no-id:9700"]} + ] + assert read_yaml_file(host, "/opt/yaml_override.yml") == [ + {"labels": {"job": "override"}, "targets": ["item-override:9700"]} + ] + assert read_yaml_file(host, "/opt/yaml-prefix/default-prefix.yml") == [ + {"labels": {"job": "prefixed"}, "targets": ["prefixed-default:9702"]} + ] + + +def test_yaml_null_document_is_initialized(host): + assert read_yaml_file(host, "/opt/yaml_null.yml") == [ + {"targets": ["from-null:9700"]} + ] + + +def test_yaml_skip_default_exporters(host): + target = host.file("/opt/yaml_skipped.yml") + assert target.exists + assert target.content_string == "" + + +def test_future_yaml_removal_fixture_is_untouched(host): + assert read_yaml_file(host, "/opt/yaml_state_removal.yml") == [ + { + "labels": {"job": "shared"}, + "targets": ["keep:9100", "remove:9100"], + }, + {"labels": {"job": "remove_last"}, "targets": ["remove:9200"]}, + ] |