Skip to content

Commit 0fde8ec

Browse files
authored
Enable testifylint rules (#34075)
enable testifylint rules disabled in: #34054
1 parent 0fd5392 commit 0fde8ec

File tree

262 files changed

+1319
-1369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

262 files changed

+1319
-1369
lines changed

.golangci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ linters:
9292
disable:
9393
- go-require
9494
- require-error
95-
- equal-values
96-
- empty
97-
- formatter
98-
- len
9995
usetesting:
10096
os-temp-dir: true
10197
exclusions:

cmd/admin_auth_ldap_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,11 @@ func TestAddLdapBindDn(t *testing.T) {
229229
return nil
230230
},
231231
updateAuthSource: func(ctx context.Context, authSource *auth.Source) error {
232-
assert.FailNow(t, "case %d: should not call updateAuthSource", n)
232+
assert.FailNow(t, "updateAuthSource called", "case %d: should not call updateAuthSource", n)
233233
return nil
234234
},
235235
getAuthSourceByID: func(ctx context.Context, id int64) (*auth.Source, error) {
236-
assert.FailNow(t, "case %d: should not call getAuthSourceByID", n)
236+
assert.FailNow(t, "getAuthSourceByID called", "case %d: should not call getAuthSourceByID", n)
237237
return nil, nil
238238
},
239239
}
@@ -460,11 +460,11 @@ func TestAddLdapSimpleAuth(t *testing.T) {
460460
return nil
461461
},
462462
updateAuthSource: func(ctx context.Context, authSource *auth.Source) error {
463-
assert.FailNow(t, "case %d: should not call updateAuthSource", n)
463+
assert.FailNow(t, "updateAuthSource called", "case %d: should not call updateAuthSource", n)
464464
return nil
465465
},
466466
getAuthSourceByID: func(ctx context.Context, id int64) (*auth.Source, error) {
467-
assert.FailNow(t, "case %d: should not call getAuthSourceByID", n)
467+
assert.FailNow(t, "getAuthSourceById called", "case %d: should not call getAuthSourceByID", n)
468468
return nil, nil
469469
},
470470
}
@@ -925,7 +925,7 @@ func TestUpdateLdapBindDn(t *testing.T) {
925925
return nil
926926
},
927927
createAuthSource: func(ctx context.Context, authSource *auth.Source) error {
928-
assert.FailNow(t, "case %d: should not call createAuthSource", n)
928+
assert.FailNow(t, "createAuthSource called", "case %d: should not call createAuthSource", n)
929929
return nil
930930
},
931931
updateAuthSource: func(ctx context.Context, authSource *auth.Source) error {
@@ -1315,7 +1315,7 @@ func TestUpdateLdapSimpleAuth(t *testing.T) {
13151315
return nil
13161316
},
13171317
createAuthSource: func(ctx context.Context, authSource *auth.Source) error {
1318-
assert.FailNow(t, "case %d: should not call createAuthSource", n)
1318+
assert.FailNow(t, "createAuthSource called", "case %d: should not call createAuthSource", n)
13191319
return nil
13201320
},
13211321
updateAuthSource: func(ctx context.Context, authSource *auth.Source) error {

cmd/admin_user_create_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ func TestAdminUserCreate(t *testing.T) {
6161
assert.NoError(t, createUser("u", "--user-type bot"))
6262
u := unittest.AssertExistsAndLoadBean(t, &user_model.User{LowerName: "u"})
6363
assert.Equal(t, user_model.UserTypeBot, u.Type)
64-
assert.Equal(t, "", u.Passwd)
64+
assert.Empty(t, u.Passwd)
6565
})
6666
}

