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