diff options
author | Morlinest <Morlinest@users.noreply.github.com> | 2017-08-28 11:17:45 +0200 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2017-08-28 12:17:45 +0300 |
commit | 8e61823ec403b661359373f8f8b0c9a7c9ea368d (patch) | |
tree | 0ee6d56bf3f1c01348afa2a2f03dfbd6f72815de /models/webhook_test.go | |
parent | ced50e0ec13085504fa19c82f018a2eecb70ff68 (diff) | |
download | gitea-8e61823ec403b661359373f8f8b0c9a7c9ea368d.tar.gz gitea-8e61823ec403b661359373f8f8b0c9a7c9ea368d.zip |
Fix tests code to prevent some runtime errors (#2381)
* Fix tests code to prevent some runtime errors
* Reduce nesting
Diffstat (limited to 'models/webhook_test.go')
-rw-r--r-- | models/webhook_test.go | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/models/webhook_test.go b/models/webhook_test.go index a637a16999..eeae7efbcb 100644 --- a/models/webhook_test.go +++ b/models/webhook_test.go @@ -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) |