41 lines
2.1 KiB
Go
41 lines
2.1 KiB
Go
package enginereads
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// The answer and the event are judged as the contract lays them out and its reader checks: the layout's version, a node
|
|
// that is a name, no empty capability, a time, and an event's why one of the two.
|
|
func TestTheAnswerAndTheEventAreJudged(t *testing.T) {
|
|
const at = "2026-11-05T12:00:00Z"
|
|
for name, c := range map[string]struct{ body, bad string }{
|
|
"whole": {`{"v":1,"node":"ace","manifest-reads":["mesh-config.resolved"],"stated-at":"` + at + `"}`, ""},
|
|
"old layout": {`{"v":2,"node":"ace","stated-at":"` + at + `"}`, "version"},
|
|
"bad node": {`{"v":1,"node":"a.b","stated-at":"` + at + `"}`, "no node"},
|
|
"empty read": {`{"v":1,"node":"ace","manifest-reads":[" "],"stated-at":"` + at + `"}`, "empty reader"},
|
|
"no time": {`{"v":1,"node":"ace","stated-at":"yesterday"}`, "RFC 3339"},
|
|
} {
|
|
_, _, err := DecodeAnswer([]byte(c.body))
|
|
if (c.bad == "") != (err == nil) || (err != nil && !strings.Contains(err.Error(), c.bad)) {
|
|
t.Errorf("answer %s: %v, want %q", name, err, c.bad)
|
|
}
|
|
}
|
|
for name, c := range map[string]struct{ body, bad string }{
|
|
"whole": {`{"v":1,"node":"ace","why":"started","manifest-reads":["a.b"],"at":"` + at + `"}`, ""},
|
|
"returned": {`{"v":1,"node":"ace","why":"returned","at":"` + at + `"}`, ""},
|
|
"old layout": {`{"v":2,"node":"ace","why":"started","at":"` + at + `"}`, "version"},
|
|
"no node": {`{"v":1,"node":"","why":"started","at":"` + at + `"}`, "no node"},
|
|
"another why": {`{"v":1,"node":"ace","why":"bored","at":"` + at + `"}`, "bored"},
|
|
"no time": {`{"v":1,"node":"ace","why":"started","at":"yesterday"}`, "RFC 3339"},
|
|
} {
|
|
_, err := DecodeChanged([]byte(c.body))
|
|
if (c.bad == "") != (err == nil) || (err != nil && !strings.Contains(err.Error(), c.bad)) {
|
|
t.Errorf("event %s: %v, want %q", name, err, c.bad)
|
|
}
|
|
}
|
|
if Verb != "manifest-reads" || Event != "manifest-reads-changed" || Consumes != "node-engine.manifest-reads-changed" || Invoke != "seat:node-engine.manifest-reads" {
|
|
t.Errorf("the names are %s %s %s %s", Verb, Event, Consumes, Invoke)
|
|
}
|
|
}
|