Add AssignRoomNID to pre-assign roomNIDs (#3111)

This commit is contained in:
Till 2023-06-13 16:28:41 +02:00 committed by GitHub
parent 2c87972a3a
commit 7a2e325d10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 0 deletions

View file

@ -7,6 +7,7 @@ import (
"time"
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/roomserver/types"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/gomatrixserverlib/spec"
"github.com/stretchr/testify/assert"
@ -199,3 +200,24 @@ func TestUserRoomKeys(t *testing.T) {
assert.Error(t, err)
})
}
func TestAssignRoomNID(t *testing.T) {
ctx := context.Background()
alice := test.NewUser(t)
room := test.NewRoom(t, alice)
roomID, err := spec.NewRoomID(room.ID)
assert.NoError(t, err)
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
db, close := mustCreateRoomserverDatabase(t, dbType)
defer close()
nid, err := db.AssignRoomNID(ctx, *roomID, room.Version)
assert.NoError(t, err)
assert.Greater(t, nid, types.EventNID(0))
_, err = db.AssignRoomNID(ctx, spec.RoomID{}, "notaroomversion")
assert.Error(t, err)
})
}