mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-27 08:41:57 -06:00
5e85a00cb3
Removes `BaseDendrite` to, hopefully, make testing and composing of components easier in the future.
35 lines
927 B
Go
35 lines
927 B
Go
package testrig
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/matrix-org/dendrite/setup/config"
|
|
"github.com/nats-io/nats.go"
|
|
|
|
"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)
|
|
}
|
|
}
|
|
}
|
|
|
|
func NewOutputEventMsg(t *testing.T, cfg *config.Dendrite, roomID string, update api.OutputEvent) *nats.Msg {
|
|
t.Helper()
|
|
msg := nats.NewMsg(cfg.Global.JetStream.Prefixed(jetstream.OutputRoomEvent))
|
|
msg.Header.Set(jetstream.RoomEventType, string(update.Type))
|
|
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
|
|
}
|