node-engine client: the node key of the have, the codecs of the health report and of the data items (ADR 0634 §1, §4; issue 1966)
Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
This commit is contained in:
@@ -105,3 +105,46 @@ func TestHaveNodeCodec(t *testing.T) {
|
||||
t.Error("a record differs by its version")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthAndDataCodecs(t *testing.T) {
|
||||
at := time.Date(2026, 11, 5, 12, 0, 0, 0, time.UTC)
|
||||
h := seat.HealthByNodeValue{Node: "n", At: at, Fallback: &seat.LoginFallback{Node: "n", From: "old", Why: "w", At: at}}
|
||||
raw, err := EncodeHealth(h)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
back, err := DecodeHealth(raw)
|
||||
h.V = keys.Version
|
||||
if err != nil || !SameHealth(back, h) {
|
||||
t.Fatalf("round trip: %v %+v", err, back)
|
||||
}
|
||||
later := h
|
||||
later.At = at.Add(time.Hour)
|
||||
if !SameHealth(h, later) {
|
||||
t.Error("a report differs by its time of writing")
|
||||
}
|
||||
for name, bad := range map[string]seat.HealthByNodeValue{
|
||||
"no node": {},
|
||||
"another node": {Node: "n", Fallback: &seat.LoginFallback{Node: "m", From: "o", Why: "w", At: at}},
|
||||
"no time": {Node: "n", Fallback: &seat.LoginFallback{Node: "n", From: "o", Why: "w"}},
|
||||
"no login from": {Node: "n", Fallback: &seat.LoginFallback{Node: "n", Why: "w", At: at}},
|
||||
} {
|
||||
if _, err := EncodeHealth(bad); err == nil {
|
||||
t.Errorf("%s: encoded", name)
|
||||
}
|
||||
}
|
||||
if _, err := DecodeHealth([]byte(`{"v":2,"node":"n"}`)); !errors.Is(err, keys.ErrUnknownVersion) {
|
||||
t.Errorf("version 2: %v", err)
|
||||
}
|
||||
d := seat.DataByNodeModuleValue{Node: "n", Module: "m", Digest: digestA}
|
||||
raw, err = EncodeData(d)
|
||||
if err != nil || !strings.Contains(string(raw), `"items":[]`) {
|
||||
t.Fatalf("data: %v %s", err, raw)
|
||||
}
|
||||
if _, err := EncodeData(seat.DataByNodeModuleValue{Node: "n", Module: "node"}); err == nil {
|
||||
t.Error("the module name node keys")
|
||||
}
|
||||
if k, err := HaveNodeKey("n"); err != nil || k != "n.node" {
|
||||
t.Errorf("node key %q %v", k, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user