From 5328be85649b9706c6787006013978f3990bb5c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Garcia?= Date: Mon, 25 Jul 2022 19:59:36 -0300 Subject: [PATCH] Add more tests to Delete --- .gitignore | 1 + test_adapters.go | 66 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index e60c757..ce5e3e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .make.setup **/*coverage.txt +go.work diff --git a/test_adapters.go b/test_adapters.go index 8933807..820713f 100644 --- a/test_adapters.go +++ b/test_adapters.go @@ -67,7 +67,7 @@ func RunTestsForAdapter( QueryOneTest(t, driver, connStr, newDBAdapter) InsertTest(t, driver, connStr, newDBAdapter) DeleteTest(t, driver, connStr, newDBAdapter) - UpdateTest(t, driver, connStr, newDBAdapter) + PatchTest(t, driver, connStr, newDBAdapter) QueryChunksTest(t, driver, connStr, newDBAdapter) TransactionTest(t, driver, connStr, newDBAdapter) ScanRowsTest(t, driver, connStr, newDBAdapter) @@ -1266,6 +1266,24 @@ func DeleteTest( ctx := context.Background() 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{}{ // Missing PermID "user_id": 1, @@ -1281,6 +1299,26 @@ func DeleteTest( ctx := context.Background() 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{}{ // Null Perm ID "user_id": 1, @@ -1297,6 +1335,26 @@ func DeleteTest( ctx := context.Background() 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{}{ // Zero Perm ID "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. -func UpdateTest( +func PatchTest( t *testing.T, driver string, connStr string, 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) if err != nil { t.Fatal("could not create test table!, reason:", err.Error())