From f1173d6879cb26af21483037fae72542f3088408 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Sat, 22 Apr 2023 23:56:27 +0200 Subject: [PATCH] Use more specific test methods (#24265) Co-authored-by: silverwind Co-authored-by: Giteabot --- cmd/migrate_storage_test.go | 2 +- models/db/list_test.go | 2 +- models/git/branches_test.go | 6 +-- models/issues/pull_test.go | 4 +- models/issues/tracked_time_test.go | 2 +- models/unittest/consistency.go | 2 +- models/user/user_test.go | 6 +-- modules/git/repo_attribute_test.go | 4 +- modules/git/repo_commit_test.go | 2 +- modules/git/repo_tag_test.go | 2 +- modules/indexer/code/indexer_test.go | 2 +- modules/lfs/http_client_test.go | 4 +- modules/log/file_test.go | 2 +- modules/markup/html_test.go | 2 +- modules/packages/container/metadata_test.go | 2 +- modules/paginator/paginator_test.go | 40 +++++++++---------- .../queue/unique_queue_disk_channel_test.go | 2 +- modules/secret/secret_test.go | 4 +- modules/storage/local_test.go | 2 +- modules/test/logchecker_test.go | 20 +++++----- modules/translation/i18n/i18n_test.go | 4 +- modules/util/slice_test.go | 20 +++++----- modules/util/truncate_test.go | 2 +- services/issue/assignee_test.go | 6 +-- services/issue/issue_test.go | 6 +-- services/repository/adopt_test.go | 6 +-- tests/integration/api_admin_test.go | 2 +- .../api_comment_attachment_test.go | 2 +- tests/integration/api_comment_test.go | 4 +- tests/integration/api_issue_config_test.go | 2 +- tests/integration/api_pull_review_test.go | 6 +-- tests/integration/api_pull_test.go | 6 +-- tests/integration/api_repo_archive_test.go | 6 +-- tests/integration/api_repo_edit_test.go | 14 +++---- tests/integration/api_repo_test.go | 4 +- tests/integration/auth_ldap_test.go | 8 ++-- tests/integration/cors_test.go | 2 +- tests/integration/empty_repo_test.go | 4 +- tests/integration/git_test.go | 8 ++-- tests/integration/pull_merge_test.go | 2 +- tests/integration/repo_test.go | 8 ++-- 41 files changed, 117 insertions(+), 117 deletions(-) diff --git a/cmd/migrate_storage_test.go b/cmd/migrate_storage_test.go index aae366c0c..e6658b6e6 100644 --- a/cmd/migrate_storage_test.go +++ b/cmd/migrate_storage_test.go @@ -67,7 +67,7 @@ func TestMigratePackages(t *testing.T) { entries, err := os.ReadDir(p) assert.NoError(t, err) - assert.EqualValues(t, 2, len(entries)) + assert.Len(t, entries, 2) assert.EqualValues(t, "01", entries[0].Name()) assert.EqualValues(t, "tmp", entries[1].Name()) } diff --git a/models/db/list_test.go b/models/db/list_test.go index 6b9bebd64..b923dc9c2 100644 --- a/models/db/list_test.go +++ b/models/db/list_test.go @@ -40,7 +40,7 @@ func TestFind(t *testing.T) { var repoUnits []repo_model.RepoUnit err = db.Find(db.DefaultContext, &opts, &repoUnits) assert.NoError(t, err) - assert.EqualValues(t, repoUnitCount, len(repoUnits)) + assert.Len(t, repoUnits, repoUnitCount) cnt, err := db.Count(db.DefaultContext, &opts, new(repo_model.RepoUnit)) assert.NoError(t, err) diff --git a/models/git/branches_test.go b/models/git/branches_test.go index b7df7f243..5d18d9525 100644 --- a/models/git/branches_test.go +++ b/models/git/branches_test.go @@ -88,12 +88,12 @@ func TestFindRenamedBranch(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) branch, exist, err := git_model.FindRenamedBranch(db.DefaultContext, 1, "dev") assert.NoError(t, err) - assert.Equal(t, true, exist) + assert.True(t, exist) assert.Equal(t, "master", branch.To) _, exist, err = git_model.FindRenamedBranch(db.DefaultContext, 1, "unknow") assert.NoError(t, err) - assert.Equal(t, false, exist) + assert.False(t, exist) } func TestRenameBranch(t *testing.T) { @@ -115,7 +115,7 @@ func TestRenameBranch(t *testing.T) { return nil })) - assert.Equal(t, true, _isDefault) + assert.True(t, _isDefault) repo1 = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) assert.Equal(t, "main", repo1.DefaultBranch) diff --git a/models/issues/pull_test.go b/models/issues/pull_test.go index bcd33329e..8d99b2667 100644 --- a/models/issues/pull_test.go +++ b/models/issues/pull_test.go @@ -109,11 +109,11 @@ func TestHasUnmergedPullRequestsByHeadInfo(t *testing.T) { exist, err := issues_model.HasUnmergedPullRequestsByHeadInfo(db.DefaultContext, 1, "branch2") assert.NoError(t, err) - assert.Equal(t, true, exist) + assert.True(t, exist) exist, err = issues_model.HasUnmergedPullRequestsByHeadInfo(db.DefaultContext, 1, "not_exist_branch") assert.NoError(t, err) - assert.Equal(t, false, exist) + assert.False(t, exist) } func TestGetUnmergedPullRequestsByHeadInfo(t *testing.T) { diff --git a/models/issues/tracked_time_test.go b/models/issues/tracked_time_test.go index becfd79d4..99b977cca 100644 --- a/models/issues/tracked_time_test.go +++ b/models/issues/tracked_time_test.go @@ -35,7 +35,7 @@ func TestAddTime(t *testing.T) { assert.Equal(t, int64(3661), tt.Time) comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{Type: issues_model.CommentTypeAddTimeManual, PosterID: 3, IssueID: 1}) - assert.Equal(t, comment.Content, "1 hour 1 minute") + assert.Equal(t, "1 hour 1 minute", comment.Content) } func TestGetTrackedTimes(t *testing.T) { diff --git a/models/unittest/consistency.go b/models/unittest/consistency.go index 17ff75c08..41798c625 100644 --- a/models/unittest/consistency.go +++ b/models/unittest/consistency.go @@ -152,7 +152,7 @@ func init() { Query() assert.NoError(t, err) - assert.EqualValues(t, label.int("NumIssues"), len(issueLabels), "Unexpected number of issue for label id: %d", label.int("ID")) + assert.Len(t, issueLabels, label.int("NumIssues"), "Unexpected number of issue for label id: %d", label.int("ID")) issueIDs := make([]int, len(issueLabels)) for i, issueLabel := range issueLabels { diff --git a/models/user/user_test.go b/models/user/user_test.go index c2314d5c0..cbfcd1546 100644 --- a/models/user/user_test.go +++ b/models/user/user_test.go @@ -36,10 +36,10 @@ func TestGetUserEmailsByNames(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) // ignore none active user email - assert.Equal(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user9"})) - assert.Equal(t, []string{"user8@example.com", "user5@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user5"})) + assert.ElementsMatch(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user9"})) + assert.ElementsMatch(t, []string{"user8@example.com", "user5@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user5"})) - assert.Equal(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user7"})) + assert.ElementsMatch(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user7"})) } func TestCanCreateOrganization(t *testing.T) { diff --git a/modules/git/repo_attribute_test.go b/modules/git/repo_attribute_test.go index f88ae9540..350b69dd2 100644 --- a/modules/git/repo_attribute_test.go +++ b/modules/git/repo_attribute_test.go @@ -19,7 +19,7 @@ func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) { n, err := wr.Write([]byte(testStr)) - assert.Equal(t, n, len(testStr)) + assert.Len(t, testStr, n) assert.NoError(t, err) select { case attr := <-wr.ReadAttribute(): @@ -32,7 +32,7 @@ func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) { // Write a second attribute again n, err = wr.Write([]byte(testStr)) - assert.Equal(t, n, len(testStr)) + assert.Len(t, testStr, n) assert.NoError(t, err) select { diff --git a/modules/git/repo_commit_test.go b/modules/git/repo_commit_test.go index 729fb0ba1..fee145e92 100644 --- a/modules/git/repo_commit_test.go +++ b/modules/git/repo_commit_test.go @@ -97,6 +97,6 @@ func TestRepository_CommitsBetweenIDs(t *testing.T) { for i, c := range cases { commits, err := bareRepo1.CommitsBetweenIDs(c.NewID, c.OldID) assert.NoError(t, err) - assert.Equal(t, c.ExpectedCommits, len(commits), "case %d", i) + assert.Len(t, commits, c.ExpectedCommits, "case %d", i) } } diff --git a/modules/git/repo_tag_test.go b/modules/git/repo_tag_test.go index 8ccfec3eb..fb6a7cdd1 100644 --- a/modules/git/repo_tag_test.go +++ b/modules/git/repo_tag_test.go @@ -26,7 +26,7 @@ func TestRepository_GetTags(t *testing.T) { return } assert.Len(t, tags, 2) - assert.Equal(t, len(tags), total) + assert.Len(t, tags, total) assert.EqualValues(t, "signed-tag", tags[0].Name) assert.EqualValues(t, "36f97d9a96457e2bab511db30fe2db03893ebc64", tags[0].ID.String()) assert.EqualValues(t, "tag", tags[0].Type) diff --git a/modules/indexer/code/indexer_test.go b/modules/indexer/code/indexer_test.go index c353d5b68..52f7e76e4 100644 --- a/modules/indexer/code/indexer_test.go +++ b/modules/indexer/code/indexer_test.go @@ -69,7 +69,7 @@ func testIndexer(name string, t *testing.T, indexer Indexer) { t.Run(kw.Keyword, func(t *testing.T) { total, res, langs, err := indexer.Search(context.TODO(), kw.RepoIDs, "", kw.Keyword, 1, 10, false) assert.NoError(t, err) - assert.EqualValues(t, len(kw.IDs), total) + assert.Len(t, kw.IDs, int(total)) assert.Len(t, langs, kw.Langs) ids := make([]int64, 0, len(res)) diff --git a/modules/lfs/http_client_test.go b/modules/lfs/http_client_test.go index a8c7e379f..cb71b9008 100644 --- a/modules/lfs/http_client_test.go +++ b/modules/lfs/http_client_test.go @@ -162,7 +162,7 @@ func TestHTTPClientDownload(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "download", batchRequest.Operation) - assert.Equal(t, 1, len(batchRequest.Objects)) + assert.Len(t, batchRequest.Objects, 1) assert.Equal(t, p.Oid, batchRequest.Objects[0].Oid) assert.Equal(t, p.Size, batchRequest.Objects[0].Size) @@ -269,7 +269,7 @@ func TestHTTPClientUpload(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "upload", batchRequest.Operation) - assert.Equal(t, 1, len(batchRequest.Objects)) + assert.Len(t, batchRequest.Objects, 1) assert.Equal(t, p.Oid, batchRequest.Objects[0].Oid) assert.Equal(t, p.Size, batchRequest.Objects[0].Size) diff --git a/modules/log/file_test.go b/modules/log/file_test.go index f1ca23d34..34f745980 100644 --- a/modules/log/file_test.go +++ b/modules/log/file_test.go @@ -51,7 +51,7 @@ func TestFileLogger(t *testing.T) { fileLogger := NewFileLogger() realFileLogger, ok := fileLogger.(*FileLogger) - assert.Equal(t, true, ok) + assert.True(t, ok) location, _ := time.LoadLocation("EST") diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go index f8b84485c..cb1216ec9 100644 --- a/modules/markup/html_test.go +++ b/modules/markup/html_test.go @@ -593,5 +593,5 @@ func TestIssue18471(t *testing.T) { }, strings.NewReader(data), &res) assert.NoError(t, err) - assert.Equal(t, res.String(), "783b039...da951ce") + assert.Equal(t, "783b039...da951ce", res.String()) } diff --git a/modules/packages/container/metadata_test.go b/modules/packages/container/metadata_test.go index 48809f4c9..195b3982c 100644 --- a/modules/packages/container/metadata_test.go +++ b/modules/packages/container/metadata_test.go @@ -33,7 +33,7 @@ func TestParseImageConfig(t *testing.T) { assert.Equal(t, projectURL, metadata.ProjectURL) assert.Equal(t, repositoryURL, metadata.RepositoryURL) assert.Equal(t, documentationURL, metadata.DocumentationURL) - assert.Equal(t, []string{"do it 1", "do it 2"}, metadata.ImageLayers) + assert.ElementsMatch(t, []string{"do it 1", "do it 2"}, metadata.ImageLayers) assert.Equal( t, map[string]string{ diff --git a/modules/paginator/paginator_test.go b/modules/paginator/paginator_test.go index 41bb30533..8a56ee512 100644 --- a/modules/paginator/paginator_test.go +++ b/modules/paginator/paginator_test.go @@ -70,19 +70,19 @@ func TestPaginator(t *testing.T) { t.Run("Generate pages", func(t *testing.T) { p := New(0, 10, 1, 0) pages := p.Pages() - assert.Equal(t, 0, len(pages)) + assert.Empty(t, pages) }) t.Run("Only current page", func(t *testing.T) { p := New(0, 10, 1, 1) pages := p.Pages() - assert.Equal(t, 1, len(pages)) + assert.Len(t, pages, 1) assert.Equal(t, 1, pages[0].Num()) assert.True(t, pages[0].IsCurrent()) p = New(1, 10, 1, 1) pages = p.Pages() - assert.Equal(t, 1, len(pages)) + assert.Len(t, pages, 1) assert.Equal(t, 1, pages[0].Num()) assert.True(t, pages[0].IsCurrent()) }) @@ -90,13 +90,13 @@ func TestPaginator(t *testing.T) { t.Run("Total page number is less or equal", func(t *testing.T) { p := New(1, 10, 1, 2) pages := p.Pages() - assert.Equal(t, 1, len(pages)) + assert.Len(t, pages, 1) assert.Equal(t, 1, pages[0].Num()) assert.True(t, pages[0].IsCurrent()) p = New(11, 10, 1, 2) pages = p.Pages() - assert.Equal(t, 2, len(pages)) + assert.Len(t, pages, 2) assert.Equal(t, 1, pages[0].Num()) assert.True(t, pages[0].IsCurrent()) assert.Equal(t, 2, pages[1].Num()) @@ -104,7 +104,7 @@ func TestPaginator(t *testing.T) { p = New(11, 10, 2, 2) pages = p.Pages() - assert.Equal(t, 2, len(pages)) + assert.Len(t, pages, 2) assert.Equal(t, 1, pages[0].Num()) assert.False(t, pages[0].IsCurrent()) assert.Equal(t, 2, pages[1].Num()) @@ -112,7 +112,7 @@ func TestPaginator(t *testing.T) { p = New(25, 10, 2, 3) pages = p.Pages() - assert.Equal(t, 3, len(pages)) + assert.Len(t, pages, 3) assert.Equal(t, 1, pages[0].Num()) assert.False(t, pages[0].IsCurrent()) assert.Equal(t, 2, pages[1].Num()) @@ -125,7 +125,7 @@ func TestPaginator(t *testing.T) { // ... 2 p := New(11, 10, 2, 1) pages := p.Pages() - assert.Equal(t, 2, len(pages)) + assert.Len(t, pages, 2) assert.Equal(t, -1, pages[0].Num()) assert.False(t, pages[0].IsCurrent()) assert.Equal(t, 2, pages[1].Num()) @@ -134,7 +134,7 @@ func TestPaginator(t *testing.T) { // ... 2 3 p = New(21, 10, 2, 2) pages = p.Pages() - assert.Equal(t, 3, len(pages)) + assert.Len(t, pages, 3) assert.Equal(t, -1, pages[0].Num()) assert.False(t, pages[0].IsCurrent()) assert.Equal(t, 2, pages[1].Num()) @@ -145,7 +145,7 @@ func TestPaginator(t *testing.T) { // ... 2 3 4 p = New(31, 10, 3, 3) pages = p.Pages() - assert.Equal(t, 4, len(pages)) + assert.Len(t, pages, 4) assert.Equal(t, -1, pages[0].Num()) assert.False(t, pages[0].IsCurrent()) assert.Equal(t, 2, pages[1].Num()) @@ -158,7 +158,7 @@ func TestPaginator(t *testing.T) { // ... 3 4 5 p = New(41, 10, 4, 3) pages = p.Pages() - assert.Equal(t, 4, len(pages)) + assert.Len(t, pages, 4) assert.Equal(t, -1, pages[0].Num()) assert.False(t, pages[0].IsCurrent()) assert.Equal(t, 3, pages[1].Num()) @@ -171,7 +171,7 @@ func TestPaginator(t *testing.T) { // ... 4 5 6 7 8 9 10 p = New(100, 10, 9, 7) pages = p.Pages() - assert.Equal(t, 8, len(pages)) + assert.Len(t, pages, 8) assert.Equal(t, -1, pages[0].Num()) assert.False(t, pages[0].IsCurrent()) assert.Equal(t, 4, pages[1].Num()) @@ -194,7 +194,7 @@ func TestPaginator(t *testing.T) { // 1 ... p := New(21, 10, 1, 1) pages := p.Pages() - assert.Equal(t, 2, len(pages)) + assert.Len(t, pages, 2) assert.Equal(t, 1, pages[0].Num()) assert.True(t, pages[0].IsCurrent()) assert.Equal(t, -1, pages[1].Num()) @@ -203,7 +203,7 @@ func TestPaginator(t *testing.T) { // 1 2 ... p = New(21, 10, 1, 2) pages = p.Pages() - assert.Equal(t, 3, len(pages)) + assert.Len(t, pages, 3) assert.Equal(t, 1, pages[0].Num()) assert.True(t, pages[0].IsCurrent()) assert.Equal(t, 2, pages[1].Num()) @@ -214,7 +214,7 @@ func TestPaginator(t *testing.T) { // 1 2 3 ... p = New(31, 10, 2, 3) pages = p.Pages() - assert.Equal(t, 4, len(pages)) + assert.Len(t, pages, 4) assert.Equal(t, 1, pages[0].Num()) assert.False(t, pages[0].IsCurrent()) assert.Equal(t, 2, pages[1].Num()) @@ -227,7 +227,7 @@ func TestPaginator(t *testing.T) { // 1 2 3 ... p = New(41, 10, 2, 3) pages = p.Pages() - assert.Equal(t, 4, len(pages)) + assert.Len(t, pages, 4) assert.Equal(t, 1, pages[0].Num()) assert.False(t, pages[0].IsCurrent()) assert.Equal(t, 2, pages[1].Num()) @@ -240,7 +240,7 @@ func TestPaginator(t *testing.T) { // 1 2 3 4 5 6 7 ... p = New(100, 10, 1, 7) pages = p.Pages() - assert.Equal(t, 8, len(pages)) + assert.Len(t, pages, 8) assert.Equal(t, 1, pages[0].Num()) assert.True(t, pages[0].IsCurrent()) assert.Equal(t, 2, pages[1].Num()) @@ -261,7 +261,7 @@ func TestPaginator(t *testing.T) { // 1 2 3 4 5 6 7 ... p = New(100, 10, 2, 7) pages = p.Pages() - assert.Equal(t, 8, len(pages)) + assert.Len(t, pages, 8) assert.Equal(t, 1, pages[0].Num()) assert.False(t, pages[0].IsCurrent()) assert.Equal(t, 2, pages[1].Num()) @@ -284,7 +284,7 @@ func TestPaginator(t *testing.T) { // ... 2 3 ... p := New(35, 10, 2, 2) pages := p.Pages() - assert.Equal(t, 4, len(pages)) + assert.Len(t, pages, 4) assert.Equal(t, -1, pages[0].Num()) assert.False(t, pages[0].IsCurrent()) assert.Equal(t, 2, pages[1].Num()) @@ -297,7 +297,7 @@ func TestPaginator(t *testing.T) { // ... 2 3 4 ... p = New(49, 10, 3, 3) pages = p.Pages() - assert.Equal(t, 5, len(pages)) + assert.Len(t, pages, 5) assert.Equal(t, -1, pages[0].Num()) assert.False(t, pages[0].IsCurrent()) assert.Equal(t, 2, pages[1].Num()) diff --git a/modules/queue/unique_queue_disk_channel_test.go b/modules/queue/unique_queue_disk_channel_test.go index fd76163f4..e1a2132dd 100644 --- a/modules/queue/unique_queue_disk_channel_test.go +++ b/modules/queue/unique_queue_disk_channel_test.go @@ -208,7 +208,7 @@ func TestPersistableChannelUniqueQueue(t *testing.T) { mapLock.Lock() assert.Equal(t, 101, len(executedInitial[name])+len(executedEmpty[name])) - assert.Equal(t, 0, len(hasEmpty[name])) + assert.Empty(t, hasEmpty[name]) mapLock.Unlock() }) close(done) diff --git a/modules/secret/secret_test.go b/modules/secret/secret_test.go index 0a189eceb..4b018fddb 100644 --- a/modules/secret/secret_test.go +++ b/modules/secret/secret_test.go @@ -15,9 +15,9 @@ func TestEncryptDecrypt(t *testing.T) { hex, _ = EncryptSecret("foo", "baz") str, _ = DecryptSecret("foo", hex) - assert.Equal(t, str, "baz") + assert.Equal(t, "baz", str) hex, _ = EncryptSecret("bar", "baz") str, _ = DecryptSecret("foo", hex) - assert.NotEqual(t, str, "baz") + assert.NotEqual(t, "baz", str) } diff --git a/modules/storage/local_test.go b/modules/storage/local_test.go index 9649761a0..0873f8e14 100644 --- a/modules/storage/local_test.go +++ b/modules/storage/local_test.go @@ -89,6 +89,6 @@ func TestLocalStorageIterator(t *testing.T) { return nil }) assert.NoError(t, err) - assert.Equal(t, count, len(expected)) + assert.Len(t, expected, count) } } diff --git a/modules/test/logchecker_test.go b/modules/test/logchecker_test.go index 1ed7f427f..4dfea8c3e 100644 --- a/modules/test/logchecker_test.go +++ b/modules/test/logchecker_test.go @@ -22,26 +22,26 @@ func TestLogChecker(t *testing.T) { log.Info("test") filtered, stopped := lc.Check(100 * time.Millisecond) - assert.EqualValues(t, []bool{false, false}, filtered) - assert.EqualValues(t, false, stopped) + assert.ElementsMatch(t, []bool{false, false}, filtered) + assert.False(t, stopped) log.Info("First") filtered, stopped = lc.Check(100 * time.Millisecond) - assert.EqualValues(t, []bool{true, false}, filtered) - assert.EqualValues(t, false, stopped) + assert.ElementsMatch(t, []bool{true, false}, filtered) + assert.False(t, stopped) log.Info("Second") filtered, stopped = lc.Check(100 * time.Millisecond) - assert.EqualValues(t, []bool{true, false}, filtered) - assert.EqualValues(t, false, stopped) + assert.ElementsMatch(t, []bool{true, false}, filtered) + assert.False(t, stopped) log.Info("Third") filtered, stopped = lc.Check(100 * time.Millisecond) - assert.EqualValues(t, []bool{true, true}, filtered) - assert.EqualValues(t, false, stopped) + assert.ElementsMatch(t, []bool{true, true}, filtered) + assert.False(t, stopped) log.Info("End") filtered, stopped = lc.Check(100 * time.Millisecond) - assert.EqualValues(t, []bool{true, true}, filtered) - assert.EqualValues(t, true, stopped) + assert.ElementsMatch(t, []bool{true, true}, filtered) + assert.True(t, stopped) } diff --git a/modules/translation/i18n/i18n_test.go b/modules/translation/i18n/i18n_test.go index 085d03811..1d1be4331 100644 --- a/modules/translation/i18n/i18n_test.go +++ b/modules/translation/i18n/i18n_test.go @@ -51,8 +51,8 @@ sub = Changed Sub String assert.Equal(t, `test value; more text`, result) langs, descs := ls.ListLangNameDesc() - assert.Equal(t, []string{"lang1", "lang2"}, langs) - assert.Equal(t, []string{"Lang1", "Lang2"}, descs) + assert.ElementsMatch(t, []string{"lang1", "lang2"}, langs) + assert.ElementsMatch(t, []string{"Lang1", "Lang2"}, descs) found := ls.Has("lang1", "no-such") assert.False(t, found) diff --git a/modules/util/slice_test.go b/modules/util/slice_test.go index b0b771a79..373c1a3b7 100644 --- a/modules/util/slice_test.go +++ b/modules/util/slice_test.go @@ -74,15 +74,15 @@ func TestSliceEqual(t *testing.T) { } func TestSliceRemoveAll(t *testing.T) { - assert.Equal(t, SliceRemoveAll([]int{2, 0, 2, 3}, 0), []int{2, 2, 3}) - assert.Equal(t, SliceRemoveAll([]int{2, 0, 2, 3}, 2), []int{0, 3}) - assert.Equal(t, SliceRemoveAll([]int{0, 0, 0, 0}, 0), []int{}) - assert.Equal(t, SliceRemoveAll([]int{2, 0, 2, 3}, 4), []int{2, 0, 2, 3}) - assert.Equal(t, SliceRemoveAll([]int{}, 0), []int{}) - assert.Equal(t, SliceRemoveAll([]int(nil), 0), []int(nil)) - assert.Equal(t, SliceRemoveAll([]int{}, 0), []int{}) + assert.ElementsMatch(t, []int{2, 2, 3}, SliceRemoveAll([]int{2, 0, 2, 3}, 0)) + assert.ElementsMatch(t, []int{0, 3}, SliceRemoveAll([]int{2, 0, 2, 3}, 2)) + assert.Empty(t, SliceRemoveAll([]int{0, 0, 0, 0}, 0)) + assert.ElementsMatch(t, []int{2, 0, 2, 3}, SliceRemoveAll([]int{2, 0, 2, 3}, 4)) + assert.Empty(t, SliceRemoveAll([]int{}, 0)) + assert.ElementsMatch(t, []int(nil), SliceRemoveAll([]int(nil), 0)) + assert.Empty(t, SliceRemoveAll([]int{}, 0)) - assert.Equal(t, SliceRemoveAll([]string{"2", "0", "2", "3"}, "0"), []string{"2", "2", "3"}) - assert.Equal(t, SliceRemoveAll([]float64{2, 0, 2, 3}, 0), []float64{2, 2, 3}) - assert.Equal(t, SliceRemoveAll([]bool{false, true, false}, true), []bool{false, false}) + assert.ElementsMatch(t, []string{"2", "2", "3"}, SliceRemoveAll([]string{"2", "0", "2", "3"}, "0")) + assert.ElementsMatch(t, []float64{2, 2, 3}, SliceRemoveAll([]float64{2, 0, 2, 3}, 0)) + assert.ElementsMatch(t, []bool{false, false}, SliceRemoveAll([]bool{false, true, false}, true)) } diff --git a/modules/util/truncate_test.go b/modules/util/truncate_test.go index 05e2bc030..dfe1230fd 100644 --- a/modules/util/truncate_test.go +++ b/modules/util/truncate_test.go @@ -25,7 +25,7 @@ func TestSplitString(t *testing.T) { assert.Equal(t, c.ellipsis+c.input[len(c.leftSub):], r, "test split %s at %d, expected rightSub: %q", c.input, c.n, c.input[len(c.leftSub):]) } else { assert.Equal(t, c.leftSub, l, "test split %q at %d, expected leftSub: %q", c.input, c.n, c.leftSub) - assert.Equal(t, "", r, "test split %q at %d, expected rightSub: %q", c.input, c.n, "") + assert.Empty(t, r, "test split %q at %d, expected rightSub: %q", c.input, c.n, "") } } } diff --git a/services/issue/assignee_test.go b/services/issue/assignee_test.go index 43b24e1d1..f47ef45ba 100644 --- a/services/issue/assignee_test.go +++ b/services/issue/assignee_test.go @@ -20,7 +20,7 @@ func TestDeleteNotPassedAssignee(t *testing.T) { // Fake issue with assignees issue, err := issues_model.GetIssueWithAttrsByID(1) assert.NoError(t, err) - assert.EqualValues(t, 1, len(issue.Assignees)) + assert.Len(t, issue.Assignees, 1) user1, err := user_model.GetUserByID(db.DefaultContext, 1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him assert.NoError(t, err) @@ -33,10 +33,10 @@ func TestDeleteNotPassedAssignee(t *testing.T) { // Clean everyone err = DeleteNotPassedAssignee(db.DefaultContext, issue, user1, []*user_model.User{}) assert.NoError(t, err) - assert.EqualValues(t, 0, len(issue.Assignees)) + assert.Empty(t, issue.Assignees) // Check they're gone assert.NoError(t, issue.LoadAssignees(db.DefaultContext)) - assert.EqualValues(t, 0, len(issue.Assignees)) + assert.Empty(t, issue.Assignees) assert.Empty(t, issue.Assignee) } diff --git a/services/issue/issue_test.go b/services/issue/issue_test.go index da0e97c23..1f6a77096 100644 --- a/services/issue/issue_test.go +++ b/services/issue/issue_test.go @@ -37,7 +37,7 @@ func TestIssue_DeleteIssue(t *testing.T) { issueIDs, err := issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1) assert.NoError(t, err) - assert.EqualValues(t, 5, len(issueIDs)) + assert.Len(t, issueIDs, 5) issue := &issues_model.Issue{ RepoID: 1, @@ -48,7 +48,7 @@ func TestIssue_DeleteIssue(t *testing.T) { assert.NoError(t, err) issueIDs, err = issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1) assert.NoError(t, err) - assert.EqualValues(t, 4, len(issueIDs)) + assert.Len(t, issueIDs, 4) // check attachment removal attachments, err := repo_model.GetAttachmentsByIssueID(db.DefaultContext, 4) @@ -57,7 +57,7 @@ func TestIssue_DeleteIssue(t *testing.T) { assert.NoError(t, err) err = deleteIssue(db.DefaultContext, issue) assert.NoError(t, err) - assert.EqualValues(t, 2, len(attachments)) + assert.Len(t, attachments, 2) for i := range attachments { attachment, err := repo_model.GetAttachmentByUUID(db.DefaultContext, attachments[i].UUID) assert.Error(t, err) diff --git a/services/repository/adopt_test.go b/services/repository/adopt_test.go index 3f777c425..c1520e01c 100644 --- a/services/repository/adopt_test.go +++ b/services/repository/adopt_test.go @@ -30,7 +30,7 @@ func TestCheckUnadoptedRepositories_Add(t *testing.T) { } assert.Equal(t, total, unadopted.index) - assert.Equal(t, end-start, len(unadopted.repositories)) + assert.Len(t, unadopted.repositories, end-start) } func TestCheckUnadoptedRepositories(t *testing.T) { @@ -41,7 +41,7 @@ func TestCheckUnadoptedRepositories(t *testing.T) { unadopted := &unadoptedRepositories{start: 0, end: 100} err := checkUnadoptedRepositories(db.DefaultContext, "notauser", []string{"repo"}, unadopted) assert.NoError(t, err) - assert.Equal(t, 0, len(unadopted.repositories)) + assert.Empty(t, unadopted.repositories) // // Unadopted repository is returned // Existing (adopted) repository is not returned @@ -59,7 +59,7 @@ func TestCheckUnadoptedRepositories(t *testing.T) { unadopted = &unadoptedRepositories{start: 0, end: 100} err = checkUnadoptedRepositories(db.DefaultContext, userName, []string{repoName}, unadopted) assert.NoError(t, err) - assert.Equal(t, 0, len(unadopted.repositories)) + assert.Empty(t, unadopted.repositories) assert.Equal(t, 0, unadopted.index) } diff --git a/tests/integration/api_admin_test.go b/tests/integration/api_admin_test.go index b608c26f6..53e4849aa 100644 --- a/tests/integration/api_admin_test.go +++ b/tests/integration/api_admin_test.go @@ -123,7 +123,7 @@ func TestAPIListUsers(t *testing.T) { } assert.True(t, found) numberOfUsers := unittest.GetCount(t, &user_model.User{}, "type = 0") - assert.Equal(t, numberOfUsers, len(users)) + assert.Len(t, users, numberOfUsers) } func TestAPIListUsersNotLoggedIn(t *testing.T) { diff --git a/tests/integration/api_comment_attachment_test.go b/tests/integration/api_comment_attachment_test.go index 1f916ffa1..1d0b902b3 100644 --- a/tests/integration/api_comment_attachment_test.go +++ b/tests/integration/api_comment_attachment_test.go @@ -68,7 +68,7 @@ func TestAPIListCommentAttachments(t *testing.T) { var apiAttachments []*api.Attachment DecodeJSON(t, resp, &apiAttachments) expectedCount := unittest.GetCount(t, &repo_model.Attachment{CommentID: comment.ID}) - assert.EqualValues(t, expectedCount, len(apiAttachments)) + assert.Len(t, apiAttachments, expectedCount) unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: apiAttachments[0].ID, CommentID: comment.ID}) } diff --git a/tests/integration/api_comment_test.go b/tests/integration/api_comment_test.go index 70affc989..56de8b590 100644 --- a/tests/integration/api_comment_test.go +++ b/tests/integration/api_comment_test.go @@ -85,7 +85,7 @@ func TestAPIListIssueComments(t *testing.T) { DecodeJSON(t, resp, &comments) expectedCount := unittest.GetCount(t, &issues_model.Comment{IssueID: issue.ID}, unittest.Cond("type = ?", issues_model.CommentTypeComment)) - assert.EqualValues(t, expectedCount, len(comments)) + assert.Len(t, comments, expectedCount) } func TestAPICreateComment(t *testing.T) { @@ -196,5 +196,5 @@ func TestAPIListIssueTimeline(t *testing.T) { var comments []*api.TimelineComment DecodeJSON(t, resp, &comments) expectedCount := unittest.GetCount(t, &issues_model.Comment{IssueID: issue.ID}) - assert.EqualValues(t, expectedCount, len(comments)) + assert.Len(t, comments, expectedCount) } diff --git a/tests/integration/api_issue_config_test.go b/tests/integration/api_issue_config_test.go index b9b3765c4..f3dc663f3 100644 --- a/tests/integration/api_issue_config_test.go +++ b/tests/integration/api_issue_config_test.go @@ -48,5 +48,5 @@ func TestAPIReposValidateDefaultIssueConfig(t *testing.T) { DecodeJSON(t, resp, &issueConfigValidation) assert.True(t, issueConfigValidation.Valid) - assert.Equal(t, issueConfigValidation.Message, "") + assert.Empty(t, issueConfigValidation.Message) } diff --git a/tests/integration/api_pull_review_test.go b/tests/integration/api_pull_review_test.go index cfb56724a..e0abf34f5 100644 --- a/tests/integration/api_pull_review_test.go +++ b/tests/integration/api_pull_review_test.go @@ -170,8 +170,8 @@ func TestAPIPullReview(t *testing.T) { DecodeJSON(t, resp, &commentReview) assert.EqualValues(t, "COMMENT", commentReview.State) assert.EqualValues(t, 2, commentReview.CodeCommentsCount) - assert.EqualValues(t, "", commentReview.Body) - assert.EqualValues(t, false, commentReview.Dismissed) + assert.Empty(t, commentReview.Body) + assert.False(t, commentReview.Dismissed) // test CreatePullReview Comment with body but without comments commentBody := "This is a body of the comment." @@ -186,7 +186,7 @@ func TestAPIPullReview(t *testing.T) { assert.EqualValues(t, "COMMENT", commentReview.State) assert.EqualValues(t, 0, commentReview.CodeCommentsCount) assert.EqualValues(t, commentBody, commentReview.Body) - assert.EqualValues(t, false, commentReview.Dismissed) + assert.False(t, commentReview.Dismissed) // test CreatePullReview Comment without body and no comments req = NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/reviews?token=%s", repo.OwnerName, repo.Name, pullIssue.Index, token), &api.CreatePullReviewOptions{ diff --git a/tests/integration/api_pull_test.go b/tests/integration/api_pull_test.go index 4b25f97dd..cf675f974 100644 --- a/tests/integration/api_pull_test.go +++ b/tests/integration/api_pull_test.go @@ -49,12 +49,12 @@ func TestAPIViewPulls(t *testing.T) { t.Run(fmt.Sprintf("APIGetPullFiles_%d", pull.ID), doAPIGetPullFiles(ctx, pull, func(t *testing.T, files []*api.ChangedFile) { if assert.Len(t, files, 1) { - assert.EqualValues(t, "File-WoW", files[0].Filename) - assert.EqualValues(t, "", files[0].PreviousFilename) + assert.Equal(t, "File-WoW", files[0].Filename) + assert.Empty(t, files[0].PreviousFilename) assert.EqualValues(t, 1, files[0].Additions) assert.EqualValues(t, 1, files[0].Changes) assert.EqualValues(t, 0, files[0].Deletions) - assert.EqualValues(t, "added", files[0].Status) + assert.Equal(t, "added", files[0].Status) } })) } diff --git a/tests/integration/api_repo_archive_test.go b/tests/integration/api_repo_archive_test.go index fbcc12ccb..699d7a436 100644 --- a/tests/integration/api_repo_archive_test.go +++ b/tests/integration/api_repo_archive_test.go @@ -32,21 +32,21 @@ func TestAPIDownloadArchive(t *testing.T) { resp := MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) bs, err := io.ReadAll(resp.Body) assert.NoError(t, err) - assert.EqualValues(t, 320, len(bs)) + assert.Len(t, bs, 320) link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.tar.gz", user2.Name, repo.Name)) link.RawQuery = url.Values{"token": {token}}.Encode() resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) bs, err = io.ReadAll(resp.Body) assert.NoError(t, err) - assert.EqualValues(t, 266, len(bs)) + assert.Len(t, bs, 266) link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master.bundle", user2.Name, repo.Name)) link.RawQuery = url.Values{"token": {token}}.Encode() resp = MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) bs, err = io.ReadAll(resp.Body) assert.NoError(t, err) - assert.EqualValues(t, 382, len(bs)) + assert.Len(t, bs, 382) link, _ = url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/archive/master", user2.Name, repo.Name)) link.RawQuery = url.Values{"token": {token}}.Encode() diff --git a/tests/integration/api_repo_edit_test.go b/tests/integration/api_repo_edit_test.go index 9594b86d7..30dc73ef1 100644 --- a/tests/integration/api_repo_edit_test.go +++ b/tests/integration/api_repo_edit_test.go @@ -194,10 +194,10 @@ func TestAPIRepoEdit(t *testing.T) { // check repo1 was written to database repo1edited = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) repo1editedOption = getRepoEditOptionFromRepo(repo1edited) - assert.Equal(t, *repo1editedOption.HasIssues, true) + assert.True(t, *repo1editedOption.HasIssues) assert.Nil(t, repo1editedOption.ExternalTracker) assert.Equal(t, *repo1editedOption.InternalTracker, *repoEditOption.InternalTracker) - assert.Equal(t, *repo1editedOption.HasWiki, true) + assert.True(t, *repo1editedOption.HasWiki) assert.Nil(t, repo1editedOption.ExternalWiki) // Test editing repo1 to use external issue and wiki @@ -216,9 +216,9 @@ func TestAPIRepoEdit(t *testing.T) { // check repo1 was written to database repo1edited = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) repo1editedOption = getRepoEditOptionFromRepo(repo1edited) - assert.Equal(t, *repo1editedOption.HasIssues, true) + assert.True(t, *repo1editedOption.HasIssues) assert.Equal(t, *repo1editedOption.ExternalTracker, *repoEditOption.ExternalTracker) - assert.Equal(t, *repo1editedOption.HasWiki, true) + assert.True(t, *repo1editedOption.HasWiki) assert.Equal(t, *repo1editedOption.ExternalWiki, *repoEditOption.ExternalWiki) repoEditOption.ExternalTracker.ExternalTrackerStyle = "regexp" @@ -229,7 +229,7 @@ func TestAPIRepoEdit(t *testing.T) { assert.NotNil(t, repo) repo1edited = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) repo1editedOption = getRepoEditOptionFromRepo(repo1edited) - assert.Equal(t, *repo1editedOption.HasIssues, true) + assert.True(t, *repo1editedOption.HasIssues) assert.Equal(t, *repo1editedOption.ExternalTracker, *repoEditOption.ExternalTracker) // Do some tests with invalid URL for external tracker and wiki @@ -259,9 +259,9 @@ func TestAPIRepoEdit(t *testing.T) { repo1edited = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) repo1editedOption = getRepoEditOptionFromRepo(repo1edited) assert.Equal(t, *repo1editedOption.Description, *repoEditOption.Description) - assert.Equal(t, *repo1editedOption.HasIssues, true) + assert.True(t, *repo1editedOption.HasIssues) assert.NotNil(t, *repo1editedOption.ExternalTracker) - assert.Equal(t, *repo1editedOption.HasWiki, true) + assert.True(t, *repo1editedOption.HasWiki) assert.NotNil(t, *repo1editedOption.ExternalWiki) // reset repo in db diff --git a/tests/integration/api_repo_test.go b/tests/integration/api_repo_test.go index ecaa9fe98..aa4e67420 100644 --- a/tests/integration/api_repo_test.go +++ b/tests/integration/api_repo_test.go @@ -412,7 +412,7 @@ func TestAPIMirrorSyncNonMirrorRepo(t *testing.T) { req := NewRequest(t, "GET", "/api/v1/repos/user2/repo1") resp := MakeRequest(t, req, http.StatusOK) DecodeJSON(t, resp, &repo) - assert.EqualValues(t, false, repo.Mirror) + assert.False(t, repo.Mirror) req = NewRequestf(t, "POST", "/api/v1/repos/user2/repo1/mirror-sync?token=%s", token) resp = MakeRequest(t, req, http.StatusBadRequest) @@ -469,7 +469,7 @@ func testAPIRepoCreateConflict(t *testing.T, u *url.URL) { resp := httpContext.Session.MakeRequest(t, req, http.StatusConflict) respJSON := map[string]string{} DecodeJSON(t, resp, &respJSON) - assert.Equal(t, respJSON["message"], "The repository with the same name already exists.") + assert.Equal(t, "The repository with the same name already exists.", respJSON["message"]) }) } diff --git a/tests/integration/auth_ldap_test.go b/tests/integration/auth_ldap_test.go index 883c9d80a..81f8d9ddd 100644 --- a/tests/integration/auth_ldap_test.go +++ b/tests/integration/auth_ldap_test.go @@ -203,7 +203,7 @@ func TestLDAPAuthChange(t *testing.T) { host, _ := doc.Find(`input[name="host"]`).Attr("value") assert.Equal(t, host, getLDAPServerHost()) binddn, _ := doc.Find(`input[name="bind_dn"]`).Attr("value") - assert.Equal(t, binddn, "uid=gitea,ou=service,dc=planetexpress,dc=com") + assert.Equal(t, "uid=gitea,ou=service,dc=planetexpress,dc=com", binddn) req = NewRequestWithValues(t, "POST", href, buildAuthSourceLDAPPayload(csrf, "", "", "", "off")) session.MakeRequest(t, req, http.StatusSeeOther) @@ -214,7 +214,7 @@ func TestLDAPAuthChange(t *testing.T) { host, _ = doc.Find(`input[name="host"]`).Attr("value") assert.Equal(t, host, getLDAPServerHost()) binddn, _ = doc.Find(`input[name="bind_dn"]`).Attr("value") - assert.Equal(t, binddn, "uid=gitea,ou=service,dc=planetexpress,dc=com") + assert.Equal(t, "uid=gitea,ou=service,dc=planetexpress,dc=com", binddn) } func TestLDAPUserSync(t *testing.T) { @@ -397,8 +397,8 @@ func TestLDAPGroupTeamSyncAddMember(t *testing.T) { assert.NoError(t, err) if user.Name == "fry" || user.Name == "leela" || user.Name == "bender" { // assert members of LDAP group "cn=ship_crew" are added to mapped teams - assert.Equal(t, len(usersOrgs), 1, "User [%s] should be member of one organization", user.Name) - assert.Equal(t, usersOrgs[0].Name, "org26", "Membership should be added to the right organization") + assert.Len(t, usersOrgs, 1, "User [%s] should be member of one organization", user.Name) + assert.Equal(t, "org26", usersOrgs[0].Name, "Membership should be added to the right organization") isMember, err := organization.IsTeamMember(db.DefaultContext, usersOrgs[0].ID, team.ID, user.ID) assert.NoError(t, err) assert.True(t, isMember, "Membership should be added to the right team") diff --git a/tests/integration/cors_test.go b/tests/integration/cors_test.go index cc2d85b41..e4151d1c3 100644 --- a/tests/integration/cors_test.go +++ b/tests/integration/cors_test.go @@ -19,5 +19,5 @@ func TestCORSNotSet(t *testing.T) { resp := session.MakeRequest(t, req, http.StatusOK) assert.Equal(t, resp.Code, http.StatusOK) corsHeader := resp.Header().Get("Access-Control-Allow-Origin") - assert.Equal(t, corsHeader, "", "Access-Control-Allow-Origin: generated header should match") // header not set + assert.Empty(t, corsHeader, "Access-Control-Allow-Origin: generated header should match") // header not set } diff --git a/tests/integration/empty_repo_test.go b/tests/integration/empty_repo_test.go index 80697c732..e6e5f7b18 100644 --- a/tests/integration/empty_repo_test.go +++ b/tests/integration/empty_repo_test.go @@ -49,7 +49,7 @@ func TestEmptyRepoAddFile(t *testing.T) { req := NewRequest(t, "GET", "/user30/empty/_new/"+setting.Repository.DefaultBranch) resp := session.MakeRequest(t, req, http.StatusOK) doc := NewHTMLParser(t, resp.Body).Find(`input[name="commit_choice"]`) - assert.Equal(t, "", doc.AttrOr("checked", "_no_")) + assert.Empty(t, doc.AttrOr("checked", "_no_")) req = NewRequestWithValues(t, "POST", "/user30/empty/_new/"+setting.Repository.DefaultBranch, map[string]string{ "_csrf": GetCSRF(t, session, "/user/settings"), "commit_choice": "direct", @@ -76,7 +76,7 @@ func TestEmptyRepoUploadFile(t *testing.T) { req := NewRequest(t, "GET", "/user30/empty/_new/"+setting.Repository.DefaultBranch) resp := session.MakeRequest(t, req, http.StatusOK) doc := NewHTMLParser(t, resp.Body).Find(`input[name="commit_choice"]`) - assert.Equal(t, "", doc.AttrOr("checked", "_no_")) + assert.Empty(t, doc.AttrOr("checked", "_no_")) body := &bytes.Buffer{} mpForm := multipart.NewWriter(body) diff --git a/tests/integration/git_test.go b/tests/integration/git_test.go index 95323b91c..8d5c0fc39 100644 --- a/tests/integration/git_test.go +++ b/tests/integration/git_test.go @@ -763,7 +763,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB return } assert.Equal(t, "user2/"+headBranch, pr1.HeadBranch) - assert.Equal(t, false, prMsg.HasMerged) + assert.False(t, prMsg.HasMerged) assert.Contains(t, "Testing commit 1", prMsg.Body) assert.Equal(t, commit, prMsg.Head.Sha) @@ -785,7 +785,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB return } assert.Equal(t, "user2/test/"+headBranch, pr2.HeadBranch) - assert.Equal(t, false, prMsg.HasMerged) + assert.False(t, prMsg.HasMerged) }) if pr1 == nil || pr2 == nil { @@ -829,7 +829,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB if !assert.NoError(t, err) { return } - assert.Equal(t, false, prMsg.HasMerged) + assert.False(t, prMsg.HasMerged) assert.Equal(t, commit, prMsg.Head.Sha) _, _, err = git.NewCommand(git.DefaultContext, "push", "origin").AddDynamicArguments("HEAD:refs/for/master/test/" + headBranch).RunStdString(&git.RunOpts{Dir: dstPath}) @@ -841,7 +841,7 @@ func doCreateAgitFlowPull(dstPath string, ctx *APITestContext, baseBranch, headB if !assert.NoError(t, err) { return } - assert.Equal(t, false, prMsg.HasMerged) + assert.False(t, prMsg.HasMerged) assert.Equal(t, commit, prMsg.Head.Sha) }) t.Run("Merge", doAPIMergePullRequest(*ctx, ctx.Username, ctx.Reponame, pr1.Index)) diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go index ee185f223..9271f25e5 100644 --- a/tests/integration/pull_merge_test.go +++ b/tests/integration/pull_merge_test.go @@ -414,7 +414,7 @@ func TestConflictChecking(t *testing.T) { assert.NoError(t, err) // Ensure conflictedFiles is populated. - assert.Equal(t, 1, len(conflictingPR.ConflictedFiles)) + assert.Len(t, conflictingPR.ConflictedFiles, 1) // Check if status is correct. assert.Equal(t, issues_model.PullRequestStatusConflict, conflictingPR.Status) // Ensure that mergeable returns false diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index f03a3b37f..f2bc04864 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -376,7 +376,7 @@ func TestMarkDownReadmeImage(t *testing.T) { htmlDoc := NewHTMLParser(t, resp.Body) src, exists := htmlDoc.doc.Find(`.markdown img`).Attr("src") assert.True(t, exists, "Image not found in README") - assert.Equal(t, src, "/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg") + assert.Equal(t, "/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg", src) req = NewRequest(t, "GET", "/user2/repo1/src/branch/home-md-img-check/README.md") resp = session.MakeRequest(t, req, http.StatusOK) @@ -384,7 +384,7 @@ func TestMarkDownReadmeImage(t *testing.T) { htmlDoc = NewHTMLParser(t, resp.Body) src, exists = htmlDoc.doc.Find(`.markdown img`).Attr("src") assert.True(t, exists, "Image not found in markdown file") - assert.Equal(t, src, "/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg") + assert.Equal(t, "/user2/repo1/media/branch/home-md-img-check/test-fake-img.jpg", src) } func TestMarkDownReadmeImageSubfolder(t *testing.T) { @@ -399,7 +399,7 @@ func TestMarkDownReadmeImageSubfolder(t *testing.T) { htmlDoc := NewHTMLParser(t, resp.Body) src, exists := htmlDoc.doc.Find(`.markdown img`).Attr("src") assert.True(t, exists, "Image not found in README") - assert.Equal(t, src, "/user2/repo1/media/branch/sub-home-md-img-check/docs/test-fake-img.jpg") + assert.Equal(t, "/user2/repo1/media/branch/sub-home-md-img-check/docs/test-fake-img.jpg", src) req = NewRequest(t, "GET", "/user2/repo1/src/branch/sub-home-md-img-check/docs/README.md") resp = session.MakeRequest(t, req, http.StatusOK) @@ -407,5 +407,5 @@ func TestMarkDownReadmeImageSubfolder(t *testing.T) { htmlDoc = NewHTMLParser(t, resp.Body) src, exists = htmlDoc.doc.Find(`.markdown img`).Attr("src") assert.True(t, exists, "Image not found in markdown file") - assert.Equal(t, src, "/user2/repo1/media/branch/sub-home-md-img-check/docs/test-fake-img.jpg") + assert.Equal(t, "/user2/repo1/media/branch/sub-home-md-img-check/docs/test-fake-img.jpg", src) }