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) } } }