cmd/main_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,27 @@ func TestCliCmdError(t *testing.T) {
131131
r, err := runTestApp(app, "./gitea", "test-cmd")
132132
assert.Error(t, err)
133133
assert.Equal(t, 1, r.ExitCode)
134-
assert.Equal(t, "", r.Stdout)
134+
assert.Empty(t, r.Stdout)
135135
assert.Equal(t, "Command error: normal error\n", r.Stderr)
136136

137137
app = newTestApp(func(ctx *cli.Context) error { return cli.Exit("exit error", 2) })
138138
r, err = runTestApp(app, "./gitea", "test-cmd")
139139
assert.Error(t, err)
140140
assert.Equal(t, 2, r.ExitCode)
141-
assert.Equal(t, "", r.Stdout)
141+
assert.Empty(t, r.Stdout)
142142
assert.Equal(t, "exit error\n", r.Stderr)
143143

144144
app = newTestApp(func(ctx *cli.Context) error { return nil })
145145
r, err = runTestApp(app, "./gitea", "test-cmd", "--no-such")
146146
assert.Error(t, err)
147147
assert.Equal(t, 1, r.ExitCode)
148148
assert.Equal(t, "Incorrect Usage: flag provided but not defined: -no-such\n\n", r.Stdout)
149-
assert.Equal(t, "", r.Stderr) // the cli package's strange behavior, the error message is not in stderr ....
149+
assert.Empty(t, r.Stderr) // the cli package's strange behavior, the error message is not in stderr ....
150150

151151
app = newTestApp(func(ctx *cli.Context) error { return nil })
152152
r, err = runTestApp(app, "./gitea", "test-cmd")
153153
assert.NoError(t, err)
154154
assert.Equal(t, -1, r.ExitCode) // the cli.OsExiter is not called
155-
assert.Equal(t, "", r.Stdout)
156-
assert.Equal(t, "", r.Stderr)
155+
assert.Empty(t, r.Stdout)
156+
assert.Empty(t, r.Stderr)
157157
}

cmd/migrate_storage_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ func TestMigratePackages(t *testing.T) {
6969
entries, err := os.ReadDir(p)
7070
assert.NoError(t, err)
7171
assert.Len(t, entries, 2)
72-
assert.EqualValues(t, "01", entries[0].Name())
73-
assert.EqualValues(t, "tmp", entries[1].Name())
72+
assert.Equal(t, "01", entries[0].Name())
73+
assert.Equal(t, "tmp", entries[1].Name())
7474
}

models/actions/runner_token_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestGetLatestRunnerToken(t *testing.T) {
1717
token := unittest.AssertExistsAndLoadBean(t, &ActionRunnerToken{ID: 3})
1818
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
1919
assert.NoError(t, err)
20-
assert.EqualValues(t, expectedToken, token)
20+
assert.Equal(t, expectedToken, token)
2121
}
2222

