2022-05-17 12:23:35 +00:00
|
|
|
package testrig
|
2022-05-09 16:23:02 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-22 08:21:32 +00:00
|
|
|
"github.com/matrix-org/dendrite/setup/config"
|
2022-10-05 10:12:42 +00:00
|
|
|
"github.com/nats-io/nats.go"
|
|
|
|
|
2022-05-09 16:23:02 +00:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/api"
|
|
|
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
|
|
|
)
|
|
|
|
|
|
|
|
func MustPublishMsgs(t *testing.T, jsctx nats.JetStreamContext, msgs ...*nats.Msg) {
|
|
|
|
t.Helper()
|
|
|
|
for _, msg := range msgs {
|
|
|
|
if _, err := jsctx.PublishMsg(msg); err != nil {
|
|
|
|
t.Fatalf("MustPublishMsgs: failed to publish message: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-22 08:21:32 +00:00
|
|
|
func NewOutputEventMsg(t *testing.T, cfg *config.Dendrite, roomID string, update api.OutputEvent) *nats.Msg {
|
2022-05-09 16:23:02 +00:00
|
|
|
t.Helper()
|
2023-03-22 08:21:32 +00:00
|
|
|
msg := nats.NewMsg(cfg.Global.JetStream.Prefixed(jetstream.OutputRoomEvent))
|
2022-10-05 10:12:42 +00:00
|
|
|
msg.Header.Set(jetstream.RoomEventType, string(update.Type))
|
2022-05-09 16:23:02 +00:00
|
|
|
msg.Header.Set(jetstream.RoomID, roomID)
|
|
|
|
var err error
|
|
|
|
msg.Data, err = json.Marshal(update)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to marshal update: %s", err)
|
|
|
|
}
|
|
|
|
return msg
|
|
|
|
}
|