diff --git a/pkg/db/test.go b/pkg/db/test.go index 719ddd435..7ef1303e4 100644 --- a/pkg/db/test.go +++ b/pkg/db/test.go @@ -73,8 +73,8 @@ func InitTestFixtures(tablenames ...string) (err error) { return nil } -// AssertDBExists checks and asserts the existence of certain entries in the db -func AssertDBExists(t *testing.T, table string, values map[string]interface{}, custom bool) { +// AssertExists checks and asserts the existence of certain entries in the db +func AssertExists(t *testing.T, table string, values map[string]interface{}, custom bool) { var exists bool var err error v := make(map[string]interface{}) @@ -94,8 +94,8 @@ func AssertDBExists(t *testing.T, table string, values map[string]interface{}, c assert.True(t, exists, fmt.Sprintf("Entries %v do not exist in table %s", values, table)) } -// AssertDBMissing checks and asserts the nonexiste nce of certain entries in the db -func AssertDBMissing(t *testing.T, table string, values map[string]interface{}) { +// AssertMissing checks and asserts the nonexiste nce of certain entries in the db +func AssertMissing(t *testing.T, table string, values map[string]interface{}) { v := make(map[string]interface{}) exists, err := x.Table(table).Where(values).Exist(&v) assert.NoError(t, err, fmt.Sprintf("Failed to assert entries don't exist in db, error was: %s", err)) diff --git a/pkg/models/kanban_test.go b/pkg/models/kanban_test.go index 768c73b42..cd1dc513b 100644 --- a/pkg/models/kanban_test.go +++ b/pkg/models/kanban_test.go @@ -78,7 +78,7 @@ func TestBucket_Delete(t *testing.T) { err = x.Where("bucket_id = ?", 1).Find(&tasks) assert.NoError(t, err) assert.Len(t, tasks, 15) - db.AssertDBMissing(t, "buckets", map[string]interface{}{ + db.AssertMissing(t, "buckets", map[string]interface{}{ "id": 2, "list_id": 1, }) @@ -92,7 +92,7 @@ func TestBucket_Delete(t *testing.T) { err := b.Delete() assert.Error(t, err) assert.True(t, IsErrCannotRemoveLastBucket(err)) - db.AssertDBExists(t, "buckets", map[string]interface{}{ + db.AssertExists(t, "buckets", map[string]interface{}{ "id": 34, "list_id": 18, }, false) diff --git a/pkg/models/label_task_test.go b/pkg/models/label_task_test.go index 152a85f29..27f0348b8 100644 --- a/pkg/models/label_task_test.go +++ b/pkg/models/label_task_test.go @@ -203,7 +203,7 @@ func TestLabelTask_Create(t *testing.T) { t.Errorf("LabelTask.Create() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name()) } if !tt.wantErr { - db.AssertDBExists(t, "label_task", map[string]interface{}{ + db.AssertExists(t, "label_task", map[string]interface{}{ "id": l.ID, "task_id": l.TaskID, "label_id": l.LabelID, @@ -299,7 +299,7 @@ func TestLabelTask_Delete(t *testing.T) { t.Errorf("LabelTask.Delete() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name()) } if !tt.wantForbidden { - db.AssertDBMissing(t, "label_task", map[string]interface{}{ + db.AssertMissing(t, "label_task", map[string]interface{}{ "label_id": l.LabelID, "task_id": l.TaskID, }) diff --git a/pkg/models/label_test.go b/pkg/models/label_test.go index 5b6b7dc22..c5d3dc38e 100644 --- a/pkg/models/label_test.go +++ b/pkg/models/label_test.go @@ -315,7 +315,7 @@ func TestLabel_Create(t *testing.T) { t.Errorf("Label.Create() error = %v, wantErr %v", err, tt.wantErr) } if !tt.wantErr { - db.AssertDBExists(t, "labels", map[string]interface{}{ + db.AssertExists(t, "labels", map[string]interface{}{ "id": l.ID, "title": l.Title, "description": l.Description, @@ -405,7 +405,7 @@ func TestLabel_Update(t *testing.T) { t.Errorf("Label.Update() error = %v, wantErr %v", err, tt.wantErr) } if !tt.wantErr && !tt.wantForbidden { - db.AssertDBExists(t, "labels", map[string]interface{}{ + db.AssertExists(t, "labels", map[string]interface{}{ "id": tt.fields.ID, "title": tt.fields.Title, }, false) @@ -489,7 +489,7 @@ func TestLabel_Delete(t *testing.T) { t.Errorf("Label.Delete() error = %v, wantErr %v", err, tt.wantErr) } if !tt.wantErr && !tt.wantForbidden { - db.AssertDBMissing(t, "labels", map[string]interface{}{ + db.AssertMissing(t, "labels", map[string]interface{}{ "id": l.ID, }) } diff --git a/pkg/models/list_team_test.go b/pkg/models/list_team_test.go index f2d8f2d88..94454bfcf 100644 --- a/pkg/models/list_team_test.go +++ b/pkg/models/list_team_test.go @@ -87,7 +87,7 @@ func TestTeamList_Create(t *testing.T) { assert.True(t, allowed) err := tl.Create(u) assert.NoError(t, err) - db.AssertDBExists(t, "team_list", map[string]interface{}{ + db.AssertExists(t, "team_list", map[string]interface{}{ "team_id": 1, "list_id": 1, "right": RightAdmin, @@ -146,7 +146,7 @@ func TestTeamList_Delete(t *testing.T) { } err := tl.Delete() assert.NoError(t, err) - db.AssertDBMissing(t, "team_list", map[string]interface{}{ + db.AssertMissing(t, "team_list", map[string]interface{}{ "team_id": 1, "list_id": 3, }) @@ -247,7 +247,7 @@ func TestTeamList_Update(t *testing.T) { t.Errorf("TeamList.Update() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name()) } if !tt.wantErr { - db.AssertDBExists(t, "team_list", map[string]interface{}{ + db.AssertExists(t, "team_list", map[string]interface{}{ "list_id": tt.fields.ListID, "team_id": tt.fields.TeamID, "right": tt.fields.Right, diff --git a/pkg/models/list_test.go b/pkg/models/list_test.go index 0dd3cd294..2146a7c71 100644 --- a/pkg/models/list_test.go +++ b/pkg/models/list_test.go @@ -41,7 +41,7 @@ func TestList_CreateOrUpdate(t *testing.T) { } err := list.Create(usr) assert.NoError(t, err) - db.AssertDBExists(t, "list", map[string]interface{}{ + db.AssertExists(t, "list", map[string]interface{}{ "id": list.ID, "title": list.Title, "description": list.Description, @@ -94,7 +94,7 @@ func TestList_CreateOrUpdate(t *testing.T) { } err := list.Create(usr) assert.NoError(t, err) - db.AssertDBExists(t, "list", map[string]interface{}{ + db.AssertExists(t, "list", map[string]interface{}{ "id": list.ID, "title": list.Title, "description": list.Description, @@ -115,7 +115,7 @@ func TestList_CreateOrUpdate(t *testing.T) { list.Description = "Lorem Ipsum dolor sit amet." err := list.Update() assert.NoError(t, err) - db.AssertDBExists(t, "list", map[string]interface{}{ + db.AssertExists(t, "list", map[string]interface{}{ "id": list.ID, "title": list.Title, "description": list.Description, @@ -156,7 +156,7 @@ func TestList_Delete(t *testing.T) { } err := list.Delete() assert.NoError(t, err) - db.AssertDBMissing(t, "list", map[string]interface{}{ + db.AssertMissing(t, "list", map[string]interface{}{ "id": 1, }) } diff --git a/pkg/models/list_users_test.go b/pkg/models/list_users_test.go index f2b497809..dce067bbe 100644 --- a/pkg/models/list_users_test.go +++ b/pkg/models/list_users_test.go @@ -127,7 +127,7 @@ func TestListUser_Create(t *testing.T) { t.Errorf("ListUser.Create() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name()) } if !tt.wantErr { - db.AssertDBExists(t, "users_list", map[string]interface{}{ + db.AssertExists(t, "users_list", map[string]interface{}{ "user_id": ul.UserID, "list_id": tt.fields.ListID, }, false) @@ -306,7 +306,7 @@ func TestListUser_Update(t *testing.T) { t.Errorf("ListUser.Update() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name()) } if !tt.wantErr { - db.AssertDBExists(t, "users_list", map[string]interface{}{ + db.AssertExists(t, "users_list", map[string]interface{}{ "list_id": tt.fields.ListID, "user_id": lu.UserID, "right": tt.fields.Right, @@ -383,7 +383,7 @@ func TestListUser_Delete(t *testing.T) { t.Errorf("ListUser.Delete() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name()) } if !tt.wantErr { - db.AssertDBMissing(t, "users_list", map[string]interface{}{ + db.AssertMissing(t, "users_list", map[string]interface{}{ "user_id": tt.fields.UserID, "list_id": tt.fields.ListID, }) diff --git a/pkg/models/namespace_team_test.go b/pkg/models/namespace_team_test.go index 243161981..8e92473f9 100644 --- a/pkg/models/namespace_team_test.go +++ b/pkg/models/namespace_team_test.go @@ -75,7 +75,7 @@ func TestTeamNamespace_Create(t *testing.T) { assert.True(t, allowed) err := tn.Create(u) assert.NoError(t, err) - db.AssertDBExists(t, "team_namespaces", map[string]interface{}{ + db.AssertExists(t, "team_namespaces", map[string]interface{}{ "team_id": 1, "namespace_id": 1, "right": RightAdmin, @@ -138,7 +138,7 @@ func TestTeamNamespace_Delete(t *testing.T) { assert.True(t, allowed) err := tn.Delete() assert.NoError(t, err) - db.AssertDBMissing(t, "team_namespaces", map[string]interface{}{ + db.AssertMissing(t, "team_namespaces", map[string]interface{}{ "team_id": 7, "namespace_id": 9, }) @@ -239,7 +239,7 @@ func TestTeamNamespace_Update(t *testing.T) { t.Errorf("TeamNamespace.Update() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name()) } if !tt.wantErr { - db.AssertDBExists(t, "team_namespaces", map[string]interface{}{ + db.AssertExists(t, "team_namespaces", map[string]interface{}{ "team_id": tt.fields.TeamID, "namespace_id": tt.fields.NamespaceID, "right": tt.fields.Right, diff --git a/pkg/models/namespace_test.go b/pkg/models/namespace_test.go index 7ddadaf81..27819b3ce 100644 --- a/pkg/models/namespace_test.go +++ b/pkg/models/namespace_test.go @@ -37,7 +37,7 @@ func TestNamespace_Create(t *testing.T) { db.LoadAndAssertFixtures(t) err := dummynamespace.Create(user1) assert.NoError(t, err) - db.AssertDBExists(t, "namespaces", map[string]interface{}{ + db.AssertExists(t, "namespaces", map[string]interface{}{ "title": "Test", "description": "Lorem Ipsum", }, false) @@ -85,7 +85,7 @@ func TestNamespace_Update(t *testing.T) { } err := n.Update() assert.NoError(t, err) - db.AssertDBExists(t, "namespaces", map[string]interface{}{ + db.AssertExists(t, "namespaces", map[string]interface{}{ "id": 1, "title": "Lorem Ipsum", }, false) @@ -130,7 +130,7 @@ func TestNamespace_Delete(t *testing.T) { } err := n.Delete() assert.NoError(t, err) - db.AssertDBMissing(t, "namespaces", map[string]interface{}{ + db.AssertMissing(t, "namespaces", map[string]interface{}{ "id": 1, }) }) diff --git a/pkg/models/namespace_users_test.go b/pkg/models/namespace_users_test.go index 52797ea9a..2950c2e22 100644 --- a/pkg/models/namespace_users_test.go +++ b/pkg/models/namespace_users_test.go @@ -126,7 +126,7 @@ func TestNamespaceUser_Create(t *testing.T) { t.Errorf("NamespaceUser.Create() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name()) } if !tt.wantErr { - db.AssertDBExists(t, "users_namespace", map[string]interface{}{ + db.AssertExists(t, "users_namespace", map[string]interface{}{ "user_id": tt.fields.UserID, "namespace_id": tt.fields.NamespaceID, }, false) @@ -310,7 +310,7 @@ func TestNamespaceUser_Update(t *testing.T) { t.Errorf("NamespaceUser.Update() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name()) } if !tt.wantErr { - db.AssertDBExists(t, "users_namespace", map[string]interface{}{ + db.AssertExists(t, "users_namespace", map[string]interface{}{ "user_id": tt.fields.UserID, "namespace_id": tt.fields.NamespaceID, "right": tt.fields.Right, @@ -387,7 +387,7 @@ func TestNamespaceUser_Delete(t *testing.T) { t.Errorf("NamespaceUser.Delete() Wrong error type! Error = %v, want = %v", err, runtime.FuncForPC(reflect.ValueOf(tt.errType).Pointer()).Name()) } if !tt.wantErr { - db.AssertDBMissing(t, "users_namespace", map[string]interface{}{ + db.AssertMissing(t, "users_namespace", map[string]interface{}{ "user_id": tt.fields.UserID, "namespace_id": tt.fields.NamespaceID, }) diff --git a/pkg/models/saved_filters_test.go b/pkg/models/saved_filters_test.go index 4656f09b7..5838d7110 100644 --- a/pkg/models/saved_filters_test.go +++ b/pkg/models/saved_filters_test.go @@ -65,7 +65,7 @@ func TestSavedFilter_Create(t *testing.T) { vals["filters::jsonb"] = vals["filters"].(string) + "::jsonb" delete(vals, "filters") } - db.AssertDBExists(t, "saved_filters", vals, true) + db.AssertExists(t, "saved_filters", vals, true) } func TestSavedFilter_ReadOne(t *testing.T) { @@ -92,7 +92,7 @@ func TestSavedFilter_Update(t *testing.T) { } err := sf.Update() assert.NoError(t, err) - db.AssertDBExists(t, "saved_filters", map[string]interface{}{ + db.AssertExists(t, "saved_filters", map[string]interface{}{ "id": 1, "title": "NewTitle", "description": "", @@ -106,7 +106,7 @@ func TestSavedFilter_Delete(t *testing.T) { } err := sf.Delete() assert.NoError(t, err) - db.AssertDBMissing(t, "saved_filters", map[string]interface{}{ + db.AssertMissing(t, "saved_filters", map[string]interface{}{ "id": 1, }) } diff --git a/pkg/models/task_comments_test.go b/pkg/models/task_comments_test.go index 1f36cb3ee..f89632f4f 100644 --- a/pkg/models/task_comments_test.go +++ b/pkg/models/task_comments_test.go @@ -35,7 +35,7 @@ func TestTaskComment_Create(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "test", tc.Comment) assert.Equal(t, int64(1), tc.Author.ID) - db.AssertDBExists(t, "task_comments", map[string]interface{}{ + db.AssertExists(t, "task_comments", map[string]interface{}{ "id": tc.ID, "author_id": u.ID, "comment": "test", @@ -60,7 +60,7 @@ func TestTaskComment_Delete(t *testing.T) { tc := &TaskComment{ID: 1} err := tc.Delete() assert.NoError(t, err) - db.AssertDBMissing(t, "task_comments", map[string]interface{}{ + db.AssertMissing(t, "task_comments", map[string]interface{}{ "id": 1, }) }) @@ -82,7 +82,7 @@ func TestTaskComment_Update(t *testing.T) { } err := tc.Update() assert.NoError(t, err) - db.AssertDBExists(t, "task_comments", map[string]interface{}{ + db.AssertExists(t, "task_comments", map[string]interface{}{ "id": 1, "comment": "testing", }, false) diff --git a/pkg/models/task_relation_test.go b/pkg/models/task_relation_test.go index 3528f4b5e..cbb3387a5 100644 --- a/pkg/models/task_relation_test.go +++ b/pkg/models/task_relation_test.go @@ -35,7 +35,7 @@ func TestTaskRelation_Create(t *testing.T) { } err := rel.Create(&user.User{ID: 1}) assert.NoError(t, err) - db.AssertDBExists(t, "task_relations", map[string]interface{}{ + db.AssertExists(t, "task_relations", map[string]interface{}{ "task_id": 1, "other_task_id": 2, "relation_kind": RelationKindSubtask, @@ -52,7 +52,7 @@ func TestTaskRelation_Create(t *testing.T) { } err := rel.Create(&user.User{ID: 1}) assert.NoError(t, err) - db.AssertDBExists(t, "task_relations", map[string]interface{}{ + db.AssertExists(t, "task_relations", map[string]interface{}{ "task_id": 1, "other_task_id": 13, "relation_kind": RelationKindSubtask, @@ -95,7 +95,7 @@ func TestTaskRelation_Delete(t *testing.T) { } err := rel.Delete() assert.NoError(t, err) - db.AssertDBMissing(t, "task_relations", map[string]interface{}{ + db.AssertMissing(t, "task_relations", map[string]interface{}{ "task_id": 1, "other_task_id": 29, "relation_kind": RelationKindSubtask, diff --git a/pkg/models/tasks_test.go b/pkg/models/tasks_test.go index acf9a53bd..3cd02820f 100644 --- a/pkg/models/tasks_test.go +++ b/pkg/models/tasks_test.go @@ -49,7 +49,7 @@ func TestTask_Create(t *testing.T) { assert.Equal(t, int64(18), task.Index) // Assert moving it into the default bucket assert.Equal(t, int64(1), task.BucketID) - db.AssertDBExists(t, "tasks", map[string]interface{}{ + db.AssertExists(t, "tasks", map[string]interface{}{ "id": task.ID, "title": "Lorem", "description": "Lorem Ipsum Dolor", @@ -118,7 +118,7 @@ func TestTask_Update(t *testing.T) { } err := task.Update() assert.NoError(t, err) - db.AssertDBExists(t, "tasks", map[string]interface{}{ + db.AssertExists(t, "tasks", map[string]interface{}{ "id": 1, "title": "test10000", "description": "Lorem Ipsum Dolor", @@ -173,7 +173,7 @@ func TestTask_Delete(t *testing.T) { } err := task.Delete() assert.NoError(t, err) - db.AssertDBMissing(t, "tasks", map[string]interface{}{ + db.AssertMissing(t, "tasks", map[string]interface{}{ "id": 1, }) }) diff --git a/pkg/models/team_members_test.go b/pkg/models/team_members_test.go index 8671edcf7..2bda54a40 100644 --- a/pkg/models/team_members_test.go +++ b/pkg/models/team_members_test.go @@ -37,7 +37,7 @@ func TestTeamMember_Create(t *testing.T) { } err := tm.Create(doer) assert.NoError(t, err) - db.AssertDBExists(t, "team_members", map[string]interface{}{ + db.AssertExists(t, "team_members", map[string]interface{}{ "id": tm.ID, "team_id": 1, "user_id": 3, @@ -84,7 +84,7 @@ func TestTeamMember_Delete(t *testing.T) { } err := tm.Delete() assert.NoError(t, err) - db.AssertDBMissing(t, "team_members", map[string]interface{}{ + db.AssertMissing(t, "team_members", map[string]interface{}{ "team_id": 1, "user_id": 1, }) @@ -102,7 +102,7 @@ func TestTeamMember_Update(t *testing.T) { err := tm.Update() assert.NoError(t, err) assert.False(t, tm.Admin) // Since this endpoint toggles the right, we should get a false for admin back. - db.AssertDBExists(t, "team_members", map[string]interface{}{ + db.AssertExists(t, "team_members", map[string]interface{}{ "team_id": 1, "user_id": 1, "admin": false, @@ -120,7 +120,7 @@ func TestTeamMember_Update(t *testing.T) { err := tm.Update() assert.NoError(t, err) assert.False(t, tm.Admin) - db.AssertDBExists(t, "team_members", map[string]interface{}{ + db.AssertExists(t, "team_members", map[string]interface{}{ "team_id": 1, "user_id": 1, "admin": false, diff --git a/pkg/models/teams_test.go b/pkg/models/teams_test.go index da1a2e25b..02409bce1 100644 --- a/pkg/models/teams_test.go +++ b/pkg/models/teams_test.go @@ -37,7 +37,7 @@ func TestTeam_Create(t *testing.T) { } err := team.Create(doer) assert.NoError(t, err) - db.AssertDBExists(t, "teams", map[string]interface{}{ + db.AssertExists(t, "teams", map[string]interface{}{ "id": team.ID, "name": "Testteam293", "description": "Lorem Ispum", @@ -100,7 +100,7 @@ func TestTeam_Update(t *testing.T) { } err := team.Update() assert.NoError(t, err) - db.AssertDBExists(t, "teams", map[string]interface{}{ + db.AssertExists(t, "teams", map[string]interface{}{ "id": team.ID, "name": "SomethingNew", }, false) @@ -135,7 +135,7 @@ func TestTeam_Delete(t *testing.T) { } err := team.Delete() assert.NoError(t, err) - db.AssertDBMissing(t, "teams", map[string]interface{}{ + db.AssertMissing(t, "teams", map[string]interface{}{ "id": 1, }) })