Skip to content

Commit 8517a41

Browse files
committed
enable formatter rule
1 parent 0dc45e5 commit 8517a41

File tree

12 files changed

+42
-89
lines changed

12 files changed

+42
-89
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ linters:
9292
disable:
9393
- go-require
9494
- require-error
95-
- formatter
9695
usetesting:
9796
os-temp-dir: true
9897
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 {

models/asymkey/ssh_key_test.go

Lines changed: 4 additions & 4 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) {
@@ -52,17 +53,16 @@ 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)
5960
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)
6767
assert.Equal(t, tc.length, lengthK)
6868
})

models/unittest/consistency.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"code.gitea.io/gitea/models/db"
1212

1313
"github.com/stretchr/testify/assert"
14+
"github.com/stretchr/testify/require"
1415
"xorm.io/builder"
1516
)
1617

@@ -24,7 +25,7 @@ const (
2425
var consistencyCheckMap = make(map[string]func(t assert.TestingT, bean any))
2526

2627
// CheckConsistencyFor test that all matching database entries are consistent
27-
func CheckConsistencyFor(t assert.TestingT, beansToCheck ...any) {
28+
func CheckConsistencyFor(t require.TestingT, beansToCheck ...any) {
2829
for _, bean := range beansToCheck {
2930
sliceType := reflect.SliceOf(reflect.TypeOf(bean))
3031
sliceValue := reflect.MakeSlice(sliceType, 0, 10)
@@ -42,13 +43,11 @@ func CheckConsistencyFor(t assert.TestingT, beansToCheck ...any) {
4243
}
4344
}
4445

45-
func checkForConsistency(t assert.TestingT, bean any) {
46+
func checkForConsistency(t require.TestingT, bean any) {
4647
tb, err := db.TableInfo(bean)
4748
assert.NoError(t, err)
4849
f := consistencyCheckMap[tb.Name]
49-
if f == nil {
50-
assert.FailNow(t, "unknown bean type: %#v", bean)
51-
}
50+
require.NotNil(t, f, "unknown bean type: %#v", bean)
5251
f(t, bean)
5352
}
5453

modules/git/repo_tag_test.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,9 @@ func TestRepository_GetTag(t *testing.T) {
6464

6565
// and try to get the Tag for lightweight tag
6666
lTag, err := bareRepo1.GetTag(lTagName)
67-
if err != nil {
68-
assert.NoError(t, err)
69-
return
70-
}
71-
if lTag == nil {
72-
assert.NotNil(t, lTag)
73-
assert.FailNow(t, "nil lTag: %s", lTagName)
74-
}
67+
require.NoError(t, err)
68+
require.NotNil(t, lTag, "nil lTag: %s", lTagName)
69+
7570
assert.Equal(t, lTagName, lTag.Name)
7671
assert.Equal(t, lTagCommitID, lTag.ID.String())
7772
assert.Equal(t, lTagCommitID, lTag.Object.String())
@@ -97,14 +92,9 @@ func TestRepository_GetTag(t *testing.T) {
9792
}
9893

9994
aTag, err := bareRepo1.GetTag(aTagName)
100-
if err != nil {
101-
assert.NoError(t, err)
102-
return
103-
}
104-
if aTag == nil {
105-
assert.NotNil(t, aTag)
106-
assert.FailNow(t, "nil aTag: %s", aTagName)
107-
}
95+
require.NoError(t, err)
96+
require.NotNil(t, aTag, "nil aTag: %s", aTagName)
97+
10898
assert.Equal(t, aTagName, aTag.Name)
10999
assert.Equal(t, aTagID, aTag.ID.String())
110100
assert.NotEqual(t, aTagID, aTag.Object.String())

modules/indexer/code/indexer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func TestESIndexAndSearch(t *testing.T) {
310310
if indexer != nil {
311311
indexer.Close()
312312
}
313-
assert.FailNow(t, "Unable to init ES indexer Error: %v", err)
313+
require.NoError(t, err, "Unable to init ES indexer")
314314
}
315315

316316
defer indexer.Close()

tests/integration/api_packages_conan_test.go

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

357357
assert.Equal(t, int64(len(contentConaninfo)), pb.Size)
358358
} else {
359-
assert.FailNow(t, "unknown file: %s", pf.Name)
359+
assert.FailNow(t, "unknown file", "unknown file: %s", pf.Name)
360360
}
361361
}
362362
})

tests/integration/api_packages_container_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func TestPackageContainer(t *testing.T) {
441441
assert.Equal(t, "application/vnd.docker.image.rootfs.diff.tar.gzip", pfd.Properties.GetByName(container_module.PropertyMediaType))
442442
assert.Equal(t, blobDigest, pfd.Properties.GetByName(container_module.PropertyDigest))
443443
default:
444-
assert.FailNow(t, "unknown file: %s", pfd.File.Name)
444+
assert.FailNow(t, "unknown file", "unknown file: %s", pfd.File.Name)
445445
}
446446
}
447447

