From 6fa9787672d0729ec2e9642cfe2879f073b245d1 Mon Sep 17 00:00:00 2001 From: SimoneDutto Date: Mon, 16 Dec 2024 14:40:40 +0100 Subject: [PATCH] add test for group deletion (#1497) * add test for group hard deletion --- internal/dbmodel/group_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/internal/dbmodel/group_test.go b/internal/dbmodel/group_test.go index e9b12b849..6d3725f1e 100644 --- a/internal/dbmodel/group_test.go +++ b/internal/dbmodel/group_test.go @@ -36,3 +36,25 @@ func TestGroupEntry(t *testing.T) { c.Assert(result.Error, qt.IsNil) c.Assert(ge3, qt.DeepEquals, ge) } + +// TestHardDeleteGroupEntry tests hard delete of groups, to make sure we can create a group with the same name after deleting it. +func TestHardDeleteGroupEntry(t *testing.T) { + c := qt.New(t) + db := gormDB(t) + + ge := dbmodel.GroupEntry{ + Name: "test-group-1", + } + c.Assert(db.Create(&ge).Error, qt.IsNil) + c.Assert(ge.ID, qt.Equals, uint(1)) + + c.Assert(db.Delete(ge).Error, qt.IsNil) + + result := db.First(&ge) + c.Assert(result.Error, qt.ErrorMatches, "record not found") + + ge1 := dbmodel.GroupEntry{ + Name: "test-group-1", + } + c.Assert(db.Create(&ge1).Error, qt.IsNil) +}