diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2021-06-07 07:27:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-07 07:27:09 +0200 |
commit | 3607f79d7869046d919fed05a21b55b6e61df1fa (patch) | |
tree | 9a176a4d5b67ac3a81ae210e9164d81959221ce0 /models | |
parent | 51775f65bc933843199320b040186703a2bb9f51 (diff) | |
download | gitea-3607f79d7869046d919fed05a21b55b6e61df1fa.tar.gz gitea-3607f79d7869046d919fed05a21b55b6e61df1fa.zip |
Fixed assert statements. (#16089)
Diffstat (limited to 'models')
-rw-r--r-- | models/attachment_test.go | 6 | ||||
-rw-r--r-- | models/issue_stopwatch_test.go | 2 | ||||
-rw-r--r-- | models/issue_watch_test.go | 2 | ||||
-rw-r--r-- | models/issue_xref_test.go | 8 | ||||
-rw-r--r-- | models/oauth2_application_test.go | 4 | ||||
-rw-r--r-- | models/org_test.go | 20 | ||||
-rw-r--r-- | models/repo_generate_test.go | 2 | ||||
-rw-r--r-- | models/repo_test.go | 12 | ||||
-rw-r--r-- | models/topic_test.go | 14 | ||||
-rw-r--r-- | models/user_heatmap_test.go | 4 | ||||
-rw-r--r-- | models/user_mail_test.go | 8 | ||||
-rw-r--r-- | models/user_openid_test.go | 10 | ||||
-rw-r--r-- | models/user_test.go | 6 |
13 files changed, 49 insertions, 49 deletions
diff --git a/models/attachment_test.go b/models/attachment_test.go index fa7fd3471b..700b7c09db 100644 --- a/models/attachment_test.go +++ b/models/attachment_test.go @@ -61,11 +61,11 @@ func TestGetByCommentOrIssueID(t *testing.T) { // count of attachments from issue ID attachments, err := GetAttachmentsByIssueID(1) assert.NoError(t, err) - assert.Equal(t, 1, len(attachments)) + assert.Len(t, attachments, 1) attachments, err = GetAttachmentsByCommentID(1) assert.NoError(t, err) - assert.Equal(t, 2, len(attachments)) + assert.Len(t, attachments, 2) } func TestDeleteAttachments(t *testing.T) { @@ -122,7 +122,7 @@ func TestGetAttachmentsByUUIDs(t *testing.T) { attachList, err := GetAttachmentsByUUIDs(DefaultDBContext(), []string{"a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a17", "not-existing-uuid"}) assert.NoError(t, err) - assert.Equal(t, 2, len(attachList)) + assert.Len(t, attachList, 2) assert.Equal(t, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attachList[0].UUID) assert.Equal(t, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a17", attachList[1].UUID) assert.Equal(t, int64(1), attachList[0].IssueID) diff --git a/models/issue_stopwatch_test.go b/models/issue_stopwatch_test.go index 6fc2b1ce5d..b6af5e93b5 100644 --- a/models/issue_stopwatch_test.go +++ b/models/issue_stopwatch_test.go @@ -67,7 +67,7 @@ func TestCreateOrStopIssueStopwatch(t *testing.T) { assert.NoError(t, CreateOrStopIssueStopwatch(user3, issue1)) sw := AssertExistsAndLoadBean(t, &Stopwatch{UserID: 3, IssueID: 1}).(*Stopwatch) - assert.Equal(t, true, sw.CreatedUnix <= timeutil.TimeStampNow()) + assert.LessOrEqual(t, sw.CreatedUnix, timeutil.TimeStampNow()) assert.NoError(t, CreateOrStopIssueStopwatch(user2, issue2)) AssertNotExistsBean(t, &Stopwatch{UserID: 2, IssueID: 2}) diff --git a/models/issue_watch_test.go b/models/issue_watch_test.go index 762b1486c6..013ca67e1e 100644 --- a/models/issue_watch_test.go +++ b/models/issue_watch_test.go @@ -32,7 +32,7 @@ func TestGetIssueWatch(t *testing.T) { iw, exists, err := GetIssueWatch(2, 2) assert.True(t, exists) assert.NoError(t, err) - assert.EqualValues(t, false, iw.IsWatching) + assert.False(t, iw.IsWatching) _, exists, err = GetIssueWatch(3, 1) assert.False(t, exists) diff --git a/models/issue_xref_test.go b/models/issue_xref_test.go index 936d1124be..f7a1adb083 100644 --- a/models/issue_xref_test.go +++ b/models/issue_xref_test.go @@ -25,7 +25,7 @@ func TestXRef_AddCrossReferences(t *testing.T) { ref := AssertExistsAndLoadBean(t, &Comment{IssueID: itarget.ID, RefIssueID: pr.ID, RefCommentID: 0}).(*Comment) assert.Equal(t, CommentTypePullRef, ref.Type) assert.Equal(t, pr.RepoID, ref.RefRepoID) - assert.Equal(t, true, ref.RefIsPull) + assert.True(t, ref.RefIsPull) assert.Equal(t, references.XRefActionCloses, ref.RefAction) // Comment on PR to reopen issue #1 @@ -34,7 +34,7 @@ func TestXRef_AddCrossReferences(t *testing.T) { ref = AssertExistsAndLoadBean(t, &Comment{IssueID: itarget.ID, RefIssueID: pr.ID, RefCommentID: c.ID}).(*Comment) assert.Equal(t, CommentTypeCommentRef, ref.Type) assert.Equal(t, pr.RepoID, ref.RefRepoID) - assert.Equal(t, true, ref.RefIsPull) + assert.True(t, ref.RefIsPull) assert.Equal(t, references.XRefActionReopens, ref.RefAction) // Issue mentioning issue #1 @@ -43,7 +43,7 @@ func TestXRef_AddCrossReferences(t *testing.T) { ref = AssertExistsAndLoadBean(t, &Comment{IssueID: itarget.ID, RefIssueID: i.ID, RefCommentID: 0}).(*Comment) assert.Equal(t, CommentTypeIssueRef, ref.Type) assert.Equal(t, pr.RepoID, ref.RefRepoID) - assert.Equal(t, false, ref.RefIsPull) + assert.False(t, ref.RefIsPull) assert.Equal(t, references.XRefActionNone, ref.RefAction) // Issue #4 to test against @@ -55,7 +55,7 @@ func TestXRef_AddCrossReferences(t *testing.T) { ref = AssertExistsAndLoadBean(t, &Comment{IssueID: itarget.ID, RefIssueID: i.ID, RefCommentID: 0}).(*Comment) assert.Equal(t, CommentTypeIssueRef, ref.Type) assert.Equal(t, i.RepoID, ref.RefRepoID) - assert.Equal(t, false, ref.RefIsPull) + assert.False(t, ref.RefIsPull) assert.Equal(t, references.XRefActionNone, ref.RefAction) // Cross-reference to issue #4 with no permission diff --git a/models/oauth2_application_test.go b/models/oauth2_application_test.go index 511d019465..7a4bce85c0 100644 --- a/models/oauth2_application_test.go +++ b/models/oauth2_application_test.go @@ -219,11 +219,11 @@ func TestOAuth2AuthorizationCode_GenerateRedirectURI(t *testing.T) { redirect, err := code.GenerateRedirectURI("thestate") assert.NoError(t, err) - assert.Equal(t, redirect.String(), "https://example.com/callback?code=thecode&state=thestate") + assert.Equal(t, "https://example.com/callback?code=thecode&state=thestate", redirect.String()) redirect, err = code.GenerateRedirectURI("") assert.NoError(t, err) - assert.Equal(t, redirect.String(), "https://example.com/callback?code=thecode") + assert.Equal(t, "https://example.com/callback?code=thecode", redirect.String()) } func TestOAuth2AuthorizationCode_Invalidate(t *testing.T) { diff --git a/models/org_test.go b/models/org_test.go index 66979714c1..bed7a6eb86 100644 --- a/models/org_test.go +++ b/models/org_test.go @@ -453,7 +453,7 @@ func TestAddOrgUser(t *testing.T) { assert.NoError(t, AddOrgUser(orgID, userID)) ou := &OrgUser{OrgID: orgID, UID: userID} AssertExistsAndLoadBean(t, ou) - assert.Equal(t, ou.IsPublic, isPublic) + assert.Equal(t, isPublic, ou.IsPublic) org = AssertExistsAndLoadBean(t, &User{ID: orgID}).(*User) assert.EqualValues(t, expectedNumMembers, org.NumMembers) } @@ -589,9 +589,9 @@ func TestHasOrgVisibleTypePublic(t *testing.T) { test1 := HasOrgVisible(org, owner) test2 := HasOrgVisible(org, user3) test3 := HasOrgVisible(org, nil) - assert.Equal(t, test1, true) // owner of org - assert.Equal(t, test2, true) // user not a part of org - assert.Equal(t, test3, true) // logged out user + assert.True(t, test1) // owner of org + assert.True(t, test2) // user not a part of org + assert.True(t, test3) // logged out user } func TestHasOrgVisibleTypeLimited(t *testing.T) { @@ -612,9 +612,9 @@ func TestHasOrgVisibleTypeLimited(t *testing.T) { test1 := HasOrgVisible(org, owner) test2 := HasOrgVisible(org, user3) test3 := HasOrgVisible(org, nil) - assert.Equal(t, test1, true) // owner of org - assert.Equal(t, test2, true) // user not a part of org - assert.Equal(t, test3, false) // logged out user + assert.True(t, test1) // owner of org + assert.True(t, test2) // user not a part of org + assert.False(t, test3) // logged out user } func TestHasOrgVisibleTypePrivate(t *testing.T) { @@ -635,9 +635,9 @@ func TestHasOrgVisibleTypePrivate(t *testing.T) { test1 := HasOrgVisible(org, owner) test2 := HasOrgVisible(org, user3) test3 := HasOrgVisible(org, nil) - assert.Equal(t, test1, true) // owner of org - assert.Equal(t, test2, false) // user not a part of org - assert.Equal(t, test3, false) // logged out user + assert.True(t, test1) // owner of org + assert.False(t, test2) // user not a part of org + assert.False(t, test3) // logged out user } func TestGetUsersWhoCanCreateOrgRepo(t *testing.T) { diff --git a/models/repo_generate_test.go b/models/repo_generate_test.go index 53ab4fcd3d..e7a93433a7 100644 --- a/models/repo_generate_test.go +++ b/models/repo_generate_test.go @@ -25,7 +25,7 @@ text/*.txt func TestGiteaTemplate(t *testing.T) { gt := GiteaTemplate{Content: giteaTemplate} - assert.Equal(t, len(gt.Globs()), 3) + assert.Len(t, gt.Globs(), 3) tt := []struct { Path string diff --git a/models/repo_test.go b/models/repo_test.go index 10ba2c99f8..28eb9baa17 100644 --- a/models/repo_test.go +++ b/models/repo_test.go @@ -61,8 +61,8 @@ func TestMetas(t *testing.T) { metas = repo.ComposeMetas() assert.Contains(t, metas, "org") assert.Contains(t, metas, "teams") - assert.Equal(t, metas["org"], "user3") - assert.Equal(t, metas["teams"], ",owners,team1,") + assert.Equal(t, "user3", metas["org"]) + assert.Equal(t, ",owners,team1,", metas["teams"]) } func TestGetRepositoryCount(t *testing.T) { @@ -111,7 +111,7 @@ func TestUpdateRepositoryVisibilityChanged(t *testing.T) { _, err = x.ID(3).Get(&act) assert.NoError(t, err) - assert.Equal(t, true, act.IsPrivate) + assert.True(t, act.IsPrivate) } func TestGetUserFork(t *testing.T) { @@ -199,13 +199,13 @@ func TestRepoGetReviewers(t *testing.T) { reviewers, err := repo1.GetReviewers(2, 2) assert.NoError(t, err) - assert.Equal(t, 4, len(reviewers)) + assert.Len(t, reviewers, 4) // test private repo repo2 := AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository) reviewers, err = repo2.GetReviewers(2, 2) assert.NoError(t, err) - assert.Equal(t, 0, len(reviewers)) + assert.Empty(t, reviewers) } func TestRepoGetReviewerTeams(t *testing.T) { @@ -219,5 +219,5 @@ func TestRepoGetReviewerTeams(t *testing.T) { repo3 := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) teams, err = repo3.GetReviewerTeams() assert.NoError(t, err) - assert.Equal(t, 2, len(teams)) + assert.Len(t, teams, 2) } diff --git a/models/topic_test.go b/models/topic_test.go index b6ef8f565c..25232eb981 100644 --- a/models/topic_test.go +++ b/models/topic_test.go @@ -19,31 +19,31 @@ func TestAddTopic(t *testing.T) { topics, err := FindTopics(&FindTopicOptions{}) assert.NoError(t, err) - assert.EqualValues(t, totalNrOfTopics, len(topics)) + assert.Len(t, topics, totalNrOfTopics) topics, err = FindTopics(&FindTopicOptions{ ListOptions: ListOptions{Page: 1, PageSize: 2}, }) assert.NoError(t, err) - assert.EqualValues(t, 2, len(topics)) + assert.Len(t, topics, 2) topics, err = FindTopics(&FindTopicOptions{ RepoID: 1, }) assert.NoError(t, err) - assert.EqualValues(t, repo1NrOfTopics, len(topics)) + assert.Len(t, topics, repo1NrOfTopics) assert.NoError(t, SaveTopics(2, "golang")) repo2NrOfTopics = 1 topics, err = FindTopics(&FindTopicOptions{}) assert.NoError(t, err) - assert.EqualValues(t, totalNrOfTopics, len(topics)) + assert.Len(t, topics, totalNrOfTopics) topics, err = FindTopics(&FindTopicOptions{ RepoID: 2, }) assert.NoError(t, err) - assert.EqualValues(t, repo2NrOfTopics, len(topics)) + assert.Len(t, topics, repo2NrOfTopics) assert.NoError(t, SaveTopics(2, "golang", "gitea")) repo2NrOfTopics = 2 @@ -54,13 +54,13 @@ func TestAddTopic(t *testing.T) { topics, err = FindTopics(&FindTopicOptions{}) assert.NoError(t, err) - assert.EqualValues(t, totalNrOfTopics, len(topics)) + assert.Len(t, topics, totalNrOfTopics) topics, err = FindTopics(&FindTopicOptions{ RepoID: 2, }) assert.NoError(t, err) - assert.EqualValues(t, repo2NrOfTopics, len(topics)) + assert.Len(t, topics, repo2NrOfTopics) } func TestTopicValidator(t *testing.T) { diff --git a/models/user_heatmap_test.go b/models/user_heatmap_test.go index cc08ac1551..31e78a19cc 100644 --- a/models/user_heatmap_test.go +++ b/models/user_heatmap_test.go @@ -52,8 +52,8 @@ func TestGetUserHeatmapDataByUser(t *testing.T) { // Get the heatmap and compare heatmap, err := GetUserHeatmapDataByUser(user, doer) assert.NoError(t, err) - assert.Equal(t, len(actions), len(heatmap), "invalid action count: did the test data became too old?") - assert.Equal(t, tc.CountResult, len(heatmap), fmt.Sprintf("testcase %d", i)) + assert.Len(t, heatmap, len(actions), "invalid action count: did the test data became too old?") + assert.Len(t, heatmap, tc.CountResult, fmt.Sprintf("testcase %d", i)) // Test JSON rendering json := jsoniter.ConfigCompatibleWithStandardLibrary diff --git a/models/user_mail_test.go b/models/user_mail_test.go index 8237ce6642..5a223dd040 100644 --- a/models/user_mail_test.go +++ b/models/user_mail_test.go @@ -129,14 +129,14 @@ func TestMakeEmailPrimary(t *testing.T) { } err := MakeEmailPrimary(email) assert.Error(t, err) - assert.Equal(t, ErrEmailNotExist.Error(), err.Error()) + assert.EqualError(t, err, ErrEmailNotExist.Error()) email = &EmailAddress{ Email: "user11@example.com", } err = MakeEmailPrimary(email) assert.Error(t, err) - assert.Equal(t, ErrEmailNotActivated.Error(), err.Error()) + assert.EqualError(t, err, ErrEmailNotActivated.Error()) email = &EmailAddress{ Email: "user9999999@example.com", @@ -232,6 +232,6 @@ func TestListEmails(t *testing.T) { } emails, count, err = SearchEmails(opts) assert.NoError(t, err) - assert.Equal(t, 5, len(emails)) - assert.True(t, count > int64(len(emails))) + assert.Len(t, emails, 5) + assert.Greater(t, count, int64(len(emails))) } diff --git a/models/user_openid_test.go b/models/user_openid_test.go index 18f84bef76..d04b072279 100644 --- a/models/user_openid_test.go +++ b/models/user_openid_test.go @@ -15,15 +15,15 @@ func TestGetUserOpenIDs(t *testing.T) { oids, err := GetUserOpenIDs(int64(1)) if assert.NoError(t, err) && assert.Len(t, oids, 2) { - assert.Equal(t, oids[0].URI, "https://user1.domain1.tld/") + assert.Equal(t, "https://user1.domain1.tld/", oids[0].URI) assert.False(t, oids[0].Show) - assert.Equal(t, oids[1].URI, "http://user1.domain2.tld/") + assert.Equal(t, "http://user1.domain2.tld/", oids[1].URI) assert.True(t, oids[1].Show) } oids, err = GetUserOpenIDs(int64(2)) if assert.NoError(t, err) && assert.Len(t, oids, 1) { - assert.Equal(t, oids[0].URI, "https://domain1.tld/user2/") + assert.Equal(t, "https://domain1.tld/user2/", oids[0].URI) assert.True(t, oids[0].Show) } } @@ -38,12 +38,12 @@ func TestGetUserByOpenID(t *testing.T) { user, err := GetUserByOpenID("https://user1.domain1.tld") if assert.NoError(t, err) { - assert.Equal(t, user.ID, int64(1)) + assert.Equal(t, int64(1), user.ID) } user, err = GetUserByOpenID("https://domain1.tld/user2/") if assert.NoError(t, err) { - assert.Equal(t, user.ID, int64(2)) + assert.Equal(t, int64(2), user.ID) } } diff --git a/models/user_test.go b/models/user_test.go index e0d4e164fc..39a1b3c989 100644 --- a/models/user_test.go +++ b/models/user_test.go @@ -386,14 +386,14 @@ func TestGetMaileableUsersByIDs(t *testing.T) { results, err := GetMaileableUsersByIDs([]int64{1, 4}, false) assert.NoError(t, err) - assert.Equal(t, 1, len(results)) + assert.Len(t, results, 1) if len(results) > 1 { assert.Equal(t, results[0].ID, 1) } results, err = GetMaileableUsersByIDs([]int64{1, 4}, true) assert.NoError(t, err) - assert.Equal(t, 2, len(results)) + assert.Len(t, results, 2) if len(results) > 2 { assert.Equal(t, results[0].ID, 1) assert.Equal(t, results[1].ID, 4) @@ -457,7 +457,7 @@ ssh-dss AAAAB3NzaC1kc3MAAACBAOChCC7lf6Uo9n7BmZ6M8St19PZf4Tn59NriyboW2x/DZuYAz3ib if err != nil { continue } - assert.Equal(t, kase.number, len(keys)) + assert.Len(t, keys, kase.number) for _, key := range keys { assert.Contains(t, kase.keyContents, key.Content) |