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