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/action_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/action_test.go')
-rw-r--r-- | models/action_test.go | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/models/action_test.go b/models/action_test.go index 431469e732..cecc83f86b 100644 --- a/models/action_test.go +++ b/models/action_test.go @@ -103,22 +103,23 @@ func TestPushCommits_ToAPIPayloadCommits(t *testing.T) { pushCommits.Len = len(pushCommits.Commits) payloadCommits := pushCommits.ToAPIPayloadCommits("/username/reponame") - assert.Len(t, payloadCommits, 2) - assert.Equal(t, "abcdef1", payloadCommits[0].ID) - assert.Equal(t, "message1", payloadCommits[0].Message) - assert.Equal(t, "/username/reponame/commit/abcdef1", payloadCommits[0].URL) - assert.Equal(t, "User Two", payloadCommits[0].Committer.Name) - assert.Equal(t, "user2", payloadCommits[0].Committer.UserName) - assert.Equal(t, "User Four", payloadCommits[0].Author.Name) - assert.Equal(t, "user4", payloadCommits[0].Author.UserName) - - assert.Equal(t, "abcdef2", payloadCommits[1].ID) - assert.Equal(t, "message2", payloadCommits[1].Message) - assert.Equal(t, "/username/reponame/commit/abcdef2", payloadCommits[1].URL) - assert.Equal(t, "User Two", payloadCommits[1].Committer.Name) - assert.Equal(t, "user2", payloadCommits[1].Committer.UserName) - assert.Equal(t, "User Two", payloadCommits[1].Author.Name) - assert.Equal(t, "user2", payloadCommits[1].Author.UserName) + if assert.Len(t, payloadCommits, 2) { + assert.Equal(t, "abcdef1", payloadCommits[0].ID) + assert.Equal(t, "message1", payloadCommits[0].Message) + assert.Equal(t, "/username/reponame/commit/abcdef1", payloadCommits[0].URL) + assert.Equal(t, "User Two", payloadCommits[0].Committer.Name) + assert.Equal(t, "user2", payloadCommits[0].Committer.UserName) + assert.Equal(t, "User Four", payloadCommits[0].Author.Name) + assert.Equal(t, "user4", payloadCommits[0].Author.UserName) + + assert.Equal(t, "abcdef2", payloadCommits[1].ID) + assert.Equal(t, "message2", payloadCommits[1].Message) + assert.Equal(t, "/username/reponame/commit/abcdef2", payloadCommits[1].URL) + assert.Equal(t, "User Two", payloadCommits[1].Committer.Name) + assert.Equal(t, "user2", payloadCommits[1].Committer.UserName) + assert.Equal(t, "User Two", payloadCommits[1].Author.Name) + assert.Equal(t, "user2", payloadCommits[1].Author.UserName) + } } func TestPushCommits_AvatarLink(t *testing.T) { @@ -313,9 +314,10 @@ func TestGetFeeds(t *testing.T) { IncludeDeleted: true, }) assert.NoError(t, err) - assert.Len(t, actions, 1) - assert.EqualValues(t, 1, actions[0].ID) - assert.EqualValues(t, user.ID, actions[0].UserID) + if assert.Len(t, actions, 1) { + assert.EqualValues(t, 1, actions[0].ID) + assert.EqualValues(t, user.ID, actions[0].UserID) + } actions, err = GetFeeds(GetFeedsOptions{ RequestedUser: user, @@ -342,8 +344,10 @@ func TestGetFeeds2(t *testing.T) { }) assert.NoError(t, err) assert.Len(t, actions, 1) - assert.EqualValues(t, 2, actions[0].ID) - assert.EqualValues(t, org.ID, actions[0].UserID) + if assert.Len(t, actions, 1) { + assert.EqualValues(t, 2, actions[0].ID) + assert.EqualValues(t, org.ID, actions[0].UserID) + } actions, err = GetFeeds(GetFeedsOptions{ RequestedUser: org, |