mirror of https://github.com/VinGarcia/ksql.git
Improve tests for the Delete() function
parent
8b897d8ca9
commit
b92a751d5e
30
ksql_test.go
30
ksql_test.go
|
@ -918,6 +918,32 @@ func TestDelete(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should delete one id correctly", func(t *testing.T) {
|
t.Run("should delete one id correctly", func(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
desc string
|
||||||
|
deletionKeyForUser func(u User) interface{}
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "passing only the ID as key",
|
||||||
|
deletionKeyForUser: func(u User) interface{} {
|
||||||
|
return u.ID
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "passing only the entire user",
|
||||||
|
deletionKeyForUser: func(u User) interface{} {
|
||||||
|
return u
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "passing the address of the user",
|
||||||
|
deletionKeyForUser: func(u User) interface{} {
|
||||||
|
return &u
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
db, closer := connectDB(t, config)
|
db, closer := connectDB(t, config)
|
||||||
defer closer.Close()
|
defer closer.Close()
|
||||||
|
|
||||||
|
@ -950,7 +976,7 @@ func TestDelete(t *testing.T) {
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
assert.Equal(t, u2.ID, result.ID)
|
assert.Equal(t, u2.ID, result.ID)
|
||||||
|
|
||||||
err = c.Delete(ctx, UsersTable, u1.ID)
|
err = c.Delete(ctx, UsersTable, test.deletionKeyForUser(u1))
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
|
|
||||||
result = User{}
|
result = User{}
|
||||||
|
@ -964,6 +990,8 @@ func TestDelete(t *testing.T) {
|
||||||
assert.NotEqual(t, uint(0), result.ID)
|
assert.NotEqual(t, uint(0), result.ID)
|
||||||
assert.Equal(t, "Won't be deleted", result.Name)
|
assert.Equal(t, "Won't be deleted", result.Name)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("should delete multiple ids correctly", func(t *testing.T) {
|
t.Run("should delete multiple ids correctly", func(t *testing.T) {
|
||||||
db, closer := connectDB(t, config)
|
db, closer := connectDB(t, config)
|
||||||
|
|
Loading…
Reference in New Issue