From 3fe8c5b19f31170dc0a16fd7ce732abc80592343 Mon Sep 17 00:00:00 2001 From: unkin-agent Date: Fri, 9 Oct 2026 23:55:24 +1100 Subject: [PATCH] Give e2e backends distinct hosts and assert the source fact host --- e2e_backend_test.go | 2 +- e2e_fixture_test.go | 3 +++ e2e_health_test.go | 4 ++-- e2e_nodelookup_test.go | 4 ++-- e2e_query_test.go | 24 ++++++++++++------------ 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/e2e_backend_test.go b/e2e_backend_test.go index 72eefb3..41aff11 100644 --- a/e2e_backend_test.go +++ b/e2e_backend_test.go @@ -154,7 +154,7 @@ func startBackend(ctx context.Context, t fatalf, name, netName string) *backend fail("starting openvoxdb for %s: %v", name, err) } - return &backend{name: name, url: fmt.Sprintf("http://127.0.0.1:%d", port), pg: pg, pdb: pdb} + return &backend{name: name, url: fmt.Sprintf("http://%s.localhost:%d", name, port), pg: pg, pdb: pdb} } // waitForPuppetDBRunning gates on the trapperkeeper status service reporting diff --git a/e2e_fixture_test.go b/e2e_fixture_test.go index 20e9fb3..1328152 100644 --- a/e2e_fixture_test.go +++ b/e2e_fixture_test.go @@ -42,6 +42,9 @@ func fixtureTime(offset time.Duration) string { const ( backendAName = "pdb-a" backendBName = "pdb-b" + // The source fact's value is the backend host, so each backend gets its own. + backendAHost = backendAName + ".localhost" + backendBHost = backendBName + ".localhost" ) type nodeFixture struct { diff --git a/e2e_health_test.go b/e2e_health_test.go index be42a80..dc2db20 100644 --- a/e2e_health_test.go +++ b/e2e_health_test.go @@ -77,8 +77,8 @@ func TestBackendDeathAndRecovery(t *testing.T) { if got, _ := factValue(facts, nodeShared, "owner"); got != backendAName { t.Errorf("owner of %s with %s down = %v, want %q", nodeShared, h.b.name, got, backendAName) } - if got, _ := factValue(facts, nodeShared, defaultSourceFact); got != backendAName { - t.Errorf("%s for %s with %s down = %v, want %q", defaultSourceFact, nodeShared, h.b.name, got, backendAName) + if got, _ := factValue(facts, nodeShared, defaultSourceFact); got != backendAHost { + t.Errorf("%s for %s with %s down = %v, want %q", defaultSourceFact, nodeShared, h.b.name, got, backendAHost) } }) diff --git a/e2e_nodelookup_test.go b/e2e_nodelookup_test.go index 7420557..07e53d5 100644 --- a/e2e_nodelookup_test.go +++ b/e2e_nodelookup_test.go @@ -84,8 +84,8 @@ func TestNodeLookupShowsProvenance(t *testing.T) { if !strings.Contains(line, defaultSourceFact) { continue } - if !strings.Contains(line, backendBName) { - t.Fatalf("node-lookup reports %q for %s, want the owning backend %q", strings.TrimSpace(line), nodeShared, backendBName) + if !strings.Contains(line, backendBHost) { + t.Fatalf("node-lookup reports %q for %s, want the owning backend %q", strings.TrimSpace(line), nodeShared, backendBHost) } return } diff --git a/e2e_query_test.go b/e2e_query_test.go index 6778f08..4a5ffc7 100644 --- a/e2e_query_test.go +++ b/e2e_query_test.go @@ -286,8 +286,8 @@ func TestSharedNodeResolvesToTheFresherBackend(t *testing.T) { if got := node["report_timestamp"]; got != tsSharedOnB { t.Errorf("merged /nodes report_timestamp for %s = %v, want the fresher %q", nodeShared, got, tsSharedOnB) } - if got := node[defaultSourceFact]; got != backendBName { - t.Errorf("merged /nodes %s for %s = %v, want %q", defaultSourceFact, nodeShared, got, backendBName) + if got := node[defaultSourceFact]; got != backendBHost { + t.Errorf("merged /nodes %s for %s = %v, want %q", defaultSourceFact, nodeShared, got, backendBHost) } rows := get(t, factsPath, query(`["=","certname","`+nodeShared+`"]`)).rows(t) @@ -769,10 +769,10 @@ func TestSourceFactInjectionAndGating(t *testing.T) { t.Run("facts carry one source record per node", func(t *testing.T) { rows := get(t, factsPath, nil).rows(t) want := map[string]string{ - nodeAlpha: backendAName, - nodeBeta: backendBName, - nodeGamma: backendBName, - nodeShared: backendBName, // won on freshness, not on configured order + nodeAlpha: backendAHost, + nodeBeta: backendBHost, + nodeGamma: backendBHost, + nodeShared: backendBHost, // won on freshness, not on configured order } got := map[string]int{} for _, row := range rows { @@ -839,10 +839,10 @@ func TestSourceFactInjectionAndGating(t *testing.T) { // records /facts carries rather than the empty set the backends hold. func TestSourceFactDrilldown(t *testing.T) { want := map[string]string{ - nodeAlpha: backendAName, - nodeBeta: backendBName, - nodeGamma: backendBName, - nodeShared: backendBName, // won on freshness, not on configured order + nodeAlpha: backendAHost, + nodeBeta: backendBHost, + nodeGamma: backendBHost, + nodeShared: backendBHost, // won on freshness, not on configured order } path := factsPath + "/" + defaultSourceFact @@ -882,8 +882,8 @@ func TestSourceFactDrilldown(t *testing.T) { value string want []string }{ - {backendAName, []string{nodeAlpha}}, - {backendBName, []string{nodeBeta, nodeGamma, nodeShared}}, + {backendAHost, []string{nodeAlpha}}, + {backendBHost, []string{nodeBeta, nodeGamma, nodeShared}}, {"nosuchbackend", nil}, } { rows := get(t, path+"/"+tc.value, nil).rows(t)