mirror of https://github.com/VinGarcia/ksql.git
Add more tests to Delete
parent
a269036a11
commit
5328be8564
|
@ -1,2 +1,3 @@
|
||||||
.make.setup
|
.make.setup
|
||||||
**/*coverage.txt
|
**/*coverage.txt
|
||||||
|
go.work
|
||||||
|
|
|
@ -67,7 +67,7 @@ func RunTestsForAdapter(
|
||||||
QueryOneTest(t, driver, connStr, newDBAdapter)
|
QueryOneTest(t, driver, connStr, newDBAdapter)
|
||||||
InsertTest(t, driver, connStr, newDBAdapter)
|
InsertTest(t, driver, connStr, newDBAdapter)
|
||||||
DeleteTest(t, driver, connStr, newDBAdapter)
|
DeleteTest(t, driver, connStr, newDBAdapter)
|
||||||
UpdateTest(t, driver, connStr, newDBAdapter)
|
PatchTest(t, driver, connStr, newDBAdapter)
|
||||||
QueryChunksTest(t, driver, connStr, newDBAdapter)
|
QueryChunksTest(t, driver, connStr, newDBAdapter)
|
||||||
TransactionTest(t, driver, connStr, newDBAdapter)
|
TransactionTest(t, driver, connStr, newDBAdapter)
|
||||||
ScanRowsTest(t, driver, connStr, newDBAdapter)
|
ScanRowsTest(t, driver, connStr, newDBAdapter)
|
||||||
|
@ -1266,6 +1266,24 @@ func DeleteTest(
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c := newTestDB(db, driver)
|
c := newTestDB(db, driver)
|
||||||
|
|
||||||
|
err := c.Delete(ctx, NewTable("user_permissions", "user_id", "perm_id"), &struct {
|
||||||
|
// Missing PermID
|
||||||
|
UserID int `ksql:"user_id"`
|
||||||
|
Name string `ksql:"name"`
|
||||||
|
}{
|
||||||
|
UserID: 1,
|
||||||
|
Name: "fake-name",
|
||||||
|
})
|
||||||
|
tt.AssertErrContains(t, err, "missing required", "perm_id")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("map with missing attr", func(t *testing.T) {
|
||||||
|
db, closer := newDBAdapter(t)
|
||||||
|
defer closer.Close()
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
c := newTestDB(db, driver)
|
||||||
|
|
||||||
err := c.Delete(ctx, NewTable("user_permissions", "user_id", "perm_id"), map[string]interface{}{
|
err := c.Delete(ctx, NewTable("user_permissions", "user_id", "perm_id"), map[string]interface{}{
|
||||||
// Missing PermID
|
// Missing PermID
|
||||||
"user_id": 1,
|
"user_id": 1,
|
||||||
|
@ -1281,6 +1299,26 @@ func DeleteTest(
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c := newTestDB(db, driver)
|
c := newTestDB(db, driver)
|
||||||
|
|
||||||
|
err := c.Delete(ctx, NewTable("user_permissions", "user_id", "perm_id"), &struct {
|
||||||
|
UserID int `ksql:"user_id"`
|
||||||
|
PermID *int `ksql:"perm_id"`
|
||||||
|
Name string `ksql:"name"`
|
||||||
|
}{
|
||||||
|
// Null Perm ID
|
||||||
|
UserID: 1,
|
||||||
|
PermID: nil,
|
||||||
|
Name: "fake-name",
|
||||||
|
})
|
||||||
|
tt.AssertErrContains(t, err, "missing required", "perm_id")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("map with NULL attr", func(t *testing.T) {
|
||||||
|
db, closer := newDBAdapter(t)
|
||||||
|
defer closer.Close()
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
c := newTestDB(db, driver)
|
||||||
|
|
||||||
err := c.Delete(ctx, NewTable("user_permissions", "user_id", "perm_id"), map[string]interface{}{
|
err := c.Delete(ctx, NewTable("user_permissions", "user_id", "perm_id"), map[string]interface{}{
|
||||||
// Null Perm ID
|
// Null Perm ID
|
||||||
"user_id": 1,
|
"user_id": 1,
|
||||||
|
@ -1297,6 +1335,26 @@ func DeleteTest(
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c := newTestDB(db, driver)
|
c := newTestDB(db, driver)
|
||||||
|
|
||||||
|
err := c.Delete(ctx, NewTable("user_permissions", "user_id", "perm_id"), &struct {
|
||||||
|
UserID int `ksql:"user_id"`
|
||||||
|
PermID int `ksql:"perm_id"`
|
||||||
|
Name string `ksql:"name"`
|
||||||
|
}{
|
||||||
|
// Zero Perm ID
|
||||||
|
UserID: 1,
|
||||||
|
PermID: 0,
|
||||||
|
Name: "fake-name",
|
||||||
|
})
|
||||||
|
tt.AssertErrContains(t, err, "invalid value", "0", "perm_id")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("map with zero attr", func(t *testing.T) {
|
||||||
|
db, closer := newDBAdapter(t)
|
||||||
|
defer closer.Close()
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
c := newTestDB(db, driver)
|
||||||
|
|
||||||
err := c.Delete(ctx, NewTable("user_permissions", "user_id", "perm_id"), map[string]interface{}{
|
err := c.Delete(ctx, NewTable("user_permissions", "user_id", "perm_id"), map[string]interface{}{
|
||||||
// Zero Perm ID
|
// Zero Perm ID
|
||||||
"user_id": 1,
|
"user_id": 1,
|
||||||
|
@ -1332,15 +1390,15 @@ func DeleteTest(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateTest runs all tests for making sure the Update function is
|
// PatchTest runs all tests for making sure the Patch function is
|
||||||
// working for a given adapter and driver.
|
// working for a given adapter and driver.
|
||||||
func UpdateTest(
|
func PatchTest(
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
driver string,
|
driver string,
|
||||||
connStr string,
|
connStr string,
|
||||||
newDBAdapter func(t *testing.T) (DBAdapter, io.Closer),
|
newDBAdapter func(t *testing.T) (DBAdapter, io.Closer),
|
||||||
) {
|
) {
|
||||||
t.Run("Update", func(t *testing.T) {
|
t.Run("Patch", func(t *testing.T) {
|
||||||
err := createTables(driver, connStr)
|
err := createTables(driver, connStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("could not create test table!, reason:", err.Error())
|
t.Fatal("could not create test table!, reason:", err.Error())
|
||||||
|
|
Loading…
Reference in New Issue