2323
func TestNewRunnerToken(t *testing.T) {
@@ -26,7 +26,7 @@ func TestNewRunnerToken(t *testing.T) {
2626
assert.NoError(t, err)
2727
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
2828
assert.NoError(t, err)
29-
assert.EqualValues(t, expectedToken, token)
29+
assert.Equal(t, expectedToken, token)
3030
}
3131

3232
func TestUpdateRunnerToken(t *testing.T) {
@@ -36,5 +36,5 @@ func TestUpdateRunnerToken(t *testing.T) {
3636
assert.NoError(t, UpdateRunnerToken(db.DefaultContext, token))
3737
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
3838
assert.NoError(t, err)
39-
assert.EqualValues(t, expectedToken, token)
39+
assert.Equal(t, expectedToken, token)
4040
}

models/activities/action_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestDeleteIssueActions(t *testing.T) {
130130

131131
// load an issue
132132
issue := unittest.AssertExistsAndLoadBean(t, &issue_model.Issue{ID: 4})
133-
assert.NotEqualValues(t, issue.ID, issue.Index) // it needs to use different ID/Index to test the DeleteIssueActions to delete some actions by IssueIndex
133+
assert.NotEqual(t, issue.ID, issue.Index) // it needs to use different ID/Index to test the DeleteIssueActions to delete some actions by IssueIndex
134134

135135
// insert a comment
136136
err := db.Insert(db.DefaultContext, &issue_model.Comment{Type: issue_model.CommentTypeComment, IssueID: issue.ID})

models/activities/notification_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ func TestNotificationsForUser(t *testing.T) {
4444
assert.NoError(t, err)
4545
if assert.Len(t, notfs, 3) {
4646
assert.EqualValues(t, 5, notfs[0].ID)
47-
assert.EqualValues(t, user.ID, notfs[0].UserID)
47+
assert.Equal(t, user.ID, notfs[0].UserID)
4848
assert.EqualValues(t, 4, notfs[1].ID)
49-
assert.EqualValues(t, user.ID, notfs[1].UserID)
49+
assert.Equal(t, user.ID, notfs[1].UserID)
5050
assert.EqualValues(t, 2, notfs[2].ID)
51-
assert.EqualValues(t, user.ID, notfs[2].UserID)
51+
assert.Equal(t, user.ID, notfs[2].UserID)
5252
}
5353
}
5454

@@ -58,7 +58,7 @@ func TestNotification_GetRepo(t *testing.T) {
5858
repo, err := notf.GetRepo(db.DefaultContext)
5959
assert.NoError(t, err)
6060
assert.Equal(t, repo, notf.Repository)
61-
assert.EqualValues(t, notf.RepoID, repo.ID)
61+
assert.Equal(t, notf.RepoID, repo.ID)
6262
}
6363

6464
func TestNotification_GetIssue(t *testing.T) {
@@ -67,7 +67,7 @@ func TestNotification_GetIssue(t *testing.T) {
6767
issue, err := notf.GetIssue(db.DefaultContext)
6868
assert.NoError(t, err)
6969
assert.Equal(t, issue, notf.Issue)
70-
assert.EqualValues(t, notf.IssueID, issue.ID)
70+
assert.Equal(t, notf.IssueID, issue.ID)
7171
}
7272

7373
func TestGetNotificationCount(t *testing.T) {
@@ -136,5 +136,5 @@ func TestSetIssueReadBy(t *testing.T) {
136136

137137
nt, err := activities_model.GetIssueNotification(db.DefaultContext, user.ID, issue.ID)
138138
assert.NoError(t, err)
139-
assert.EqualValues(t, activities_model.NotificationStatusRead, nt.Status)
139+
assert.Equal(t, activities_model.NotificationStatusRead, nt.Status)
140140
}

models/asymkey/ssh_key_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/42wim/sshsig"
2020
"github.com/stretchr/testify/assert"
21+
"github.com/stretchr/testify/require"
2122
)
2223

2324
func Test_SSHParsePublicKey(t *testing.T) {
@@ -42,7 +43,7 @@ func Test_SSHParsePublicKey(t *testing.T) {
4243
keyTypeN, lengthN, err := SSHNativeParsePublicKey(tc.content)
4344
assert.NoError(t, err)
4445
assert.Equal(t, tc.keyType, keyTypeN)
45-
assert.EqualValues(t, tc.length, lengthN)
46+
assert.Equal(t, tc.length, lengthN)
4647
})
4748
if tc.skipSSHKeygen {
4849
return
@@ -52,19 +53,18 @@ func Test_SSHParsePublicKey(t *testing.T) {
5253
if err != nil {
5354
// Some servers do not support ecdsa format.
5455
if !strings.Contains(err.Error(), "line 1 too long:") {
55-
assert.FailNow(t, "%v", err)
56+
require.NoError(t, err)
5657
}
5758
}
5859
assert.Equal(t, tc.keyType, keyTypeK)
59-
assert.EqualValues(t, tc.length, lengthK)
60+
assert.Equal(t, tc.length, lengthK)
6061
})
6162
t.Run("SSHParseKeyNative", func(t *testing.T) {
6263
keyTypeK, lengthK, err := SSHNativeParsePublicKey(tc.content)
63-
if err != nil {
64-
assert.FailNow(t, "%v", err)
65-
}
64+
require.NoError(t, err)
65+
6666
assert.Equal(t, tc.keyType, keyTypeK)
67-
assert.EqualValues(t, tc.length, lengthK)
67+
assert.Equal(t, tc.length, lengthK)
6868
})
6969
})
7070
}

models/auth/oauth2_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func TestOAuth2Application_CreateGrant(t *testing.T) {
126126
assert.NotNil(t, grant)
127127
assert.Equal(t, int64(2), grant.UserID)
128128
assert.Equal(t, int64(1), grant.ApplicationID)
129-
assert.Equal(t, "", grant.Scope)
129+
assert.Empty(t, grant.Scope)
130130
}
131131

132132
//////////////////// Grant

models/db/context_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func TestContextSafety(t *testing.T) {
118118
})
119119
return nil
120120
})
121-
assert.EqualValues(t, testCount, actualCount)
121+
assert.Equal(t, testCount, actualCount)
122122

