aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorTheFox0x7 <thefox0x7@gmail.com>2024-12-15 11:41:29 +0100
committerGitHub <noreply@github.com>2024-12-15 10:41:29 +0000
commit33e8e82c4b528db8efb1cf9fc4dbab2d9e21ace8 (patch)
tree6ee296e2ef469911d0db440100e1eb835945af89 /modules
parentdf9a78cd04e364264c103cf3a92d94179cc1dd4f (diff)
downloadgitea-33e8e82c4b528db8efb1cf9fc4dbab2d9e21ace8.tar.gz
gitea-33e8e82c4b528db8efb1cf9fc4dbab2d9e21ace8.zip
Enable tenv and testifylint rules (#32852)
Enables tenv and testifylint linters closes: https://github.com/go-gitea/gitea/issues/32842
Diffstat (limited to 'modules')
-rw-r--r--modules/activitypub/client_test.go5
-rw-r--r--modules/assetfs/layered_test.go2
-rw-r--r--modules/auth/pam/pam_test.go2
-rw-r--r--modules/auth/password/hash/dummy_test.go2
-rw-r--r--modules/base/tool_test.go7
-rw-r--r--modules/dump/dumper_test.go2
-rw-r--r--modules/git/commit_sha256_test.go2
-rw-r--r--modules/git/commit_test.go6
-rw-r--r--modules/git/grep_test.go4
-rw-r--r--modules/git/parse_nogogit_test.go2
-rw-r--r--modules/git/repo_branch_test.go4
-rw-r--r--modules/git/repo_compare_test.go4
-rw-r--r--modules/indexer/issues/internal/tests/tests.go38
-rw-r--r--modules/lfs/transferadapter_test.go6
-rw-r--r--modules/log/logger_test.go4
-rw-r--r--modules/markup/html_internal_test.go4
-rw-r--r--modules/packages/conan/conanfile_parser_test.go2
-rw-r--r--modules/packages/conan/conaninfo_parser_test.go2
-rw-r--r--modules/queue/base_test.go6
-rw-r--r--modules/queue/workerqueue_test.go4
-rw-r--r--modules/references/references_test.go2
-rw-r--r--modules/repository/repo_test.go6
-rw-r--r--modules/setting/cron_test.go2
-rw-r--r--modules/setting/oauth2_test.go2
-rw-r--r--modules/setting/storage_test.go10
-rw-r--r--modules/user/user_test.go3
-rw-r--r--modules/util/color_test.go6
-rw-r--r--modules/util/keypair_test.go5
-rw-r--r--modules/util/time_str_test.go4
-rw-r--r--modules/util/util_test.go16
30 files changed, 80 insertions, 84 deletions
diff --git a/modules/activitypub/client_test.go b/modules/activitypub/client_test.go
index 65ea8d4d5b..d0c4845445 100644
--- a/modules/activitypub/client_test.go
+++ b/modules/activitypub/client_test.go
@@ -8,7 +8,6 @@ import (
"io"
"net/http"
"net/http/httptest"
- "regexp"
"testing"
"code.gitea.io/gitea/models/db"
@@ -28,9 +27,9 @@ func TestActivityPubSignedPost(t *testing.T) {
expected := "BODY"
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- assert.Regexp(t, regexp.MustCompile("^"+setting.Federation.DigestAlgorithm), r.Header.Get("Digest"))
+ assert.Regexp(t, "^"+setting.Federation.DigestAlgorithm, r.Header.Get("Digest"))
assert.Contains(t, r.Header.Get("Signature"), pubID)
- assert.Equal(t, r.Header.Get("Content-Type"), ActivityStreamsContentType)
+ assert.Equal(t, ActivityStreamsContentType, r.Header.Get("Content-Type"))
body, err := io.ReadAll(r.Body)
assert.NoError(t, err)
assert.Equal(t, expected, string(body))
diff --git a/modules/assetfs/layered_test.go b/modules/assetfs/layered_test.go
index b82111e745..03a3ae0d7c 100644
--- a/modules/assetfs/layered_test.go
+++ b/modules/assetfs/layered_test.go
@@ -58,7 +58,7 @@ func TestLayered(t *testing.T) {
assertRead := func(expected string, expectedErr error, elems ...string) {
bs, err := assets.ReadFile(elems...)
if err != nil {
- assert.ErrorAs(t, err, &expectedErr)
+ assert.ErrorIs(t, err, expectedErr)
} else {
assert.NoError(t, err)
assert.Equal(t, expected, string(bs))
diff --git a/modules/auth/pam/pam_test.go b/modules/auth/pam/pam_test.go
index c277d59c41..7265b5d0c1 100644
--- a/modules/auth/pam/pam_test.go
+++ b/modules/auth/pam/pam_test.go
@@ -15,5 +15,5 @@ func TestPamAuth(t *testing.T) {
result, err := Auth("gitea", "user1", "false-pwd")
assert.Error(t, err)
assert.EqualError(t, err, "Authentication failure")
- assert.Len(t, result, 0)
+ assert.Len(t, result)
}
diff --git a/modules/auth/password/hash/dummy_test.go b/modules/auth/password/hash/dummy_test.go
index f3b36df625..e56e3f1a7f 100644
--- a/modules/auth/password/hash/dummy_test.go
+++ b/modules/auth/password/hash/dummy_test.go
@@ -18,7 +18,7 @@ func TestDummyHasher(t *testing.T) {
password, salt := "password", "ZogKvWdyEx"
hash, err := dummy.Hash(password, salt)
- assert.Nil(t, err)
+ assert.NoError(t, err)
assert.Equal(t, hash, salt+":"+password)
assert.True(t, dummy.VerifyPassword(password, hash, salt))
diff --git a/modules/base/tool_test.go b/modules/base/tool_test.go
index 86cccdf209..f63679048e 100644
--- a/modules/base/tool_test.go
+++ b/modules/base/tool_test.go
@@ -6,7 +6,6 @@ package base
import (
"crypto/sha1"
"fmt"
- "os"
"testing"
"time"
@@ -157,7 +156,7 @@ func TestStringsToInt64s(t *testing.T) {
testSuccess([]string{"1", "4", "16", "64", "256"}, []int64{1, 4, 16, 64, 256})
ints, err := StringsToInt64s([]string{"-1", "a"})
- assert.Len(t, ints, 0)
+ assert.Empty(t, ints)
assert.Error(t, err)
}
@@ -172,9 +171,9 @@ func TestInt64sToStrings(t *testing.T) {
// TODO: Test EntryIcon
func TestSetupGiteaRoot(t *testing.T) {
- _ = os.Setenv("GITEA_ROOT", "test")
+ t.Setenv("GITEA_ROOT", "test")
assert.Equal(t, "test", SetupGiteaRoot())
- _ = os.Setenv("GITEA_ROOT", "")
+ t.Setenv("GITEA_ROOT", "")
assert.NotEqual(t, "test", SetupGiteaRoot())
}
diff --git a/modules/dump/dumper_test.go b/modules/dump/dumper_test.go
index b444fa2de5..2db3a598a4 100644
--- a/modules/dump/dumper_test.go
+++ b/modules/dump/dumper_test.go
@@ -25,7 +25,7 @@ func TestPrepareFileNameAndType(t *testing.T) {
assert.Equal(t,
fmt.Sprintf("outFile=%s, outType=%s", expFile, expType),
fmt.Sprintf("outFile=%s, outType=%s", outFile, outType),
- fmt.Sprintf("argFile=%s, argType=%s", argFile, argType),
+ "argFile=%s, argType=%s", argFile, argType,
)
}
diff --git a/modules/git/commit_sha256_test.go b/modules/git/commit_sha256_test.go
index 3b8b6d3763..2184a9c47c 100644
--- a/modules/git/commit_sha256_test.go
+++ b/modules/git/commit_sha256_test.go
@@ -146,7 +146,7 @@ func TestHasPreviousCommitSha256(t *testing.T) {
parentSHA := MustIDFromString("b0ec7af4547047f12d5093e37ef8f1b3b5415ed8ee17894d43a34d7d34212e9c")
notParentSHA := MustIDFromString("42e334efd04cd36eea6da0599913333c26116e1a537ca76e5b6e4af4dda00236")
assert.Equal(t, objectFormat, parentSHA.Type())
- assert.Equal(t, objectFormat.Name(), "sha256")
+ assert.Equal(t, "sha256", objectFormat.Name())
haz, err := commit.HasPreviousCommit(parentSHA)
assert.NoError(t, err)
diff --git a/modules/git/commit_test.go b/modules/git/commit_test.go
index bf381a5350..6ac65564dc 100644
--- a/modules/git/commit_test.go
+++ b/modules/git/commit_test.go
@@ -343,9 +343,9 @@ func TestGetCommitFileStatusMerges(t *testing.T) {
},
}
- assert.Equal(t, commitFileStatus.Added, expected.Added)
- assert.Equal(t, commitFileStatus.Removed, expected.Removed)
- assert.Equal(t, commitFileStatus.Modified, expected.Modified)
+ assert.Equal(t, expected.Added, commitFileStatus.Added)
+ assert.Equal(t, expected.Removed, commitFileStatus.Removed)
+ assert.Equal(t, expected.Modified, commitFileStatus.Modified)
}
func Test_GetCommitBranchStart(t *testing.T) {
diff --git a/modules/git/grep_test.go b/modules/git/grep_test.go
index 6a99f80407..005d539726 100644
--- a/modules/git/grep_test.go
+++ b/modules/git/grep_test.go
@@ -73,9 +73,9 @@ func TestGrepSearch(t *testing.T) {
res, err = GrepSearch(context.Background(), repo, "no-such-content", GrepOptions{})
assert.NoError(t, err)
- assert.Len(t, res, 0)
+ assert.Empty(t, res)
res, err = GrepSearch(context.Background(), &Repository{Path: "no-such-git-repo"}, "no-such-content", GrepOptions{})
assert.Error(t, err)
- assert.Len(t, res, 0)
+ assert.Empty(t, res)
}
diff --git a/modules/git/parse_nogogit_test.go b/modules/git/parse_nogogit_test.go
index 23fddb014c..a4436ce499 100644
--- a/modules/git/parse_nogogit_test.go
+++ b/modules/git/parse_nogogit_test.go
@@ -100,5 +100,5 @@ func TestParseTreeEntriesInvalid(t *testing.T) {
// there was a panic: "runtime error: slice bounds out of range" when the input was invalid: #20315
entries, err := ParseTreeEntries([]byte("100644 blob ea0d83c9081af9500ac9f804101b3fd0a5c293af"))
assert.Error(t, err)
- assert.Len(t, entries, 0)
+ assert.Empty(t, entries)
}
diff --git a/modules/git/repo_branch_test.go b/modules/git/repo_branch_test.go
index 009c545832..5d3b8abb3a 100644
--- a/modules/git/repo_branch_test.go
+++ b/modules/git/repo_branch_test.go
@@ -34,7 +34,7 @@ func TestRepository_GetBranches(t *testing.T) {
branches, countAll, err = bareRepo1.GetBranchNames(5, 1)
assert.NoError(t, err)
- assert.Len(t, branches, 0)
+ assert.Empty(t, branches)
assert.EqualValues(t, 3, countAll)
assert.ElementsMatch(t, []string{}, branches)
}
@@ -66,7 +66,7 @@ func TestGetRefsBySha(t *testing.T) {
// do not exist
branches, err := bareRepo5.GetRefsBySha("8006ff9adbf0cb94da7dad9e537e53817f9fa5c0", "")
assert.NoError(t, err)
- assert.Len(t, branches, 0)
+ assert.Empty(t, branches)
// refs/pull/1/head
branches, err = bareRepo5.GetRefsBySha("c83380d7056593c51a699d12b9c00627bd5743e9", PullPrefix)
diff --git a/modules/git/repo_compare_test.go b/modules/git/repo_compare_test.go
index 9983873186..454ed6b9f8 100644
--- a/modules/git/repo_compare_test.go
+++ b/modules/git/repo_compare_test.go
@@ -72,7 +72,7 @@ func TestReadPatch(t *testing.T) {
assert.Empty(t, noFile)
assert.Empty(t, noCommit)
assert.Len(t, oldCommit, 40)
- assert.True(t, oldCommit == "6e8e2a6f9efd71dbe6917816343ed8415ad696c3")
+ assert.Equal(t, "6e8e2a6f9efd71dbe6917816343ed8415ad696c3", oldCommit)
}
func TestReadWritePullHead(t *testing.T) {
@@ -113,7 +113,7 @@ func TestReadWritePullHead(t *testing.T) {
}
assert.Len(t, headContents, 40)
- assert.True(t, headContents == newCommit)
+ assert.Equal(t, headContents, newCommit)
// Remove file after the test
err = repo.RemoveReference(PullPrefix + "1/head")
diff --git a/modules/indexer/issues/internal/tests/tests.go b/modules/indexer/issues/internal/tests/tests.go
index 16f0a78ec0..94ce8520bf 100644
--- a/modules/indexer/issues/internal/tests/tests.go
+++ b/modules/indexer/issues/internal/tests/tests.go
@@ -113,7 +113,7 @@ var cases = []*testIndexerCase{
},
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
assert.Equal(t, len(data), int(result.Total))
},
},
@@ -176,7 +176,7 @@ var cases = []*testIndexerCase{
IsPull: optional.Some(false),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.False(t, data[v.ID].IsPull)
}
@@ -192,7 +192,7 @@ var cases = []*testIndexerCase{
IsPull: optional.Some(true),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.True(t, data[v.ID].IsPull)
}
@@ -208,7 +208,7 @@ var cases = []*testIndexerCase{
IsClosed: optional.Some(false),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.False(t, data[v.ID].IsClosed)
}
@@ -224,7 +224,7 @@ var cases = []*testIndexerCase{
IsClosed: optional.Some(true),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.True(t, data[v.ID].IsClosed)
}
@@ -274,7 +274,7 @@ var cases = []*testIndexerCase{
MilestoneIDs: []int64{1, 2, 6},
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.Contains(t, []int64{1, 2, 6}, data[v.ID].MilestoneID)
}
@@ -292,7 +292,7 @@ var cases = []*testIndexerCase{
MilestoneIDs: []int64{0},
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.Equal(t, int64(0), data[v.ID].MilestoneID)
}
@@ -310,7 +310,7 @@ var cases = []*testIndexerCase{
ProjectID: optional.Some(int64(1)),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.Equal(t, int64(1), data[v.ID].ProjectID)
}
@@ -328,7 +328,7 @@ var cases = []*testIndexerCase{
ProjectID: optional.Some(int64(0)),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.Equal(t, int64(0), data[v.ID].ProjectID)
}
@@ -346,7 +346,7 @@ var cases = []*testIndexerCase{
ProjectColumnID: optional.Some(int64(1)),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.Equal(t, int64(1), data[v.ID].ProjectColumnID)
}
@@ -364,7 +364,7 @@ var cases = []*testIndexerCase{
ProjectColumnID: optional.Some(int64(0)),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.Equal(t, int64(0), data[v.ID].ProjectColumnID)
}
@@ -382,7 +382,7 @@ var cases = []*testIndexerCase{
PosterID: optional.Some(int64(1)),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.Equal(t, int64(1), data[v.ID].PosterID)
}
@@ -400,7 +400,7 @@ var cases = []*testIndexerCase{
AssigneeID: optional.Some(int64(1)),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.Equal(t, int64(1), data[v.ID].AssigneeID)
}
@@ -418,7 +418,7 @@ var cases = []*testIndexerCase{
AssigneeID: optional.Some(int64(0)),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.Equal(t, int64(0), data[v.ID].AssigneeID)
}
@@ -436,7 +436,7 @@ var cases = []*testIndexerCase{
MentionID: optional.Some(int64(1)),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.Contains(t, data[v.ID].MentionIDs, int64(1))
}
@@ -454,7 +454,7 @@ var cases = []*testIndexerCase{
ReviewedID: optional.Some(int64(1)),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.Contains(t, data[v.ID].ReviewedIDs, int64(1))
}
@@ -472,7 +472,7 @@ var cases = []*testIndexerCase{
ReviewRequestedID: optional.Some(int64(1)),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.Contains(t, data[v.ID].ReviewRequestedIDs, int64(1))
}
@@ -490,7 +490,7 @@ var cases = []*testIndexerCase{
SubscriberID: optional.Some(int64(1)),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.Contains(t, data[v.ID].SubscriberIDs, int64(1))
}
@@ -509,7 +509,7 @@ var cases = []*testIndexerCase{
UpdatedBeforeUnix: optional.Some(int64(30)),
},
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
- assert.Equal(t, 5, len(result.Hits))
+ assert.Len(t, result.Hits, 5)
for _, v := range result.Hits {
assert.GreaterOrEqual(t, data[v.ID].UpdatedUnix, int64(20))
assert.LessOrEqual(t, data[v.ID].UpdatedUnix, int64(30))
diff --git a/modules/lfs/transferadapter_test.go b/modules/lfs/transferadapter_test.go
index 7fec137efe..a430b71a5f 100644
--- a/modules/lfs/transferadapter_test.go
+++ b/modules/lfs/transferadapter_test.go
@@ -96,7 +96,7 @@ func TestBasicTransferAdapter(t *testing.T) {
for n, c := range cases {
_, err := a.Download(context.Background(), c.link)
if len(c.expectederror) > 0 {
- assert.True(t, strings.Contains(err.Error(), c.expectederror), "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
+ assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
} else {
assert.NoError(t, err, "case %d", n)
}
@@ -129,7 +129,7 @@ func TestBasicTransferAdapter(t *testing.T) {
for n, c := range cases {
err := a.Upload(context.Background(), c.link, p, bytes.NewBufferString("dummy"))
if len(c.expectederror) > 0 {
- assert.True(t, strings.Contains(err.Error(), c.expectederror), "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
+ assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
} else {
assert.NoError(t, err, "case %d", n)
}
@@ -162,7 +162,7 @@ func TestBasicTransferAdapter(t *testing.T) {
for n, c := range cases {
err := a.Verify(context.Background(), c.link, p)
if len(c.expectederror) > 0 {
- assert.True(t, strings.Contains(err.Error(), c.expectederror), "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
+ assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
} else {
assert.NoError(t, err, "case %d", n)
}
diff --git a/modules/log/logger_test.go b/modules/log/logger_test.go
index 70222f64f5..0de14eb411 100644
--- a/modules/log/logger_test.go
+++ b/modules/log/logger_test.go
@@ -56,7 +56,7 @@ func TestLogger(t *testing.T) {
logger := NewLoggerWithWriters(context.Background(), "test")
dump := logger.DumpWriters()
- assert.EqualValues(t, 0, len(dump))
+ assert.Empty(t, dump)
assert.EqualValues(t, NONE, logger.GetLevel())
assert.False(t, logger.IsEnabled())
@@ -69,7 +69,7 @@ func TestLogger(t *testing.T) {
assert.EqualValues(t, DEBUG, logger.GetLevel())
dump = logger.DumpWriters()
- assert.EqualValues(t, 2, len(dump))
+ assert.Len(t, dump, 2)
logger.Trace("trace-level") // this level is not logged
logger.Debug("debug-level")
diff --git a/modules/markup/html_internal_test.go b/modules/markup/html_internal_test.go
index 9419350e61..159d712955 100644
--- a/modules/markup/html_internal_test.go
+++ b/modules/markup/html_internal_test.go
@@ -278,12 +278,12 @@ func TestRender_AutoLink(t *testing.T) {
test := func(input, expected string) {
var buffer strings.Builder
err := PostProcessDefault(NewTestRenderContext(localMetas), strings.NewReader(input), &buffer)
- assert.Equal(t, err, nil)
+ assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer.String()))
buffer.Reset()
err = PostProcessDefault(NewTestRenderContext(localMetas), strings.NewReader(input), &buffer)
- assert.Equal(t, err, nil)
+ assert.NoError(t, err)
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer.String()))
}
diff --git a/modules/packages/conan/conanfile_parser_test.go b/modules/packages/conan/conanfile_parser_test.go
index 5801570184..aabafd5f64 100644
--- a/modules/packages/conan/conanfile_parser_test.go
+++ b/modules/packages/conan/conanfile_parser_test.go
@@ -40,7 +40,7 @@ class ConanPackageConan(ConanFile):
func TestParseConanfile(t *testing.T) {
metadata, err := ParseConanfile(strings.NewReader(contentConanfile))
- assert.Nil(t, err)
+ assert.NoError(t, err)
assert.Equal(t, license, metadata.License)
assert.Equal(t, author, metadata.Author)
assert.Equal(t, homepage, metadata.ProjectURL)
diff --git a/modules/packages/conan/conaninfo_parser_test.go b/modules/packages/conan/conaninfo_parser_test.go
index 556a4b939e..f6510ca667 100644
--- a/modules/packages/conan/conaninfo_parser_test.go
+++ b/modules/packages/conan/conaninfo_parser_test.go
@@ -50,7 +50,7 @@ const (
func TestParseConaninfo(t *testing.T) {
info, err := ParseConaninfo(strings.NewReader(contentConaninfo))
assert.NotNil(t, info)
- assert.Nil(t, err)
+ assert.NoError(t, err)
assert.Equal(
t,
map[string]string{
diff --git a/modules/queue/base_test.go b/modules/queue/base_test.go
index c5bf526ae6..01b52b3c16 100644
--- a/modules/queue/base_test.go
+++ b/modules/queue/base_test.go
@@ -46,10 +46,10 @@ func testQueueBasic(t *testing.T, newFn func(cfg *BaseConfig) (baseQueue, error)
assert.NoError(t, err)
if !isUnique {
assert.EqualValues(t, 2, cnt)
- assert.EqualValues(t, false, has) // non-unique queues don't check for duplicates
+ assert.False(t, has) // non-unique queues don't check for duplicates
} else {
assert.EqualValues(t, 1, cnt)
- assert.EqualValues(t, true, has)
+ assert.True(t, has)
}
// push another item
@@ -101,7 +101,7 @@ func testQueueBasic(t *testing.T, newFn func(cfg *BaseConfig) (baseQueue, error)
pushBlockTime = 30 * time.Millisecond
err = q.PushItem(ctx, []byte("item-full"))
assert.ErrorIs(t, err, context.DeadlineExceeded)
- assert.True(t, time.Since(timeStart) >= pushBlockTime*2/3)
+ assert.GreaterOrEqual(t, time.Since(timeStart), pushBlockTime*2/3)
pushBlockTime = oldPushBlockTime
// remove all
diff --git a/modules/queue/workerqueue_test.go b/modules/queue/workerqueue_test.go
index d66253ff66..c0841a1752 100644
--- a/modules/queue/workerqueue_test.go
+++ b/modules/queue/workerqueue_test.go
@@ -172,8 +172,8 @@ func testWorkerPoolQueuePersistence(t *testing.T, queueSetting setting.QueueSett
q2() // restart the queue to continue to execute the tasks in it
- assert.NotZero(t, len(tasksQ1))
- assert.NotZero(t, len(tasksQ2))
+ assert.NotEmpty(t, tasksQ1)
+ assert.NotEmpty(t, tasksQ2)
assert.EqualValues(t, testCount, len(tasksQ1)+len(tasksQ2))
}
diff --git a/modules/references/references_test.go b/modules/references/references_test.go
index e5a0d60fe3..e224c919e9 100644
--- a/modules/references/references_test.go
+++ b/modules/references/references_test.go
@@ -526,7 +526,7 @@ func TestCustomizeCloseKeywords(t *testing.T) {
func TestParseCloseKeywords(t *testing.T) {
// Test parsing of CloseKeywords and ReopenKeywords
- assert.Len(t, parseKeywords([]string{""}), 0)
+ assert.Empty(t, parseKeywords([]string{""}))
assert.Len(t, parseKeywords([]string{" aa ", " bb ", "99", "#", "", "this is", "cc"}), 3)
for _, test := range []struct {
diff --git a/modules/repository/repo_test.go b/modules/repository/repo_test.go
index 68980f92f9..f3e7be6d7d 100644
--- a/modules/repository/repo_test.go
+++ b/modules/repository/repo_test.go
@@ -62,15 +62,15 @@ func Test_calcSync(t *testing.T) {
}
inserts, deletes, updates := calcSync(gitTags, dbReleases)
- if assert.EqualValues(t, 1, len(inserts), "inserts") {
+ if assert.Len(t, inserts, 1, "inserts") {
assert.EqualValues(t, *gitTags[2], *inserts[0], "inserts equal")
}
- if assert.EqualValues(t, 1, len(deletes), "deletes") {
+ if assert.Len(t, deletes, 1, "deletes") {
assert.EqualValues(t, 1, deletes[0], "deletes equal")
}
- if assert.EqualValues(t, 1, len(updates), "updates") {
+ if assert.Len(t, updates, 1, "updates") {
assert.EqualValues(t, *gitTags[1], *updates[0], "updates equal")
}
}
diff --git a/modules/setting/cron_test.go b/modules/setting/cron_test.go
index 3187ab18a2..55244d7075 100644
--- a/modules/setting/cron_test.go
+++ b/modules/setting/cron_test.go
@@ -38,6 +38,6 @@ EXTEND = true
_, err = getCronSettings(cfg, "test", extended)
assert.NoError(t, err)
assert.True(t, extended.Base)
- assert.EqualValues(t, extended.Second, "white rabbit")
+ assert.EqualValues(t, "white rabbit", extended.Second)
assert.True(t, extended.Extend)
}
diff --git a/modules/setting/oauth2_test.go b/modules/setting/oauth2_test.go
index 38ee4d248d..d0e5ccf13d 100644
--- a/modules/setting/oauth2_test.go
+++ b/modules/setting/oauth2_test.go
@@ -74,5 +74,5 @@ DEFAULT_APPLICATIONS = tea
DEFAULT_APPLICATIONS =
`)
loadOAuth2From(cfg)
- assert.Nil(t, nil, OAuth2.DefaultApplications)
+ assert.Nil(t, OAuth2.DefaultApplications)
}
diff --git a/modules/setting/storage_test.go b/modules/setting/storage_test.go
index 8ee37fd2b6..afff85537e 100644
--- a/modules/setting/storage_test.go
+++ b/modules/setting/storage_test.go
@@ -447,7 +447,7 @@ MINIO_USE_SSL = true
assert.NoError(t, loadRepoArchiveFrom(cfg))
assert.EqualValues(t, "my_access_key", RepoArchive.Storage.MinioConfig.AccessKeyID)
assert.EqualValues(t, "my_secret_key", RepoArchive.Storage.MinioConfig.SecretAccessKey)
- assert.EqualValues(t, true, RepoArchive.Storage.MinioConfig.UseSSL)
+ assert.True(t, RepoArchive.Storage.MinioConfig.UseSSL)
assert.EqualValues(t, "repo-archive/", RepoArchive.Storage.MinioConfig.BasePath)
}
@@ -464,7 +464,7 @@ MINIO_BASE_PATH = /prefix
assert.NoError(t, loadRepoArchiveFrom(cfg))
assert.EqualValues(t, "my_access_key", RepoArchive.Storage.MinioConfig.AccessKeyID)
assert.EqualValues(t, "my_secret_key", RepoArchive.Storage.MinioConfig.SecretAccessKey)
- assert.EqualValues(t, true, RepoArchive.Storage.MinioConfig.UseSSL)
+ assert.True(t, RepoArchive.Storage.MinioConfig.UseSSL)
assert.EqualValues(t, "/prefix/repo-archive/", RepoArchive.Storage.MinioConfig.BasePath)
cfg, err = NewConfigProviderFromData(`
@@ -477,7 +477,7 @@ MINIO_BASE_PATH = /prefix
assert.NoError(t, err)
assert.NoError(t, loadRepoArchiveFrom(cfg))
assert.EqualValues(t, "127.0.0.1", RepoArchive.Storage.MinioConfig.IamEndpoint)
- assert.EqualValues(t, true, RepoArchive.Storage.MinioConfig.UseSSL)
+ assert.True(t, RepoArchive.Storage.MinioConfig.UseSSL)
assert.EqualValues(t, "/prefix/repo-archive/", RepoArchive.Storage.MinioConfig.BasePath)
cfg, err = NewConfigProviderFromData(`
@@ -495,7 +495,7 @@ MINIO_BASE_PATH = /lfs
assert.NoError(t, loadLFSFrom(cfg))
assert.EqualValues(t, "my_access_key", LFS.Storage.MinioConfig.AccessKeyID)
assert.EqualValues(t, "my_secret_key", LFS.Storage.MinioConfig.SecretAccessKey)
- assert.EqualValues(t, true, LFS.Storage.MinioConfig.UseSSL)
+ assert.True(t, LFS.Storage.MinioConfig.UseSSL)
assert.EqualValues(t, "/lfs", LFS.Storage.MinioConfig.BasePath)
cfg, err = NewConfigProviderFromData(`
@@ -513,7 +513,7 @@ MINIO_BASE_PATH = /lfs
assert.NoError(t, loadLFSFrom(cfg))
assert.EqualValues(t, "my_access_key", LFS.Storage.MinioConfig.AccessKeyID)
assert.EqualValues(t, "my_secret_key", LFS.Storage.MinioConfig.SecretAccessKey)
- assert.EqualValues(t, true, LFS.Storage.MinioConfig.UseSSL)
+ assert.True(t, LFS.Storage.MinioConfig.UseSSL)
assert.EqualValues(t, "/lfs", LFS.Storage.MinioConfig.BasePath)
}
diff --git a/modules/user/user_test.go b/modules/user/user_test.go
index 9129ae79a1..372a675d34 100644
--- a/modules/user/user_test.go
+++ b/modules/user/user_test.go
@@ -4,7 +4,6 @@
package user
import (
- "os"
"os/exec"
"runtime"
"strings"
@@ -36,7 +35,7 @@ func TestCurrentUsername(t *testing.T) {
if user != whoami {
t.Errorf("expected %s as user, got: %s", whoami, user)
}
- os.Setenv("USER", "spoofed")
+ t.Setenv("USER", "spoofed")
user = CurrentUsername()
if user != whoami {
t.Errorf("expected %s as user, got: %s", whoami, user)
diff --git a/modules/util/color_test.go b/modules/util/color_test.go
index be6e6b122a..abd5551218 100644
--- a/modules/util/color_test.go
+++ b/modules/util/color_test.go
@@ -27,9 +27,9 @@ func Test_HexToRBGColor(t *testing.T) {
}
for n, c := range cases {
r, g, b := HexToRBGColor(c.colorString)
- assert.Equal(t, c.expectedR, r, "case %d: error R should match: expected %f, but get %f", n, c.expectedR, r)
- assert.Equal(t, c.expectedG, g, "case %d: error G should match: expected %f, but get %f", n, c.expectedG, g)
- assert.Equal(t, c.expectedB, b, "case %d: error B should match: expected %f, but get %f", n, c.expectedB, b)
+ assert.InDelta(t, c.expectedR, r, 0, "case %d: error R should match: expected %f, but get %f", n, c.expectedR, r)
+ assert.InDelta(t, c.expectedG, g, 0, "case %d: error G should match: expected %f, but get %f", n, c.expectedG, g)
+ assert.InDelta(t, c.expectedB, b, 0, "case %d: error B should match: expected %f, but get %f", n, c.expectedB, b)
}
}
diff --git a/modules/util/keypair_test.go b/modules/util/keypair_test.go
index c6f68c845a..2bade3bb28 100644
--- a/modules/util/keypair_test.go
+++ b/modules/util/keypair_test.go
@@ -10,7 +10,6 @@ import (
"crypto/sha256"
"crypto/x509"
"encoding/pem"
- "regexp"
"testing"
"github.com/stretchr/testify/assert"
@@ -23,8 +22,8 @@ func TestKeygen(t *testing.T) {
assert.NotEmpty(t, priv)
assert.NotEmpty(t, pub)
- assert.Regexp(t, regexp.MustCompile("^-----BEGIN RSA PRIVATE KEY-----.*"), priv)
- assert.Regexp(t, regexp.MustCompile("^-----BEGIN PUBLIC KEY-----.*"), pub)
+ assert.Regexp(t, "^-----BEGIN RSA PRIVATE KEY-----.*", priv)
+ assert.Regexp(t, "^-----BEGIN PUBLIC KEY-----.*", pub)
}
func TestSignUsingKeys(t *testing.T) {
diff --git a/modules/util/time_str_test.go b/modules/util/time_str_test.go
index 67b7978d0b..8d1de51c8e 100644
--- a/modules/util/time_str_test.go
+++ b/modules/util/time_str_test.go
@@ -27,9 +27,9 @@ func TestTimeStr(t *testing.T) {
t.Run(test.input, func(t *testing.T) {
output, err := TimeEstimateParse(test.input)
if test.err {
- assert.NotNil(t, err)
+ assert.Error(t, err)
} else {
- assert.Nil(t, err)
+ assert.NoError(t, err)
}
assert.Equal(t, test.output, output)
})
diff --git a/modules/util/util_test.go b/modules/util/util_test.go
index 9ce72fb866..5abce08b41 100644
--- a/modules/util/util_test.go
+++ b/modules/util/util_test.go
@@ -122,8 +122,8 @@ func Test_NormalizeEOL(t *testing.T) {
func Test_RandomInt(t *testing.T) {
randInt, err := CryptoRandomInt(255)
- assert.True(t, randInt >= 0)
- assert.True(t, randInt <= 255)
+ assert.GreaterOrEqual(t, randInt, int64(0))
+ assert.LessOrEqual(t, randInt, int64(255))
assert.NoError(t, err)
}
@@ -223,22 +223,22 @@ func BenchmarkToUpper(b *testing.B) {
}
func TestToTitleCase(t *testing.T) {
- assert.Equal(t, ToTitleCase(`foo bar baz`), `Foo Bar Baz`)
- assert.Equal(t, ToTitleCase(`FOO BAR BAZ`), `Foo Bar Baz`)
+ assert.Equal(t, `Foo Bar Baz`, ToTitleCase(`foo bar baz`))
+ assert.Equal(t, `Foo Bar Baz`, ToTitleCase(`FOO BAR BAZ`))
}
func TestToPointer(t *testing.T) {
assert.Equal(t, "abc", *ToPointer("abc"))
assert.Equal(t, 123, *ToPointer(123))
abc := "abc"
- assert.False(t, &abc == ToPointer(abc))
+ assert.NotSame(t, &abc, ToPointer(abc))
val123 := 123
- assert.False(t, &val123 == ToPointer(val123))
+ assert.NotSame(t, &val123, ToPointer(val123))
}
func TestReserveLineBreakForTextarea(t *testing.T) {
- assert.Equal(t, ReserveLineBreakForTextarea("test\r\ndata"), "test\ndata")
- assert.Equal(t, ReserveLineBreakForTextarea("test\r\ndata\r\n"), "test\ndata\n")
+ assert.Equal(t, "test\ndata", ReserveLineBreakForTextarea("test\r\ndata"))
+ assert.Equal(t, "test\ndata\n", ReserveLineBreakForTextarea("test\r\ndata\r\n"))
}
func TestOptionalArg(t *testing.T) {