Skip to content

Merge the duplicated unit-test setups across natmap and auto-discover #46

Description

@FAZuH

Part of the whole-repo test-suite audit (2026-09-30).

What to build

The repeated Arrange block replaced by the make_* helper the guidelines already mandate, so each test keeps only its own scenario.

Findings

  • crates/natmap/src/daemon.rs:1090,1098,1119,1140,1161 — five tests, each restating the same 12-line state.write().await.mapping.insert(DockerPortMap::new(...)) block. A make_state(&[("alpha", 8080, "10.0.0.2")]) helper plus one table.
  • crates/natmap/src/daemon.rs:1228,1247,1266 — three reconcile_addr_* tests, each with two five-line DockerPortMapRequest literals.
  • crates/auto-discover/src/daemon.rs:1042-1365 — ten sync_service_* tests sharing an identical eight-line Arrange (tempdir plus two fakes plus make_daemon plus make_resolved), differing only in the ResolvedPortType variant.
  • crates/auto-discover/src/consul.rs:389,437 — build_consul_service builds a 20-line ResolvedService literal and makes 12 assertions in one test; build_consul_service_udp_check copies the literal. One make_resolved(port_type, protocol) helper plus a table of (port_type, expected_meta).
  • src/cmd/dns_parser.rs:189-254,518-528 — the highest test-to-production ratio in the repo, 52 tests for 181 production lines. Eight parse_zone_*_record tests assert the same three fields with a different rtype string; can_proxy_a_record, can_proxy_aaaa_record and can_proxy_cname_record are three tests for one matches!(rtype, "A" | "AAAA" | "CNAME").

Acceptance criteria

  • Every shared fixture is a make_* private helper at the top of its test module, per standards.md §7.4
  • Each test contains its own scenario, not its own copy of the setup
  • One concept per test: the consul.rs 12-assertion test becomes a table or splits
  • Test names follow standards.md §3.6
  • cargo test -p lab-ops_natmap --lib, cargo test -p lab-ops_auto-discover --lib and cargo test -p lab-ops --lib pass
  • No test loses coverage: the same inputs and the same expected outputs are asserted

Blocked by

None (can start immediately).

Estimated: -30 tests, -390 lines.

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