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") } }