From 0b3969be1e20c6bdea6d51578fb2c245b2b4b296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Garcia?= Date: Sat, 12 Feb 2022 08:12:04 -0300 Subject: [PATCH] Add test for Delete() with maps as arguments --- ksql_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/ksql_test.go b/ksql_test.go index 03ee07a..f2c8cbb 100644 --- a/ksql_test.go +++ b/ksql_test.go @@ -1118,6 +1118,42 @@ func TestDelete(t *testing.T) { tt.AssertEqual(t, userPerms[0].UserID, 1) tt.AssertEqual(t, userPerms[0].PostID, 44) }) + + t.Run("using maps", func(t *testing.T) { + db, closer := connectDB(t, config) + defer closer.Close() + + ctx := context.Background() + c := newTestDB(db, config.driver) + + // This permission should not be deleted, we'll use the id to check it: + p0 := UserPermission{ + UserID: 2, + PostID: 44, + } + err = c.Insert(ctx, NewTable("user_permissions", "id"), &p0) + tt.AssertNoErr(t, err) + tt.AssertNotEqual(t, p0.ID, 0) + + p1 := UserPermission{ + UserID: 2, + PostID: 42, + } + err = c.Insert(ctx, NewTable("user_permissions", "id"), &p1) + tt.AssertNoErr(t, err) + + err = c.Delete(ctx, UserPermissionsTable, map[string]interface{}{ + "user_id": 2, + "post_id": 42, + }) + tt.AssertNoErr(t, err) + + userPerms, err := getUserPermissionsByUser(db, config.driver, 2) + tt.AssertNoErr(t, err) + tt.AssertEqual(t, len(userPerms), 1) + tt.AssertEqual(t, userPerms[0].UserID, 2) + tt.AssertEqual(t, userPerms[0].PostID, 44) + }) }) t.Run("should return ErrRecordNotFound if no rows were deleted", func(t *testing.T) {