123123
// deny the bad usages
124124
assert.PanicsWithError(t, "using database context in an iterator would cause corrupted results", func() {

models/db/engine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestDeleteOrphanedObjects(t *testing.T) {
5252

5353
countAfter, err := db.GetEngine(db.DefaultContext).Count(&issues_model.PullRequest{})
5454
assert.NoError(t, err)
55-
assert.EqualValues(t, countBefore, countAfter)
55+
assert.Equal(t, countBefore, countAfter)
5656
}
5757

5858
func TestPrimaryKeys(t *testing.T) {

models/db/list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ func TestFind(t *testing.T) {
4747

4848
repoUnits, newCnt, err := db.FindAndCount[repo_model.RepoUnit](db.DefaultContext, opts)
4949
assert.NoError(t, err)
50-
assert.EqualValues(t, cnt, newCnt)
50+
assert.Equal(t, cnt, newCnt)
5151
assert.Len(t, repoUnits, repoUnitCount)
5252
}

models/dbfs/dbfs_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ func TestDbfsBasic(t *testing.T) {
3131

3232
n, err := f.Write([]byte("0123456789")) // blocks: 0123 4567 89
3333
assert.NoError(t, err)
34-
assert.EqualValues(t, 10, n)
34+
assert.Equal(t, 10, n)
3535

3636
_, err = f.Seek(0, io.SeekStart)
3737
assert.NoError(t, err)
3838

3939
buf, err := io.ReadAll(f)
4040
assert.NoError(t, err)
41-
assert.EqualValues(t, 10, n)
42-
assert.EqualValues(t, "0123456789", string(buf))
41+
assert.Equal(t, 10, n)
42+
assert.Equal(t, "0123456789", string(buf))
4343

4444
// write some new data
4545
_, err = f.Seek(1, io.SeekStart)
@@ -50,14 +50,14 @@ func TestDbfsBasic(t *testing.T) {
5050
// read from offset
5151
buf, err = io.ReadAll(f)
5252
assert.NoError(t, err)
53-
assert.EqualValues(t, "9", string(buf))
53+
assert.Equal(t, "9", string(buf))
5454

5555
// read all
5656
_, err = f.Seek(0, io.SeekStart)
5757
assert.NoError(t, err)
5858
buf, err = io.ReadAll(f)
5959
assert.NoError(t, err)
60-
assert.EqualValues(t, "0bcdefghi9", string(buf))
60+
assert.Equal(t, "0bcdefghi9", string(buf))
6161

6262
// write to new size
6363
_, err = f.Seek(-1, io.SeekEnd)
@@ -68,7 +68,7 @@ func TestDbfsBasic(t *testing.T) {
6868
assert.NoError(t, err)
6969
buf, err = io.ReadAll(f)
7070
assert.NoError(t, err)
71-
assert.EqualValues(t, "0bcdefghiJKLMNOP", string(buf))
71+
assert.Equal(t, "0bcdefghiJKLMNOP", string(buf))
7272

7373
// write beyond EOF and fill with zero
7474
_, err = f.Seek(5, io.SeekCurrent)
@@ -79,7 +79,7 @@ func TestDbfsBasic(t *testing.T) {
7979
assert.NoError(t, err)
8080
buf, err = io.ReadAll(f)
8181
assert.NoError(t, err)
82-
assert.EqualValues(t, "0bcdefghiJKLMNOP\x00\x00\x00\x00\x00xyzu", string(buf))
82+
assert.Equal(t, "0bcdefghiJKLMNOP\x00\x00\x00\x00\x00xyzu", string(buf))
8383

8484
// write to the block with zeros
8585
_, err = f.Seek(-6, io.SeekCurrent)
@@ -90,7 +90,7 @@ func TestDbfsBasic(t *testing.T) {
9090
assert.NoError(t, err)
9191
buf, err = io.ReadAll(f)
9292
assert.NoError(t, err)
93-
assert.EqualValues(t, "0bcdefghiJKLMNOP\x00\x00\x00ABCDzu", string(buf))
93+
assert.Equal(t, "0bcdefghiJKLMNOP\x00\x00\x00ABCDzu", string(buf))
9494

9595
assert.NoError(t, f.Close())
9696

@@ -117,7 +117,7 @@ func TestDbfsBasic(t *testing.T) {
117117
assert.NoError(t, err)
118118
stat, err := f.Stat()
119119
assert.NoError(t, err)
120-
assert.EqualValues(t, "test.txt", stat.Name())
120+
assert.Equal(t, "test.txt", stat.Name())
121121
assert.EqualValues(t, 0, stat.Size())
122122
_, err = f.Write([]byte("0123456789"))
123123
assert.NoError(t, err)
@@ -144,7 +144,7 @@ func TestDbfsReadWrite(t *testing.T) {
144144

145145
line, err := f2r.ReadString('\n')
146146
assert.NoError(t, err)
147-
assert.EqualValues(t, "line 1\n", line)
147+
assert.Equal(t, "line 1\n", line)
148148
_, err = f2r.ReadString('\n')
149149
assert.ErrorIs(t, err, io.EOF)
150150

@@ -153,7 +153,7 @@ func TestDbfsReadWrite(t *testing.T) {
153153

154154
line, err = f2r.ReadString('\n')
155155
assert.NoError(t, err)
156-
assert.EqualValues(t, "line 2\n", line)
156+
assert.Equal(t, "line 2\n", line)
157157
_, err = f2r.ReadString('\n')
158158
assert.ErrorIs(t, err, io.EOF)
159159
}
@@ -186,5 +186,5 @@ func TestDbfsSeekWrite(t *testing.T) {
186186

187187
buf, err := io.ReadAll(fr)
188188
assert.NoError(t, err)
189-
assert.EqualValues(t, "111333", string(buf))
189+
assert.Equal(t, "111333", string(buf))
190190
}

models/git/branch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
func TestAddDeletedBranch(t *testing.T) {
2222
assert.NoError(t, unittest.PrepareTestDatabase())
2323
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
24-
assert.EqualValues(t, git.Sha1ObjectFormat.Name(), repo.ObjectFormatName)
24+
assert.Equal(t, git.Sha1ObjectFormat.Name(), repo.ObjectFormatName)
2525
firstBranch := unittest.AssertExistsAndLoadBean(t, &git_model.Branch{ID: 1})
2626

2727
assert.True(t, firstBranch.IsDeleted)

models/git/protected_branch_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestBranchRuleMatchPriority(t *testing.T) {
7070
assert.Error(t, fmt.Errorf("no matched rules but expected %s[%d]", kase.Rules[kase.ExpectedMatchIdx], kase.ExpectedMatchIdx))
7171
}
7272
} else {
73-
assert.EqualValues(t, kase.Rules[kase.ExpectedMatchIdx], matchedPB.RuleName)
73+
assert.Equal(t, kase.Rules[kase.ExpectedMatchIdx], matchedPB.RuleName)
7474
}
7575
}
7676
}

models/git/protected_branch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestBranchRuleMatch(t *testing.T) {
7474
} else {
7575
infact = " not"
7676
}
77-
assert.EqualValues(t, kase.ExpectedMatch, pb.Match(kase.BranchName),
77+
assert.Equal(t, kase.ExpectedMatch, pb.Match(kase.BranchName),
7878
"%s should%s match %s but it is%s", kase.BranchName, should, kase.Rule, infact,
7979
)
8080
}

0 commit comments

Comments
 (0)