From 8e61823ec403b661359373f8f8b0c9a7c9ea368d Mon Sep 17 00:00:00 2001 From: Morlinest Date: Mon, 28 Aug 2017 11:17:45 +0200 Subject: Fix tests code to prevent some runtime errors (#2381) * Fix tests code to prevent some runtime errors * Reduce nesting --- models/webhook_test.go | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'models/webhook_test.go') 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) -- cgit v1.2.3