mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-03 04:03:09 -06:00
Test what happens if we select non-existing NIDs
This commit is contained in:
parent
c89e06bd6f
commit
78ebf6f7ab
|
|
@ -42,6 +42,7 @@ func Test_EventJSONTable(t *testing.T) {
|
||||||
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
|
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
|
||||||
tab, close := mustCreateEventJSONTable(t, dbType)
|
tab, close := mustCreateEventJSONTable(t, dbType)
|
||||||
defer close()
|
defer close()
|
||||||
|
|
||||||
// create some dummy data
|
// create some dummy data
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
err := tab.InsertEventJSON(
|
err := tab.InsertEventJSON(
|
||||||
|
|
@ -50,13 +51,45 @@ func Test_EventJSONTable(t *testing.T) {
|
||||||
)
|
)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
// select a subset of the data
|
|
||||||
values, err := tab.BulkSelectEventJSON(context.Background(), nil, []types.EventNID{1, 2, 3, 4, 5})
|
tests := []struct {
|
||||||
assert.NoError(t, err)
|
name string
|
||||||
assert.Equal(t, 5, len(values))
|
args []types.EventNID
|
||||||
for i, v := range values {
|
wantCount int
|
||||||
assert.Equal(t, v.EventNID, types.EventNID(i+1))
|
}{
|
||||||
assert.Equal(t, []byte(fmt.Sprintf(`{"value":%d"}`, i+1)), v.EventJSON)
|
{
|
||||||
|
name: "select subset of existing NIDs",
|
||||||
|
args: []types.EventNID{1, 2, 3, 4, 5},
|
||||||
|
wantCount: 5,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "select subset of existing/non-existing NIDs",
|
||||||
|
args: []types.EventNID{1, 2, 12, 50},
|
||||||
|
wantCount: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "select single existing NID",
|
||||||
|
args: []types.EventNID{1},
|
||||||
|
wantCount: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "select single non-existing NID",
|
||||||
|
args: []types.EventNID{13},
|
||||||
|
wantCount: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
// select a subset of the data
|
||||||
|
values, err := tab.BulkSelectEventJSON(context.Background(), nil, tc.args)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, tc.wantCount, len(values))
|
||||||
|
for i, v := range values {
|
||||||
|
assert.Equal(t, v.EventNID, types.EventNID(i+1))
|
||||||
|
assert.Equal(t, []byte(fmt.Sprintf(`{"value":%d"}`, i+1)), v.EventJSON)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue