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

0 commit comments

Comments
 (0)