From 6165d6322c793fc1a11cf15006add5d0ba7e102d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 31 Jul 2019 16:56:04 +0800 Subject: [PATCH] fix tests --- models/action_test.go | 59 ++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/models/action_test.go b/models/action_test.go index d0217e41a8c95..e2546044d4672 100644 --- a/models/action_test.go +++ b/models/action_test.go @@ -100,29 +100,54 @@ func TestPushCommits_ToAPIPayloadCommits(t *testing.T) { AuthorName: "User2", Message: "good signed commit (with not yet validated email)", }, + { + Sha1: "5099b81", + CommitterEmail: "user2@example.com", + CommitterName: "User2", + AuthorEmail: "user2@example.com", + AuthorName: "User2", + Message: "good signed commit", + }, } pushCommits.Len = len(pushCommits.Commits) repo := AssertExistsAndLoadBean(t, &Repository{ID: 16}).(*Repository) payloadCommits, err := pushCommits.ToAPIPayloadCommits(repo.RepoPath(), "/user2/repo16") assert.NoError(t, err) - if assert.Len(t, payloadCommits, 2) { - assert.Equal(t, "69554a6", payloadCommits[0].ID) - assert.Equal(t, "not signed commit", payloadCommits[0].Message) - assert.Equal(t, "/user2/repo16/commit/69554a6", payloadCommits[0].URL) - assert.Equal(t, "User2", payloadCommits[0].Committer.Name) - assert.Equal(t, "user2", payloadCommits[0].Committer.UserName) - assert.Equal(t, "User2", payloadCommits[0].Author.Name) - assert.Equal(t, "user2", payloadCommits[0].Author.UserName) - - assert.Equal(t, "27566bd", payloadCommits[1].ID) - assert.Equal(t, "good signed commit (with not yet validated email)", payloadCommits[1].Message) - assert.Equal(t, "/user2/repo16/commit/27566bd", payloadCommits[1].URL) - assert.Equal(t, "User2", payloadCommits[1].Committer.Name) - assert.Equal(t, "user2", payloadCommits[1].Committer.UserName) - assert.Equal(t, "User2", payloadCommits[1].Author.Name) - assert.Equal(t, "user2", payloadCommits[1].Author.UserName) - } + assert.EqualValues(t, 3, len(payloadCommits)) + + assert.Equal(t, "69554a6", payloadCommits[0].ID) + assert.Equal(t, "not signed commit", payloadCommits[0].Message) + assert.Equal(t, "/user2/repo16/commit/69554a6", payloadCommits[0].URL) + assert.Equal(t, "User2", payloadCommits[0].Committer.Name) + assert.Equal(t, "user2", payloadCommits[0].Committer.UserName) + assert.Equal(t, "User2", payloadCommits[0].Author.Name) + assert.Equal(t, "user2", payloadCommits[0].Author.UserName) + assert.EqualValues(t, []string{}, payloadCommits[0].Added) + assert.EqualValues(t, []string{}, payloadCommits[0].Removed) + assert.EqualValues(t, []string{"readme.md"}, payloadCommits[0].Modified) + + assert.Equal(t, "27566bd", payloadCommits[1].ID) + assert.Equal(t, "good signed commit (with not yet validated email)", payloadCommits[1].Message) + assert.Equal(t, "/user2/repo16/commit/27566bd", payloadCommits[1].URL) + assert.Equal(t, "User2", payloadCommits[1].Committer.Name) + assert.Equal(t, "user2", payloadCommits[1].Committer.UserName) + assert.Equal(t, "User2", payloadCommits[1].Author.Name) + assert.Equal(t, "user2", payloadCommits[1].Author.UserName) + assert.EqualValues(t, []string{}, payloadCommits[1].Added) + assert.EqualValues(t, []string{}, payloadCommits[1].Removed) + assert.EqualValues(t, []string{"readme.md"}, payloadCommits[1].Modified) + + assert.Equal(t, "5099b81", payloadCommits[2].ID) + assert.Equal(t, "good signed commit", payloadCommits[2].Message) + assert.Equal(t, "/user2/repo16/commit/5099b81", payloadCommits[2].URL) + assert.Equal(t, "User2", payloadCommits[2].Committer.Name) + assert.Equal(t, "user2", payloadCommits[2].Committer.UserName) + assert.Equal(t, "User2", payloadCommits[2].Author.Name) + assert.Equal(t, "user2", payloadCommits[2].Author.UserName) + assert.EqualValues(t, []string{"readme.md"}, payloadCommits[2].Added) + assert.EqualValues(t, []string{}, payloadCommits[2].Removed) + assert.EqualValues(t, []string{}, payloadCommits[2].Modified) } func TestPushCommits_AvatarLink(t *testing.T) {