Change method names to avoid doubling db
Signed-off-by: kolaente <k@knt.li>
This commit is contained in:
parent
b919c99704
commit
55a670dbe2
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue