2022-05-17 13:23:35 +01:00
|
|
|
package testrig
|
2022-05-09 17:23:02 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
2022-10-05 11:12:42 +01:00
|
|
|
"github.com/nats-io/nats.go"
|
|
|
|
|
2022-05-09 17:23:02 +01:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/api"
|
|
|
|
"github.com/matrix-org/dendrite/setup/base"
|
|
|
|
"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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewOutputEventMsg(t *testing.T, base *base.BaseDendrite, roomID string, update api.OutputEvent) *nats.Msg {
|
|
|
|
t.Helper()
|
2022-10-05 11:12:42 +01:00
|
|
|
msg := nats.NewMsg(base.Cfg.Global.JetStream.Prefixed(jetstream.OutputRoomEvent))
|
|
|
|
msg.Header.Set(jetstream.RoomEventType, string(update.Type))
|
2022-05-09 17:23:02 +01: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
|
|
|
|
}
|