Skip to content

Assert on parsed structure in the cf2ansible and port_binding tests #48

Description

@FAZuH

Part of the whole-repo test-suite audit (2026-09-30). These are Fragile Fixtures: a formatting change breaks them with no behaviour change.

What to build

Tests that read the data the program produces, not the exact bytes it happened to emit.

Findings

  • tests/cf2ansible.rs asserts on exact YAML formatting. domain0 (:74) carries about 20 assertions across 10 unrelated behaviours; domain3 (:138) has 12; assert_common (:34) has 7. assert_type_count (:60) counts the literal string "\n type: A\n", so restyling the YAML to block form breaks all four tests with no behaviour change. Parse the YAML with serde_yaml and assert on the structure, or commit one snapshot per fixture.
  • The same problem in a model test. crates/natmap/tests/model.rs:42 add_mapping_request_serialize_defaults asserts json.contains("\"host_ip\":\"0.0.0.0\"") for the same reason. Deserialise and compare fields.
  • Three port_binding tests parse a human-formatted table. tests/auto_discover/port_binding.rs:220,261,306 use awk "$6 == id {print $8}" on natmap ls output. Reorder or re-pad a table column and all three break. Use the /rules JSON endpoint, or natmap ls --json if it exists.
  • The same three tests are also duplicates. bind_ip_strict_address (:196), bind_interface_resolved_address (:237) and bind_interface_overrides_defaults (:278) are 40 lines each, differing only in the YAML bind_ip: versus bind_interface: line and whether a defaults: block is present. One table-driven test.
  • Two tests that do not test what they name. src/cmd/cf2ansible.rs:271 output_produces_yaml never calls print_ansible_tasks_to; it calls parse_zone and checks the rtype list, while the real output is covered by tests/cf2ansible.rs. And ns_records_not_proxied (:301) is a for loop with an assert_eq! inside, so it passes vacuously if the fixture has no NS records.
  • Test names break standards.md §3.6. domain0, domain1, domain2, domain3 are named after the fixture file, with no module and no scenario.

Acceptance criteria

  • No test asserts on whitespace, column position, or a substring of formatted output
  • Restyling the YAML emitter, or reordering a table column, does not break these tests. Demonstrate this.
  • ns_records_not_proxied fails when the fixture is changed to have zero NS records, i.e. it is no longer vacuous
  • Test names follow <module_or_function>_<scenario> per standards.md §3.6
  • One concept per test: the 20-assertion domain0 becomes several named tests
  • cargo test -p lab-ops --test cf2ansible passes

Blocked by

None (can start immediately).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified, ready for an AFK agent

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions