mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 06:12:45 +00:00
Add roomserver tests (2/?) (#2445)
* Add invite table tests; move variable declarations * Add Membership table tests * Move variable declarations * Add PrevEvents table tests * Add Published table test * Add Redactions tests Fix bug in SQLite markRedactionValidatedSQL * PR comments, better readability for invite tests
This commit is contained in:
parent
1897e2f1c0
commit
6db08b2874
17 changed files with 517 additions and 66 deletions
79
roomserver/storage/tables/published_table_test.go
Normal file
79
roomserver/storage/tables/published_table_test.go
Normal file
|
@ -0,0 +1,79 @@
|
|||
package tables_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/postgres"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/sqlite3"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage/tables"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/dendrite/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func mustCreatePublishedTable(t *testing.T, dbType test.DBType) (tab tables.Published, close func()) {
|
||||
t.Helper()
|
||||
connStr, close := test.PrepareDBConnectionString(t, dbType)
|
||||
db, err := sqlutil.Open(&config.DatabaseOptions{
|
||||
ConnectionString: config.DataSource(connStr),
|
||||
}, sqlutil.NewExclusiveWriter())
|
||||
assert.NoError(t, err)
|
||||
switch dbType {
|
||||
case test.DBTypePostgres:
|
||||
err = postgres.CreatePublishedTable(db)
|
||||
assert.NoError(t, err)
|
||||
tab, err = postgres.PreparePublishedTable(db)
|
||||
case test.DBTypeSQLite:
|
||||
err = sqlite3.CreatePublishedTable(db)
|
||||
assert.NoError(t, err)
|
||||
tab, err = sqlite3.PreparePublishedTable(db)
|
||||
}
|
||||
assert.NoError(t, err)
|
||||
|
||||
return tab, close
|
||||
}
|
||||
|
||||
func TestPublishedTable(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
alice := test.NewUser()
|
||||
|
||||
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
|
||||
tab, close := mustCreatePublishedTable(t, dbType)
|
||||
defer close()
|
||||
|
||||
// Publish some rooms
|
||||
publishedRooms := []string{}
|
||||
for i := 0; i < 10; i++ {
|
||||
room := test.NewRoom(t, alice)
|
||||
published := i%2 == 0
|
||||
err := tab.UpsertRoomPublished(ctx, nil, room.ID, published)
|
||||
assert.NoError(t, err)
|
||||
if published {
|
||||
publishedRooms = append(publishedRooms, room.ID)
|
||||
}
|
||||
publishedRes, err := tab.SelectPublishedFromRoomID(ctx, nil, room.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, published, publishedRes)
|
||||
}
|
||||
sort.Strings(publishedRooms)
|
||||
|
||||
// check that we get the expected published rooms
|
||||
roomIDs, err := tab.SelectAllPublishedRooms(ctx, nil, true)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, publishedRooms, roomIDs)
|
||||
|
||||
// test an actual upsert
|
||||
room := test.NewRoom(t, alice)
|
||||
err = tab.UpsertRoomPublished(ctx, nil, room.ID, true)
|
||||
assert.NoError(t, err)
|
||||
err = tab.UpsertRoomPublished(ctx, nil, room.ID, false)
|
||||
assert.NoError(t, err)
|
||||
// should now be false, due to the upsert
|
||||
publishedRes, err := tab.SelectPublishedFromRoomID(ctx, nil, room.ID)
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, publishedRes)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue