Test what happens if we select non-existing NIDs

This commit is contained in:
Till Faelligen 2022-05-09 14:28:12 +02:00
parent c89e06bd6f
commit 78ebf6f7ab

View file

@ -42,6 +42,7 @@ func Test_EventJSONTable(t *testing.T) {
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
tab, close := mustCreateEventJSONTable(t, dbType)
defer close()
// create some dummy data
for i := 0; i < 10; i++ {
err := tab.InsertEventJSON(
@ -50,13 +51,45 @@ func Test_EventJSONTable(t *testing.T) {
)
assert.NoError(t, err)
}
// select a subset of the data
values, err := tab.BulkSelectEventJSON(context.Background(), nil, []types.EventNID{1, 2, 3, 4, 5})
assert.NoError(t, err)
assert.Equal(t, 5, 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)
tests := []struct {
name string
args []types.EventNID
wantCount int
}{
{
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)
}
})
}
})
}