Files
mesh-catalog/modules/zfs/cmd/zfs-tools/bus_stream_test.go
T
jschoubben 58664eee60 zfs: the hand acts answer started at once and the manifest asks stream-publish, bus-state-calls and ledger-calls (A-43, A-44)
Removes streamHear, HandPoll, HandWait and the stream mark; keeps toolEmit.

Builds: design 42 zfs-owns-zfs §24, §25, lead answers A-43, A-44
2026-11-13 01:52:50 +01:00

30 lines
986 B
Go

package main
import (
"encoding/json"
"errors"
"testing"
"git.novox.be/novox/mesh-sdk/go/buscalls"
)
// A-42: the tool says an event with mesh/stream.publish on the stream `events`, the kind as the event and a message id.
func TestAToolSaysItsEventWithStreamPublish(t *testing.T) {
var got buscalls.StreamPublishRequest
var method string
say := toolEmit(func(m string, p any) (json.RawMessage, error) {
method, got = m, p.(buscalls.StreamPublishRequest)
return json.RawMessage(`{"sequence":9}`), nil
})
if err := say(ScrubEvent, map[string]any{"pool": "tank"}); err != nil {
t.Fatal(err)
}
if method != buscalls.StreamPublish || got.Stream != "events" || got.Event != ScrubEvent || got.ID == "" || string(got.Body) != `{"pool":"tank"}` {
t.Errorf("asked %s %+v", method, got)
}
fail := toolEmit(func(string, any) (json.RawMessage, error) { return nil, errors.New("refused") })
if fail(ScrubEvent, nil) == nil {
t.Error("a refused publish was said done")
}
}