diff --git a/go/catalogue/process_bus.go b/go/catalogue/process_bus.go index b83c2e80..710f7b99 100644 --- a/go/catalogue/process_bus.go +++ b/go/catalogue/process_bus.go @@ -19,6 +19,9 @@ type ProcessBus struct { // Emits are the events this process emits, named locally, as the module's own Emits names them // (EmitsAll): a process emits only what its module may emit as a whole. Emits []string `json:"emits,omitempty"` + // Consumes are the events this process hears, each as its module's `consumes` names it: only an event its module + // consumes (design 47 G A-340, after design 42 zfs-owns-zfs V5 and G1). + Consumes []string `json:"consumes,omitempty"` // Queues are the module's own work-queue streams (ADR 0436 ยง6) this process consumes. Queues []string `json:"queues,omitempty"` // State is the module's own state, by local name, this process reads and writes. @@ -97,7 +100,7 @@ func (b *ProcessBus) UnmarshalJSON(raw []byte) error { dec := json.NewDecoder(bytes.NewReader(raw)) dec.DisallowUnknownFields() if err := dec.Decode(&p); err != nil { - return fmt.Errorf("a process's bus is {emits, queues, state, asks, invokes, keeps}: %w", typedUnknown(err)) + return fmt.Errorf("a process's bus is {emits, consumes, queues, state, asks, invokes, keeps}: %w", typedUnknown(err)) } *b = ProcessBus(p) return nil diff --git a/go/catalogue/process_bus_test.go b/go/catalogue/process_bus_test.go index a7b44ab9..842ce474 100644 --- a/go/catalogue/process_bus_test.go +++ b/go/catalogue/process_bus_test.go @@ -1,5 +1,10 @@ package catalogue +import ( + "encoding/json" + "testing" +) + func strSliceEqual(a, b []string) bool { if len(a) != len(b) { return false @@ -11,3 +16,20 @@ func strSliceEqual(a, b []string) bool { } 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") + } +}