Files
mesh-sdk/go/catalogue/process_bus_test.go
T
2026-11-13 11:36:20 +01:00

36 lines
1.1 KiB
Go

package catalogue
import (
"encoding/json"
"testing"
)
func strSliceEqual(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
// Design 47 G A-340: a process's bus names the events it hears under `consumes`; a bus of today reads as today and an
// unknown key is still refused.
func TestAProcessBusMayNameWhatItConsumes(t *testing.T) {
var heard ProcessBus
if err := json.Unmarshal([]byte(`{"emits":["a"],"consumes":["mesh-conditions.findings-asked"]}`), &heard); err != nil ||
!strSliceEqual(heard.Consumes, []string{"mesh-conditions.findings-asked"}) || !strSliceEqual(heard.Emits, []string{"a"}) {
t.Errorf("a bus's consumes read as %v (%v)", heard.Consumes, err)
}
var today ProcessBus
if err := json.Unmarshal([]byte(`{"emits":["a"],"queues":["q"]}`), &today); err != nil || len(today.Consumes) != 0 {
t.Errorf("a bus of today read as %+v (%v)", today, err)
}
if err := json.Unmarshal([]byte(`{"hears":["x"]}`), &ProcessBus{}); err == nil {
t.Error("an unknown key was accepted")
}
}