Derive the guard from taken modules only: their published private-network ports and their manifests' guards (hq ADR 0103)
This commit is contained in:
@@ -225,3 +225,38 @@ func TestConsumersAreToldTheGivenPort(t *testing.T) {
|
||||
t.Fatalf("a port given for the whole mesh was not refused: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// novox/hq ADR 0103: the guard an adopted node is sent follows what was taken there. A store
|
||||
// assigned but not taken is not guarded — its port may still be the predecessor's — and taking it
|
||||
// guards it from the next declaration.
|
||||
func TestTheGuardIsSentForTakenModulesOnly(t *testing.T) {
|
||||
open := aMesh(t)
|
||||
ctx := t.Context()
|
||||
register(t, open, catalogue.Manifest{Module: "store", Version: "1",
|
||||
Listens: []catalogue.Listening{{Port: 5432, From: catalogue.FromMesh}},
|
||||
Guards: []int{5432},
|
||||
Resources: []map[string]any{{"id": "server", "type": "container", "name": "mesh-store",
|
||||
"ports": []any{"5432:5432"},
|
||||
"image": "registry.example/pg@sha256:" + strings.Repeat("b", 64)}}})
|
||||
if err := open.inventory.SetAdopted(ctx, "anchor", true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := assign(ctx, open, "anchor", "store"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if hasID(composed(t, open, "anchor").Resources, catalogue.GuardID()) {
|
||||
t.Fatal("an untaken store is guarded")
|
||||
}
|
||||
if err := open.inventory.Take(ctx, "anchor", "store"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, r := range composed(t, open, "anchor").Resources {
|
||||
if r["id"] == catalogue.GuardID() {
|
||||
if r["content"] != catalogue.AsGuard([]int{5432}) {
|
||||
t.Fatalf("the taken store's guard is:\n%s", r["content"])
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatal("a taken store is not guarded")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user