tests/integration/api_packages_nuget_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func TestPackageNuGet(t *testing.T) {
276276
case fmt.Sprintf("%s.nuspec", packageName):
277277
assert.False(t, pf.IsLead)
278278
default:
279-
assert.Fail(t, "unexpected filename: %v", pf.Name)
279+
assert.Fail(t, "unexpected filename", "unexpected filename: %v", pf.Name)
280280
}
281281
}
282282

@@ -322,7 +322,7 @@ func TestPackageNuGet(t *testing.T) {
322322
case fmt.Sprintf("%s.nuspec", packageName):
323323
assert.False(t, pf.IsLead)
324324
default:
325-
assert.Fail(t, "unexpected filename: %v", pf.Name)
325+
assert.Fail(t, "unexpected filename", "unexpected filename: %v", pf.Name)
326326
}
327327
}
328328

@@ -419,7 +419,7 @@ AAAjQmxvYgAAAGm7ENm9SGxMtAFVvPUsPJTF6PbtAAAAAFcVogEJAAAAAQAAAA==`)
419419
assert.Equal(t, nuget_module.PropertySymbolID, pps[0].Name)
420420
assert.Equal(t, symbolID, pps[0].Value)
421421
default:
422-
assert.FailNow(t, "unexpected file: %v", pf.Name)
422+
assert.FailNow(t, "unexpected file", "unexpected file: %v", pf.Name)
423423
}
424424
}
425425

tests/integration/api_repo_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ func TestAPIOrgReposWithCodeUnitDisabled(t *testing.T) {
337337
var units []unit_model.Type
338338
units = append(units, unit_model.TypeCode)
339339

340-
if err := repo_service.UpdateRepositoryUnits(db.DefaultContext, repo21, nil, units); err != nil {
341-
assert.Fail(t, "should have been able to delete code repository unit; failed to %v", err)
342-
}
340+
err := repo_service.UpdateRepositoryUnits(db.DefaultContext, repo21, nil, units)
341+
assert.NoError(t, err, "should have been able to delete code repository unit")
342+
343343
assert.False(t, repo21.UnitEnabled(db.DefaultContext, unit_model.TypeCode))
344344

345345
session := loginUser(t, "user2")
@@ -405,7 +405,7 @@ func TestAPIRepoMigrate(t *testing.T) {
405405
case "You can not import from disallowed hosts.":
406406
assert.Equal(t, "private-ip", testCase.repoName)
407407
default:
408-
assert.FailNow(t, "unexpected error '%v' on url '%s'", respJSON["message"], testCase.cloneURL)
408+
assert.FailNow(t, "unexpected error", "unexpected error '%v' on url '%s'", respJSON["message"], testCase.cloneURL)
409409
}
410410
} else {
411411
assert.Equal(t, testCase.expectedStatus, resp.Code)

0 commit comments

Comments
 (0)