Fix unit tests hopefully

This commit is contained in:
Neil Alexander 2022-01-07 17:12:20 +00:00
parent 9e341501b2
commit 5a884fd4c0
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
2 changed files with 10 additions and 4 deletions

View file

@ -68,6 +68,13 @@ func TestMain(m *testing.M) {
panic("can't create cache: " + err.Error())
}
// Create a temporary directory for JetStream.
d, err := ioutil.TempDir("./", "jetstream*")
if err != nil {
panic(err)
}
defer os.RemoveAll(d)
// Draw up just enough Dendrite config for the server key
// API to work.
cfg := &config.Dendrite{}
@ -75,6 +82,8 @@ func TestMain(m *testing.M) {
cfg.Global.ServerName = gomatrixserverlib.ServerName(s.name)
cfg.Global.PrivateKey = testPriv
cfg.Global.JetStream.InMemory = true
cfg.Global.JetStream.TopicPrefix = string(s.name[:1])
cfg.Global.JetStream.StoragePath = config.Path(d)
cfg.Global.KeyID = serverKeyID
cfg.Global.KeyValidityPeriod = s.validity
cfg.FederationAPI.Database.ConnectionString = config.DataSource("file::memory:")

View file

@ -74,10 +74,7 @@ func setupNATS(cfg *config.JetStream, nc *natsclient.Conn) (nats.JetStreamContex
logrus.WithError(err).Fatal("Unable to get stream info")
}
if info == nil {
// Define a default subject if not already specified.
if len(stream.Subjects) == 0 {
stream.Subjects = []string{name}
}
stream.Subjects = []string{name}
// If we're trying to keep everything in memory (e.g. unit tests)
// then overwrite the storage policy.