Hold a converged declaration to the bytes main sends, captured from it, rather than to re-marshalling itself (hq ADR 0100)
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
|||||||
|
|
||||||
"github.com/novox/mesh-controller/internal/catalogue"
|
"github.com/novox/mesh-controller/internal/catalogue"
|
||||||
"github.com/novox/mesh-controller/internal/inventory"
|
"github.com/novox/mesh-controller/internal/inventory"
|
||||||
|
"github.com/novox/mesh-controller/internal/overlay"
|
||||||
)
|
)
|
||||||
|
|
||||||
// novox/hq ADR 0100: every declaration an adopted node is sent says it is adopted and which modules
|
// novox/hq ADR 0100: every declaration an adopted node is sent says it is adopted and which modules
|
||||||
@@ -41,13 +42,24 @@ func composed(t *testing.T, open *stores, node string) sendable {
|
|||||||
return declared
|
return declared
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convergedBefore is the envelope a converged node was sent before adoption existed, captured by
|
||||||
|
// running this same composition at the commit this branch left main (0a39b7d). The mesh here is
|
||||||
|
// aMesh's laptop with the private network taken off it, so nothing in the declaration is random:
|
||||||
|
// what changes this string is a change to what a converged machine is sent, which is the thing an
|
||||||
|
// older host would refuse.
|
||||||
|
const convergedBefore = `{"declaration":1,"resources":[{"content":"hello","id":"hello-web.page","path":"/var/lib/hello-web/index.html","type":"file"},{"hosts":["anchor.internal:10.77.0.1"],"id":"hello-web.server","image":"registry.example/hello@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","name":"hello-web","type":"container"},{"id":"hello-web.served","path":"/var/lib/hello-web","type":"directory"}]}`
|
||||||
|
|
||||||
func TestAConvergedDeclarationIsByteForByteWhatItWas(t *testing.T) {
|
func TestAConvergedDeclarationIsByteForByteWhatItWas(t *testing.T) {
|
||||||
open := aMesh(t)
|
open := aMesh(t)
|
||||||
|
ctx := t.Context()
|
||||||
register(t, open, helloWeb())
|
register(t, open, helloWeb())
|
||||||
if _, err := assign(t.Context(), open, "anchor", "hello-web"); err != nil {
|
if _, err := unassign(ctx, open, "laptop", overlay.Name); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
declared := composed(t, open, "anchor")
|
if _, err := assign(ctx, open, "laptop", "hello-web"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
declared := composed(t, open, "laptop")
|
||||||
if declared.Adoption != nil {
|
if declared.Adoption != nil {
|
||||||
t.Fatal("a converged node was given an adoption envelope")
|
t.Fatal("a converged node was given an adoption envelope")
|
||||||
}
|
}
|
||||||
@@ -55,13 +67,9 @@ func TestAConvergedDeclarationIsByteForByteWhatItWas(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
// The envelope exactly as every send site marshalled it before adoption existed.
|
if string(body) != convergedBefore {
|
||||||
before, err := json.Marshal(map[string]any{"declaration": 1, "resources": declared.Resources})
|
t.Fatalf("a converged declaration changed; an older host parses this strictly:\n%s\n%s",
|
||||||
if err != nil {
|
body, convergedBefore)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if !bytes.Equal(body, before) {
|
|
||||||
t.Fatalf("a converged declaration changed:\n%s\n%s", body, before)
|
|
||||||
}
|
}
|
||||||
if bytes.Contains(body, []byte(`"adoption"`)) {
|
if bytes.Contains(body, []byte(`"adoption"`)) {
|
||||||
t.Fatal("a converged declaration names adoption; an older host would refuse it")
|
t.Fatal("a converged declaration names adoption; an older host would refuse it")
|
||||||
|
|||||||
Reference in New Issue
Block a user