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 /modules | |
parent | 51775f65bc933843199320b040186703a2bb9f51 (diff) | |
download | gitea-3607f79d7869046d919fed05a21b55b6e61df1fa.tar.gz gitea-3607f79d7869046d919fed05a21b55b6e61df1fa.zip |
Fixed assert statements. (#16089)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/auth/pam/pam_test.go | 2 | ||||
-rw-r--r-- | modules/base/tool_test.go | 8 | ||||
-rw-r--r-- | modules/git/parse_nogogit_test.go | 2 | ||||
-rw-r--r-- | modules/git/repo_commit_test.go | 4 | ||||
-rw-r--r-- | modules/git/tree_entry_test.go | 12 | ||||
-rw-r--r-- | modules/indexer/code/indexer_test.go | 2 | ||||
-rw-r--r-- | modules/lfs/http_client_test.go | 2 | ||||
-rw-r--r-- | modules/lfs/pointer_test.go | 22 | ||||
-rw-r--r-- | modules/log/console_test.go | 14 | ||||
-rw-r--r-- | modules/log/file_test.go | 4 | ||||
-rw-r--r-- | modules/log/log_test.go | 50 | ||||
-rw-r--r-- | modules/log/smtp_test.go | 2 | ||||
-rw-r--r-- | modules/log/writer_test.go | 39 | ||||
-rw-r--r-- | modules/markup/markdown/meta_test.go | 4 | ||||
-rw-r--r-- | modules/migrations/gitea_downloader_test.go | 4 | ||||
-rw-r--r-- | modules/migrations/gitea_uploader_test.go | 18 | ||||
-rw-r--r-- | modules/migrations/github_test.go | 6 | ||||
-rw-r--r-- | modules/migrations/gitlab_test.go | 4 | ||||
-rw-r--r-- | modules/migrations/gogs_test.go | 4 | ||||
-rw-r--r-- | modules/password/password_test.go | 2 | ||||
-rw-r--r-- | modules/queue/queue_channel_test.go | 2 | ||||
-rw-r--r-- | modules/repository/commits_test.go | 2 | ||||
-rw-r--r-- | modules/repository/create_test.go | 2 |
23 files changed, 105 insertions, 106 deletions
diff --git a/modules/auth/pam/pam_test.go b/modules/auth/pam/pam_test.go index eafc9bc3db..fa16ff0fe7 100644 --- a/modules/auth/pam/pam_test.go +++ b/modules/auth/pam/pam_test.go @@ -15,6 +15,6 @@ import ( func TestPamAuth(t *testing.T) { result, err := Auth("gitea", "user1", "false-pwd") assert.Error(t, err) - assert.EqualValues(t, "Authentication failure", err.Error()) + assert.EqualError(t, err, "Authentication failure") assert.Len(t, result, 0) } diff --git a/modules/base/tool_test.go b/modules/base/tool_test.go index 1343f5bed3..5280827e8a 100644 --- a/modules/base/tool_test.go +++ b/modules/base/tool_test.go @@ -223,9 +223,9 @@ func TestInt64sToMap(t *testing.T) { func TestInt64sContains(t *testing.T) { assert.Equal(t, map[int64]bool{}, Int64sToMap([]int64{})) - assert.Equal(t, true, Int64sContains([]int64{6, 44324, 4324, 32, 1, 2323}, 1)) - assert.Equal(t, true, Int64sContains([]int64{2323}, 2323)) - assert.Equal(t, false, Int64sContains([]int64{6, 44324, 4324, 32, 1, 2323}, 232)) + assert.True(t, Int64sContains([]int64{6, 44324, 4324, 32, 1, 2323}, 1)) + assert.True(t, Int64sContains([]int64{2323}, 2323)) + assert.False(t, Int64sContains([]int64{6, 44324, 4324, 32, 1, 2323}, 232)) } func TestIsLetter(t *testing.T) { @@ -249,7 +249,7 @@ func TestIsLetter(t *testing.T) { func TestSetupGiteaRoot(t *testing.T) { _ = os.Setenv("GITEA_ROOT", "test") - assert.EqualValues(t, "test", SetupGiteaRoot()) + assert.Equal(t, "test", SetupGiteaRoot()) _ = os.Setenv("GITEA_ROOT", "") assert.NotEqual(t, "test", SetupGiteaRoot()) } diff --git a/modules/git/parse_nogogit_test.go b/modules/git/parse_nogogit_test.go index a9e7dcc7f8..502c38d4e8 100644 --- a/modules/git/parse_nogogit_test.go +++ b/modules/git/parse_nogogit_test.go @@ -58,7 +58,7 @@ func TestParseTreeEntries(t *testing.T) { for _, testCase := range testCases { entries, err := ParseTreeEntries([]byte(testCase.Input)) assert.NoError(t, err) - assert.EqualValues(t, len(testCase.Expected), len(entries)) + assert.Len(t, entries, len(testCase.Expected)) for i, entry := range entries { assert.EqualValues(t, testCase.Expected[i].ID, entry.ID) assert.EqualValues(t, testCase.Expected[i].name, entry.name) diff --git a/modules/git/repo_commit_test.go b/modules/git/repo_commit_test.go index 3eedaa6b6e..8f8acbdfed 100644 --- a/modules/git/repo_commit_test.go +++ b/modules/git/repo_commit_test.go @@ -72,9 +72,9 @@ func TestIsCommitInBranch(t *testing.T) { result, err := bareRepo1.IsCommitInBranch("2839944139e0de9737a044f78b0e4b40d989a9e3", "branch1") assert.NoError(t, err) - assert.Equal(t, true, result) + assert.True(t, result) result, err = bareRepo1.IsCommitInBranch("2839944139e0de9737a044f78b0e4b40d989a9e3", "branch2") assert.NoError(t, err) - assert.Equal(t, false, result) + assert.False(t, result) } diff --git a/modules/git/tree_entry_test.go b/modules/git/tree_entry_test.go index 16cfbc4fc3..3382de4102 100644 --- a/modules/git/tree_entry_test.go +++ b/modules/git/tree_entry_test.go @@ -71,33 +71,33 @@ func TestFollowLink(t *testing.T) { // should be able to dereference to target target, err := lnk.FollowLink() assert.NoError(t, err) - assert.Equal(t, target.Name(), "hello") + assert.Equal(t, "hello", target.Name()) assert.False(t, target.IsLink()) - assert.Equal(t, target.ID.String(), "b14df6442ea5a1b382985a6549b85d435376c351") + assert.Equal(t, "b14df6442ea5a1b382985a6549b85d435376c351", target.ID.String()) // should error when called on normal file target, err = commit.Tree.GetTreeEntryByPath("file1.txt") assert.NoError(t, err) _, err = target.FollowLink() - assert.Equal(t, err.Error(), "file1.txt: not a symlink") + assert.EqualError(t, err, "file1.txt: not a symlink") // should error for broken links target, err = commit.Tree.GetTreeEntryByPath("foo/broken_link") assert.NoError(t, err) assert.True(t, target.IsLink()) _, err = target.FollowLink() - assert.Equal(t, err.Error(), "broken_link: broken link") + assert.EqualError(t, err, "broken_link: broken link") // should error for external links target, err = commit.Tree.GetTreeEntryByPath("foo/outside_repo") assert.NoError(t, err) assert.True(t, target.IsLink()) _, err = target.FollowLink() - assert.Equal(t, err.Error(), "outside_repo: points outside of repo") + assert.EqualError(t, err, "outside_repo: points outside of repo") // testing fix for short link bug target, err = commit.Tree.GetTreeEntryByPath("foo/link_short") assert.NoError(t, err) _, err = target.FollowLink() - assert.Equal(t, err.Error(), "link_short: broken link") + assert.EqualError(t, err, "link_short: broken link") } diff --git a/modules/indexer/code/indexer_test.go b/modules/indexer/code/indexer_test.go index 8fcb7a0e8a..01717bd288 100644 --- a/modules/indexer/code/indexer_test.go +++ b/modules/indexer/code/indexer_test.go @@ -67,7 +67,7 @@ func testIndexer(name string, t *testing.T, indexer Indexer) { total, res, langs, err := indexer.Search(kw.RepoIDs, "", kw.Keyword, 1, 10, false) assert.NoError(t, err) assert.EqualValues(t, len(kw.IDs), total) - assert.EqualValues(t, kw.Langs, len(langs)) + assert.Len(t, langs, kw.Langs) var ids = make([]int64, 0, len(res)) for _, hit := range res { diff --git a/modules/lfs/http_client_test.go b/modules/lfs/http_client_test.go index 043aa0214e..68ec947aa8 100644 --- a/modules/lfs/http_client_test.go +++ b/modules/lfs/http_client_test.go @@ -56,7 +56,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, oid, batchRequest.Objects[0].Oid) assert.Equal(t, size, batchRequest.Objects[0].Size) diff --git a/modules/lfs/pointer_test.go b/modules/lfs/pointer_test.go index 0ed6df2c6d..9cd8b15c9e 100644 --- a/modules/lfs/pointer_test.go +++ b/modules/lfs/pointer_test.go @@ -15,16 +15,16 @@ import ( func TestStringContent(t *testing.T) { p := Pointer{Oid: "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393", Size: 1234} expected := "version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 1234\n" - assert.Equal(t, p.StringContent(), expected) + assert.Equal(t, expected, p.StringContent()) } func TestRelativePath(t *testing.T) { p := Pointer{Oid: "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393"} expected := path.Join("4d", "7a", "214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393") - assert.Equal(t, p.RelativePath(), expected) + assert.Equal(t, expected, p.RelativePath()) p2 := Pointer{Oid: "4d7a"} - assert.Equal(t, p2.RelativePath(), "4d7a") + assert.Equal(t, "4d7a", p2.RelativePath()) } func TestIsValid(t *testing.T) { @@ -48,8 +48,8 @@ func TestGeneratePointer(t *testing.T) { p, err := GeneratePointer(strings.NewReader("Gitea")) assert.NoError(t, err) assert.True(t, p.IsValid()) - assert.Equal(t, p.Oid, "94cb57646c54a297c9807697e80a30946f79a4b82cb079d2606847825b1812cc") - assert.Equal(t, p.Size, int64(5)) + assert.Equal(t, "94cb57646c54a297c9807697e80a30946f79a4b82cb079d2606847825b1812cc", p.Oid) + assert.Equal(t, int64(5), p.Size) } func TestReadPointerFromBuffer(t *testing.T) { @@ -84,20 +84,20 @@ func TestReadPointerFromBuffer(t *testing.T) { p, err = ReadPointerFromBuffer([]byte("version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 1234\n")) assert.NoError(t, err) assert.True(t, p.IsValid()) - assert.Equal(t, p.Oid, "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393") - assert.Equal(t, p.Size, int64(1234)) + assert.Equal(t, "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393", p.Oid) + assert.Equal(t, int64(1234), p.Size) p, err = ReadPointerFromBuffer([]byte("version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 1234\ntest")) assert.NoError(t, err) assert.True(t, p.IsValid()) - assert.Equal(t, p.Oid, "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393") - assert.Equal(t, p.Size, int64(1234)) + assert.Equal(t, "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393", p.Oid) + assert.Equal(t, int64(1234), p.Size) } func TestReadPointer(t *testing.T) { p, err := ReadPointer(strings.NewReader("version https://git-lfs.github.com/spec/v1\noid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393\nsize 1234\n")) assert.NoError(t, err) assert.True(t, p.IsValid()) - assert.Equal(t, p.Oid, "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393") - assert.Equal(t, p.Size, int64(1234)) + assert.Equal(t, "4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393", p.Oid) + assert.Equal(t, int64(1234), p.Size) } diff --git a/modules/log/console_test.go b/modules/log/console_test.go index e7ed07123b..4da87b48a3 100644 --- a/modules/log/console_test.go +++ b/modules/log/console_test.go @@ -48,7 +48,7 @@ func TestConsoleLoggerMinimalConfig(t *testing.T) { assert.Equal(t, prefix, realCW.Prefix) assert.Equal(t, "", string(written)) cw.Close() - assert.Equal(t, false, closed) + assert.False(t, closed) } } @@ -97,20 +97,20 @@ func TestConsoleLogger(t *testing.T) { expected := fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg) cw.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = DEBUG expected = "" cw.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) event.level = TRACE expected = "" cw.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) nonMatchEvent := Event{ level: INFO, @@ -124,15 +124,15 @@ func TestConsoleLogger(t *testing.T) { expected = "" cw.LogEvent(&nonMatchEvent) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) event.level = WARN expected = fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg) cw.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] cw.Close() - assert.Equal(t, false, closed) + assert.False(t, closed) } diff --git a/modules/log/file_test.go b/modules/log/file_test.go index af6fbcb29d..7bc5f90037 100644 --- a/modules/log/file_test.go +++ b/modules/log/file_test.go @@ -30,7 +30,7 @@ func TestFileLoggerFails(t *testing.T) { fileLogger := NewFileLogger() //realFileLogger, ok := fileLogger.(*FileLogger) - //assert.Equal(t, true, ok) + //assert.True(t, ok) // Fail if there is bad json err = fileLogger.Init("{") @@ -161,7 +161,7 @@ func TestCompressFileLogger(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/log/log_test.go b/modules/log/log_test.go index 810505dea5..d14daa5a20 100644 --- a/modules/log/log_test.go +++ b/modules/log/log_test.go @@ -26,9 +26,9 @@ func baseConsoleTest(t *testing.T, logger *MultiChannelledLogger) (chan []byte, channelledLog := m.GetEventLogger("console") assert.NotEmpty(t, channelledLog) realChanLog, ok := channelledLog.(*ChannelledLog) - assert.Equal(t, true, ok) + assert.True(t, ok) realCL, ok := realChanLog.loggerProvider.(*ConsoleLogger) - assert.Equal(t, true, ok) + assert.True(t, ok) assert.Equal(t, INFO, realCL.Level) realCL.out = c @@ -38,20 +38,20 @@ func baseConsoleTest(t *testing.T, logger *MultiChannelledLogger) (chan []byte, logger.Log(0, INFO, format, args...) line := <-written assert.Contains(t, string(line), fmt.Sprintf(format, args...)) - assert.Equal(t, false, <-closed) + assert.False(t, <-closed) format = "test2: %s" logger.Warn(format, args...) line = <-written assert.Contains(t, string(line), fmt.Sprintf(format, args...)) - assert.Equal(t, false, <-closed) + assert.False(t, <-closed) format = "testerror: %s" logger.Error(format, args...) line = <-written assert.Contains(t, string(line), fmt.Sprintf(format, args...)) - assert.Equal(t, false, <-closed) + assert.False(t, <-closed) return written, closed } @@ -63,7 +63,7 @@ func TestNewLoggerUnexported(t *testing.T) { out := logger.MultiChannelledLog.GetEventLogger("console") assert.NotEmpty(t, out) chanlog, ok := out.(*ChannelledLog) - assert.Equal(t, true, ok) + assert.True(t, ok) assert.Equal(t, "console", chanlog.provider) assert.Equal(t, INFO, logger.GetLevel()) baseConsoleTest(t, logger) @@ -74,11 +74,11 @@ func TestNewLoggger(t *testing.T) { logger := NewLogger(0, "console", "console", fmt.Sprintf(`{"level":"%s"}`, level.String())) assert.Equal(t, INFO, GetLevel()) - assert.Equal(t, false, IsTrace()) - assert.Equal(t, false, IsDebug()) - assert.Equal(t, true, IsInfo()) - assert.Equal(t, true, IsWarn()) - assert.Equal(t, true, IsError()) + assert.False(t, IsTrace()) + assert.False(t, IsDebug()) + assert.True(t, IsInfo()) + assert.True(t, IsWarn()) + assert.True(t, IsError()) written, closed := baseConsoleTest(t, logger) @@ -88,17 +88,17 @@ func TestNewLoggger(t *testing.T) { Log(0, INFO, format, args...) line := <-written assert.Contains(t, string(line), fmt.Sprintf(format, args...)) - assert.Equal(t, false, <-closed) + assert.False(t, <-closed) Info(format, args...) line = <-written assert.Contains(t, string(line), fmt.Sprintf(format, args...)) - assert.Equal(t, false, <-closed) + assert.False(t, <-closed) go DelLogger("console") line = <-written assert.Equal(t, "", string(line)) - assert.Equal(t, true, <-closed) + assert.True(t, <-closed) } func TestNewLogggerRecreate(t *testing.T) { @@ -106,11 +106,11 @@ func TestNewLogggerRecreate(t *testing.T) { NewLogger(0, "console", "console", fmt.Sprintf(`{"level":"%s"}`, level.String())) assert.Equal(t, INFO, GetLevel()) - assert.Equal(t, false, IsTrace()) - assert.Equal(t, false, IsDebug()) - assert.Equal(t, true, IsInfo()) - assert.Equal(t, true, IsWarn()) - assert.Equal(t, true, IsError()) + assert.False(t, IsTrace()) + assert.False(t, IsDebug()) + assert.True(t, IsInfo()) + assert.True(t, IsWarn()) + assert.True(t, IsError()) format := "test: %s" args := []interface{}{"A"} @@ -120,11 +120,11 @@ func TestNewLogggerRecreate(t *testing.T) { NewLogger(0, "console", "console", fmt.Sprintf(`{"level":"%s"}`, level.String())) assert.Equal(t, INFO, GetLevel()) - assert.Equal(t, false, IsTrace()) - assert.Equal(t, false, IsDebug()) - assert.Equal(t, true, IsInfo()) - assert.Equal(t, true, IsWarn()) - assert.Equal(t, true, IsError()) + assert.False(t, IsTrace()) + assert.False(t, IsDebug()) + assert.True(t, IsInfo()) + assert.True(t, IsWarn()) + assert.True(t, IsError()) Log(0, INFO, format, args...) @@ -150,5 +150,5 @@ func TestNewNamedLogger(t *testing.T) { go DelNamedLogger("test") line := <-written assert.Equal(t, "", string(line)) - assert.Equal(t, true, <-closed) + assert.True(t, <-closed) } diff --git a/modules/log/smtp_test.go b/modules/log/smtp_test.go index 216d555215..c8758bf6be 100644 --- a/modules/log/smtp_test.go +++ b/modules/log/smtp_test.go @@ -26,7 +26,7 @@ func TestSMTPLogger(t *testing.T) { logger := NewSMTPLogger() smtpLogger, ok := logger.(*SMTPLogger) - assert.Equal(t, true, ok) + assert.True(t, ok) err := logger.Init(fmt.Sprintf("{\"prefix\":\"%s\",\"level\":\"%s\",\"flags\":%d,\"username\":\"%s\",\"password\":\"%s\",\"host\":\"%s\",\"subject\":\"%s\",\"sendTos\":[\"%s\",\"%s\"]}", prefix, level.String(), flags, username, password, host, subject, sendTos[0], sendTos[1])) assert.NoError(t, err) diff --git a/modules/log/writer_test.go b/modules/log/writer_test.go index 886dd58fb3..99a5fd3406 100644 --- a/modules/log/writer_test.go +++ b/modules/log/writer_test.go @@ -64,44 +64,44 @@ func TestBaseLogger(t *testing.T) { expected := fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg) b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = DEBUG expected = "" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) event.level = TRACE expected = "" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) event.level = WARN expected = fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg) b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = ERROR expected = fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg) b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = CRITICAL expected = fmt.Sprintf("%s%s %s:%d:%s [%c] %s\n", prefix, dateString, event.filename, event.line, event.caller, strings.ToUpper(event.level.String())[0], event.msg) b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] b.Close() - assert.Equal(t, true, closed) + assert.True(t, closed) } func TestBaseLoggerDated(t *testing.T) { @@ -142,46 +142,46 @@ func TestBaseLoggerDated(t *testing.T) { expected := fmt.Sprintf("%s%s %s:%d [%s] %s", prefix, dateString, "FILENAME", event.line, strings.ToUpper(event.level.String()), event.msg) b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = INFO expected = "" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = ERROR expected = fmt.Sprintf("%s%s %s:%d [%s] %s", prefix, dateString, "FILENAME", event.line, strings.ToUpper(event.level.String()), event.msg) b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = DEBUG expected = "" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = CRITICAL expected = fmt.Sprintf("%s%s %s:%d [%s] %s", prefix, dateString, "FILENAME", event.line, strings.ToUpper(event.level.String()), event.msg) b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.level = TRACE expected = "" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] b.Close() - assert.Equal(t, true, closed) + assert.True(t, closed) } func TestBaseLoggerMultiLineNoFlagsRegexp(t *testing.T) { @@ -222,20 +222,20 @@ func TestBaseLoggerMultiLineNoFlagsRegexp(t *testing.T) { expected := "TEST\n\tMESSAGE\n\tTEST\n" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.filename = "ELSEWHERE" b.LogEvent(&event) assert.Equal(t, "", string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event.caller = "FILENAME" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] event = Event{ @@ -249,9 +249,8 @@ func TestBaseLoggerMultiLineNoFlagsRegexp(t *testing.T) { expected = "TEST\n\tFILENAME\n\tTEST\n" b.LogEvent(&event) assert.Equal(t, expected, string(written)) - assert.Equal(t, false, closed) + assert.False(t, closed) written = written[:0] - } func TestBrokenRegexp(t *testing.T) { @@ -273,5 +272,5 @@ func TestBrokenRegexp(t *testing.T) { b.NewWriterLogger(c) assert.Empty(t, b.regexp) b.Close() - assert.Equal(t, true, closed) + assert.True(t, closed) } diff --git a/modules/markup/markdown/meta_test.go b/modules/markup/markdown/meta_test.go index a585f0382f..f525777a54 100644 --- a/modules/markup/markdown/meta_test.go +++ b/modules/markup/markdown/meta_test.go @@ -18,7 +18,7 @@ func TestExtractMetadata(t *testing.T) { var meta structs.IssueTemplate body, err := ExtractMetadata(fmt.Sprintf("%s\n%s\n%s\n%s", sepTest, frontTest, sepTest, bodyTest), &meta) assert.NoError(t, err) - assert.Equal(t, body, bodyTest) + assert.Equal(t, bodyTest, body) assert.Equal(t, metaTest, meta) assert.True(t, meta.Valid()) }) @@ -39,7 +39,7 @@ func TestExtractMetadata(t *testing.T) { var meta structs.IssueTemplate body, err := ExtractMetadata(fmt.Sprintf("%s\n%s\n%s", sepTest, frontTest, sepTest), &meta) assert.NoError(t, err) - assert.Equal(t, body, "") + assert.Equal(t, "", body) assert.Equal(t, metaTest, meta) assert.True(t, meta.Valid()) }) diff --git a/modules/migrations/gitea_downloader_test.go b/modules/migrations/gitea_downloader_test.go index c52c1225f4..babf038280 100644 --- a/modules/migrations/gitea_downloader_test.go +++ b/modules/migrations/gitea_downloader_test.go @@ -158,13 +158,13 @@ func TestGiteaDownloadRepo(t *testing.T) { issues, isEnd, err := downloader.GetIssues(1, 50) assert.NoError(t, err) - assert.EqualValues(t, 7, len(issues)) + assert.Len(t, issues, 7) assert.True(t, isEnd) assert.EqualValues(t, "open", issues[0].State) issues, isEnd, err = downloader.GetIssues(3, 2) assert.NoError(t, err) - assert.EqualValues(t, 2, len(issues)) + assert.Len(t, issues, 2) assert.False(t, isEnd) var ( diff --git a/modules/migrations/gitea_uploader_test.go b/modules/migrations/gitea_uploader_test.go index 3c7def4675..cf975020a3 100644 --- a/modules/migrations/gitea_uploader_test.go +++ b/modules/migrations/gitea_uploader_test.go @@ -59,18 +59,18 @@ func TestGiteaUploadRepo(t *testing.T) { State: structs.StateOpen, }) assert.NoError(t, err) - assert.EqualValues(t, 1, len(milestones)) + assert.Len(t, milestones, 1) milestones, err = models.GetMilestones(models.GetMilestonesOption{ RepoID: repo.ID, State: structs.StateClosed, }) assert.NoError(t, err) - assert.EqualValues(t, 0, len(milestones)) + assert.Empty(t, milestones) labels, err := models.GetLabelsByRepoID(repo.ID, "", models.ListOptions{}) assert.NoError(t, err) - assert.EqualValues(t, 11, len(labels)) + assert.Len(t, labels, 11) releases, err := models.GetReleasesByRepoID(repo.ID, models.FindReleasesOptions{ ListOptions: models.ListOptions{ @@ -80,7 +80,7 @@ func TestGiteaUploadRepo(t *testing.T) { IncludeTags: true, }) assert.NoError(t, err) - assert.EqualValues(t, 8, len(releases)) + assert.Len(t, releases, 8) releases, err = models.GetReleasesByRepoID(repo.ID, models.FindReleasesOptions{ ListOptions: models.ListOptions{ @@ -90,7 +90,7 @@ func TestGiteaUploadRepo(t *testing.T) { IncludeTags: false, }) assert.NoError(t, err) - assert.EqualValues(t, 1, len(releases)) + assert.Len(t, releases, 1) issues, err := models.Issues(&models.IssuesOptions{ RepoIDs: []int64{repo.ID}, @@ -98,16 +98,16 @@ func TestGiteaUploadRepo(t *testing.T) { SortType: "oldest", }) assert.NoError(t, err) - assert.EqualValues(t, 14, len(issues)) + assert.Len(t, issues, 14) assert.NoError(t, issues[0].LoadDiscussComments()) - assert.EqualValues(t, 0, len(issues[0].Comments)) + assert.Empty(t, issues[0].Comments) pulls, _, err := models.PullRequests(repo.ID, &models.PullRequestsOptions{ SortType: "oldest", }) assert.NoError(t, err) - assert.EqualValues(t, 34, len(pulls)) + assert.Len(t, pulls, 34) assert.NoError(t, pulls[0].LoadIssue()) assert.NoError(t, pulls[0].Issue.LoadDiscussComments()) - assert.EqualValues(t, 2, len(pulls[0].Issue.Comments)) + assert.Len(t, pulls[0].Issue.Comments, 2) } diff --git a/modules/migrations/github_test.go b/modules/migrations/github_test.go index efa8b6ba9b..5bd980a9d8 100644 --- a/modules/migrations/github_test.go +++ b/modules/migrations/github_test.go @@ -147,7 +147,7 @@ func TestGitHubDownloadRepo(t *testing.T) { // downloader.GetIssues() issues, isEnd, err := downloader.GetIssues(1, 2) assert.NoError(t, err) - assert.EqualValues(t, 2, len(issues)) + assert.Len(t, issues, 2) assert.False(t, isEnd) var ( @@ -242,7 +242,7 @@ func TestGitHubDownloadRepo(t *testing.T) { // downloader.GetComments() comments, err := downloader.GetComments(2) assert.NoError(t, err) - assert.EqualValues(t, 2, len(comments)) + assert.Len(t, comments, 2) assert.EqualValues(t, []*base.Comment{ { IssueIndex: 2, @@ -273,7 +273,7 @@ func TestGitHubDownloadRepo(t *testing.T) { // downloader.GetPullRequests() prs, _, err := downloader.GetPullRequests(1, 2) assert.NoError(t, err) - assert.EqualValues(t, 2, len(prs)) + assert.Len(t, prs, 2) closed1 = time.Date(2019, 11, 12, 21, 39, 27, 0, time.UTC) var merged1 = time.Date(2019, 11, 12, 21, 39, 27, 0, time.UTC) diff --git a/modules/migrations/gitlab_test.go b/modules/migrations/gitlab_test.go index f64d72147c..32ed6d807a 100644 --- a/modules/migrations/gitlab_test.go +++ b/modules/migrations/gitlab_test.go @@ -115,7 +115,7 @@ func TestGitlabDownloadRepo(t *testing.T) { issues, isEnd, err := downloader.GetIssues(1, 2) assert.NoError(t, err) - assert.EqualValues(t, 2, len(issues)) + assert.Len(t, issues, 2) assert.False(t, isEnd) var ( @@ -206,7 +206,7 @@ func TestGitlabDownloadRepo(t *testing.T) { comments, err := downloader.GetComments(2) assert.NoError(t, err) - assert.EqualValues(t, 4, len(comments)) + assert.Len(t, comments, 4) assert.EqualValues(t, []*base.Comment{ { IssueIndex: 2, diff --git a/modules/migrations/gogs_test.go b/modules/migrations/gogs_test.go index c240ae6432..d173952b06 100644 --- a/modules/migrations/gogs_test.go +++ b/modules/migrations/gogs_test.go @@ -80,7 +80,7 @@ func TestGogsDownloadRepo(t *testing.T) { // downloader.GetIssues() issues, isEnd, err := downloader.GetIssues(1, 8) assert.NoError(t, err) - assert.EqualValues(t, 1, len(issues)) + assert.Len(t, issues, 1) assert.False(t, isEnd) assert.EqualValues(t, []*base.Issue{ @@ -105,7 +105,7 @@ func TestGogsDownloadRepo(t *testing.T) { // downloader.GetComments() comments, err := downloader.GetComments(1) assert.NoError(t, err) - assert.EqualValues(t, 1, len(comments)) + assert.Len(t, comments, 1) assert.EqualValues(t, []*base.Comment{ { PosterName: "lunny", diff --git a/modules/password/password_test.go b/modules/password/password_test.go index 4325086b50..63f98aa9c3 100644 --- a/modules/password/password_test.go +++ b/modules/password/password_test.go @@ -54,7 +54,7 @@ func TestComplexity_Generate(t *testing.T) { for i := 0; i < maxCount; i++ { pwd, err := Generate(pwdLen) assert.NoError(t, err) - assert.Equal(t, pwdLen, len(pwd)) + assert.Len(t, pwd, pwdLen) assert.True(t, IsComplexEnough(pwd), "Failed complexities with modes %+v for generated: %s", modes, pwd) } } diff --git a/modules/queue/queue_channel_test.go b/modules/queue/queue_channel_test.go index e7abe5b50b..f1ddd7ec92 100644 --- a/modules/queue/queue_channel_test.go +++ b/modules/queue/queue_channel_test.go @@ -36,7 +36,7 @@ func TestChannelQueue(t *testing.T) { }, &testData{}) assert.NoError(t, err) - assert.Equal(t, queue.(*ChannelQueue).WorkerPool.boostWorkers, 5) + assert.Equal(t, 5, queue.(*ChannelQueue).WorkerPool.boostWorkers) go queue.Run(nilFn, nilFn) diff --git a/modules/repository/commits_test.go b/modules/repository/commits_test.go index ba69a7f97c..a5b28ce933 100644 --- a/modules/repository/commits_test.go +++ b/modules/repository/commits_test.go @@ -51,7 +51,7 @@ func TestPushCommits_ToAPIPayloadCommits(t *testing.T) { repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 16}).(*models.Repository) payloadCommits, err := pushCommits.ToAPIPayloadCommits(repo.RepoPath(), "/user2/repo16") assert.NoError(t, err) - assert.EqualValues(t, 3, len(payloadCommits)) + assert.Len(t, payloadCommits, 3) assert.Equal(t, "69554a6", payloadCommits[0].ID) assert.Equal(t, "not signed commit", payloadCommits[0].Message) diff --git a/modules/repository/create_test.go b/modules/repository/create_test.go index d3e8bf5af1..65ed7806a9 100644 --- a/modules/repository/create_test.go +++ b/modules/repository/create_test.go @@ -21,7 +21,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) { team := models.AssertExistsAndLoadBean(t, &models.Team{ID: teamID}).(*models.Team) assert.NoError(t, team.GetRepositories(&models.SearchTeamOptions{}), "%s: GetRepositories", team.Name) assert.Len(t, team.Repos, team.NumRepos, "%s: len repo", team.Name) - assert.Equal(t, len(repoIds), len(team.Repos), "%s: repo count", team.Name) + assert.Len(t, team.Repos, len(repoIds), "%s: repo count", team.Name) for i, rid := range repoIds { if rid > 0 { assert.True(t, team.HasRepository(rid), "%s: HasRepository(%d) %d", rid, i) |