52 lines
2.4 KiB
Go
52 lines
2.4 KiB
Go
package delivery
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
// ADR 0565 clauses 2 and 6 (issue 1953 L5-S2): the control records' layouts read what their writers write. The
|
|
// packages value is the controller's declared-packages mirror's, as its writer's own test pins it (mesh-controller
|
|
// internal/inventory/declared_packages_test.go at 0fbb5ef3); the config declaration is its declared-config mirror's
|
|
// (DeclaredMirrored); a pull request's key is mesh-config's form.
|
|
func TestTheControlRecordsReadTheirWritersValues(t *testing.T) {
|
|
for _, c := range []struct {
|
|
name string
|
|
raw string
|
|
into any
|
|
}{
|
|
{"declared packages", `{"node":"one","packages":[{"package":"curl","modules":["backup","web"],"absent":false},` +
|
|
`{"package":"nano","modules":["web"],"absent":true}]}`, &DeclaredPackages{}},
|
|
{"a config candidate", `{"v":1,"pull":"novox/mesh-catalog#42","head":"abc","declares":{"mail":{"quota":{"kind":"config",` +
|
|
`"default":10,"why":"a quota","type":"integer","minimum":1}}},"at":"2026-10-29T12:00:00Z"}`, &ConfigCandidate{}},
|
|
{"a held value", `{"pull":"novox/mesh-catalog#42","head":"abc","declaration":"sha256:d","node":"novox","module":"mail",` +
|
|
`"key":"quota","value":20,"by":"person.jochen","via":"telegram","why":"more room","approved":"the operator",` +
|
|
`"proposal":"p-1","at":"2026-10-29T12:00:00Z"}`, &KeptValue{}},
|
|
{"the predefined list", `{"v":1,"commit":"abc","at":"2026-10-29T12:00:00Z","list":{"domain":{"type":"string"}}}`, &PredefinedKept{}},
|
|
} {
|
|
if err := json.Unmarshal([]byte(c.raw), c.into); err != nil {
|
|
t.Fatalf("%s: %v", c.name, err)
|
|
}
|
|
again, _ := json.Marshal(c.into)
|
|
var want, got any
|
|
_ = json.Unmarshal([]byte(c.raw), &want)
|
|
_ = json.Unmarshal(again, &got)
|
|
if string(jsonOf(want)) != string(jsonOf(got)) || (c.name == "declared packages" && string(again) != c.raw) {
|
|
t.Errorf("%s reads back as %s", c.name, again)
|
|
}
|
|
}
|
|
if k, err := HeldValueKey("novox/mesh-catalog#42", "novox", "mail", "quota"); k != "novox.mesh-catalog.42.novox.mail.quota" || err != nil {
|
|
t.Errorf("a held value's key is %q, %v", k, err)
|
|
}
|
|
for pull, want := range map[string]string{"novox/mesh-catalog#42": "novox.mesh-catalog.42", "x#1": "", "a/b": "", "a/b.c#1": ""} {
|
|
if got, err := ConfigCandidateKey(pull); got != want || (want == "") != (err != nil) {
|
|
t.Errorf("%s keyed %q, %v", pull, got, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func jsonOf(v any) []byte {
|
|
b, _ := json.Marshal(v)
|
|
return b
|
|
}
|