Files
mesh-contracts/go/clients/meshconfigclient/client_test.go
T
jschoubben 821d611530 Round 2 T1, T2, T5: the contracts end G with no more tests than at their merge base; fixtures name roles
The test that read every fixture for the operator's account and a node goes (T1); the tests G added
fold into existing ones as subtests, so each module counts its merge base (design 47 G §626, A-306);
node names in the lines G adds are role names (T5).

Builds: design 47 G §626, A-306; review round 2 findings T1, T2, T5
Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
2026-11-12 22:18:04 +01:00

46 lines
2.0 KiB
Go

package meshconfigclient
import (
"strings"
"testing"
)
// The keys are the earlier form of go/delivery's HeldValueKey and ConfigCandidateKey (golden), which the holder writes.
func TestKeysAreTheEarlierForm(t *testing.T) {
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 := PullKey(pull); got != want || (want == "") != (err != nil) {
t.Errorf("%s keyed %q, %v", pull, got, err)
}
}
if _, err := HeldValueKey("novox/mesh-catalog#42", "", "mail", "quota"); err == nil {
t.Error("a held value without a node was keyed")
}
}
const held = `{"pull":"novox/mesh-catalog#434","head":"abc1234def","declaration":"sha256:3a7b","node":"ace","module":"n8n","key":"media-gid","value":2000,"by":"the operator","approved":"operator@telegram","at":"2026-11-05T12:30:00Z"}`
func TestAHeldValueIsTheOneItsKeyNames(t *testing.T) {
key := "novox.mesh-catalog.434.ace.n8n.media-gid"
v, err := DecodeKept(key, []byte(held))
if err != nil || v.Node != "ace" || v.Value != float64(2000) {
t.Fatalf("read %+v, %v", v, err)
}
if raw, err := ValueOf(v); err != nil || string(raw) != "2000" {
t.Errorf("the value is %s, %v", raw, err)
}
for name, c := range map[string]struct{ key, raw string }{
"another pull request's key": {"novox.mesh-catalog.435.ace.n8n.media-gid", held},
"another module's key": {"novox.mesh-catalog.434.ace.plex.media-gid", held},
"no head": {key, strings.Replace(held, `"head":"abc1234def",`, "", 1)},
"a field it does not know": {key, strings.Replace(held, `"by"`, `"extra":1,"by"`, 1)},
"a pull that is not one": {key, strings.Replace(held, "novox/mesh-catalog#434", "novox", 1)},
} {
if _, err := DecodeKept(c.key, []byte(c.raw)); err == nil {
t.Errorf("%s was read", name)
}
}
}