Give e2e backends distinct hosts and assert the source fact host
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful

This commit is contained in:
2026-10-09 23:55:24 +11:00
parent a47f907538
commit 3fe8c5b19f
5 changed files with 20 additions and 17 deletions
+1 -1
View File
@@ -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
+3
View File
@@ -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 {
+2 -2
View File
@@ -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)
}
})
+2 -2
View File
@@ -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
}
+12 -12
View File
@@ -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)