forked from forgejo/forgejo
Fix tests code to prevent some runtime errors (#2381)
* Fix tests code to prevent some runtime errors * Reduce nesting
This commit is contained in:
parent
ced50e0ec1
commit
8e61823ec4
15 changed files with 181 additions and 150 deletions
|
@ -41,8 +41,9 @@ func TestWebhook_History(t *testing.T) {
|
|||
webhook := AssertExistsAndLoadBean(t, &Webhook{ID: 1}).(*Webhook)
|
||||
tasks, err := webhook.History(0)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, tasks, 1)
|
||||
assert.Equal(t, int64(1), tasks[0].ID)
|
||||
if assert.Len(t, tasks, 1) {
|
||||
assert.Equal(t, int64(1), tasks[0].ID)
|
||||
}
|
||||
|
||||
webhook = AssertExistsAndLoadBean(t, &Webhook{ID: 2}).(*Webhook)
|
||||
tasks, err = webhook.History(0)
|
||||
|
@ -123,36 +124,40 @@ func TestGetActiveWebhooksByRepoID(t *testing.T) {
|
|||
assert.NoError(t, PrepareTestDatabase())
|
||||
hooks, err := GetActiveWebhooksByRepoID(1)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, hooks, 1)
|
||||
assert.Equal(t, int64(1), hooks[0].ID)
|
||||
assert.True(t, hooks[0].IsActive)
|
||||
if assert.Len(t, hooks, 1) {
|
||||
assert.Equal(t, int64(1), hooks[0].ID)
|
||||
assert.True(t, hooks[0].IsActive)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetWebhooksByRepoID(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
hooks, err := GetWebhooksByRepoID(1)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, hooks, 2)
|
||||
assert.Equal(t, int64(1), hooks[0].ID)
|
||||
assert.Equal(t, int64(2), hooks[1].ID)
|
||||
if assert.Len(t, hooks, 2) {
|
||||
assert.Equal(t, int64(1), hooks[0].ID)
|
||||
assert.Equal(t, int64(2), hooks[1].ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetActiveWebhooksByOrgID(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
hooks, err := GetActiveWebhooksByOrgID(3)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, hooks, 1)
|
||||
assert.Equal(t, int64(3), hooks[0].ID)
|
||||
assert.True(t, hooks[0].IsActive)
|
||||
if assert.Len(t, hooks, 1) {
|
||||
assert.Equal(t, int64(3), hooks[0].ID)
|
||||
assert.True(t, hooks[0].IsActive)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetWebhooksByOrgID(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
hooks, err := GetWebhooksByOrgID(3)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, hooks, 1)
|
||||
assert.Equal(t, int64(3), hooks[0].ID)
|
||||
assert.True(t, hooks[0].IsActive)
|
||||
if assert.Len(t, hooks, 1) {
|
||||
assert.Equal(t, int64(3), hooks[0].ID)
|
||||
assert.True(t, hooks[0].IsActive)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -211,8 +216,9 @@ func TestHookTasks(t *testing.T) {
|
|||
assert.NoError(t, PrepareTestDatabase())
|
||||
hookTasks, err := HookTasks(1, 1)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, hookTasks, 1)
|
||||
assert.Equal(t, int64(1), hookTasks[0].ID)
|
||||
if assert.Len(t, hookTasks, 1) {
|
||||
assert.Equal(t, int64(1), hookTasks[0].ID)
|
||||
}
|
||||
|
||||
hookTasks, err = HookTasks(NonexistentID, 1)
|
||||
assert.NoError(t, err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue