Skip to content

Commit f1173d6

Browse files
KN4CK3RsilverwindGiteaBot
authored
Use more specific test methods (#24265)
Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Giteabot <teabot@gitea.io>
1 parent ac384c4 commit f1173d6

Some content is hidden

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

41 files changed

+118
-118
lines changed

cmd/migrate_storage_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestMigratePackages(t *testing.T) {
6767

6868
entries, err := os.ReadDir(p)
6969
assert.NoError(t, err)
70-
assert.EqualValues(t, 2, len(entries))
70+
assert.Len(t, entries, 2)
7171
assert.EqualValues(t, "01", entries[0].Name())
7272
assert.EqualValues(t, "tmp", entries[1].Name())
7373
}

models/db/list_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestFind(t *testing.T) {
4040
var repoUnits []repo_model.RepoUnit
4141
err = db.Find(db.DefaultContext, &opts, &repoUnits)
4242
assert.NoError(t, err)
43-
assert.EqualValues(t, repoUnitCount, len(repoUnits))
43+
assert.Len(t, repoUnits, repoUnitCount)
4444

4545
cnt, err := db.Count(db.DefaultContext, &opts, new(repo_model.RepoUnit))
4646
assert.NoError(t, err)

models/git/branches_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ func TestFindRenamedBranch(t *testing.T) {
8888
assert.NoError(t, unittest.PrepareTestDatabase())
8989
branch, exist, err := git_model.FindRenamedBranch(db.DefaultContext, 1, "dev")
9090
assert.NoError(t, err)
91-
assert.Equal(t, true, exist)
91+
assert.True(t, exist)
9292
assert.Equal(t, "master", branch.To)
9393

9494
_, exist, err = git_model.FindRenamedBranch(db.DefaultContext, 1, "unknow")
9595
assert.NoError(t, err)
96-
assert.Equal(t, false, exist)
96+
assert.False(t, exist)
9797
}
9898

9999
func TestRenameBranch(t *testing.T) {
@@ -115,7 +115,7 @@ func TestRenameBranch(t *testing.T) {
115115
return nil
116116
}))
117117

118-
assert.Equal(t, true, _isDefault)
118+
assert.True(t, _isDefault)
119119
repo1 = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
120120
assert.Equal(t, "main", repo1.DefaultBranch)
121121

models/issues/pull_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ func TestHasUnmergedPullRequestsByHeadInfo(t *testing.T) {
109109

110110
exist, err := issues_model.HasUnmergedPullRequestsByHeadInfo(db.DefaultContext, 1, "branch2")
111111
assert.NoError(t, err)
112-
assert.Equal(t, true, exist)
112+
assert.True(t, exist)
113113

114114
exist, err = issues_model.HasUnmergedPullRequestsByHeadInfo(db.DefaultContext, 1, "not_exist_branch")
115115
assert.NoError(t, err)
116-
assert.Equal(t, false, exist)
116+
assert.False(t, exist)
117117
}
118118

119119
func TestGetUnmergedPullRequestsByHeadInfo(t *testing.T) {

models/issues/tracked_time_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestAddTime(t *testing.T) {
3535
assert.Equal(t, int64(3661), tt.Time)
3636

3737
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{Type: issues_model.CommentTypeAddTimeManual, PosterID: 3, IssueID: 1})
38-
assert.Equal(t, comment.Content, "1 hour 1 minute")
38+
assert.Equal(t, "1 hour 1 minute", comment.Content)
3939
}
4040

4141
func TestGetTrackedTimes(t *testing.T) {

models/unittest/consistency.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func init() {
152152
Query()
153153
assert.NoError(t, err)
154154

155-
assert.EqualValues(t, label.int("NumIssues"), len(issueLabels), "Unexpected number of issue for label id: %d", label.int("ID"))
155+
assert.Len(t, issueLabels, label.int("NumIssues"), "Unexpected number of issue for label id: %d", label.int("ID"))
156156

157157
issueIDs := make([]int, len(issueLabels))
158158
for i, issueLabel := range issueLabels {

models/user/user_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ func TestGetUserEmailsByNames(t *testing.T) {
3636
assert.NoError(t, unittest.PrepareTestDatabase())
3737

3838
// ignore none active user email
39-
assert.Equal(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user9"}))
40-
assert.Equal(t, []string{"user8@example.com", "user5@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user5"}))
39+
assert.ElementsMatch(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user9"}))
40+
assert.ElementsMatch(t, []string{"user8@example.com", "user5@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user5"}))
4141

42-
assert.Equal(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user7"}))
42+
assert.ElementsMatch(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user7"}))
4343
}
4444

4545
func TestCanCreateOrganization(t *testing.T) {

modules/git/repo_attribute_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
1919

2020
n, err := wr.Write([]byte(testStr))
2121

22-
assert.Equal(t, n, len(testStr))
22+
assert.Len(t, testStr, n)
2323
assert.NoError(t, err)
2424
select {
2525
case attr := <-wr.ReadAttribute():
@@ -32,7 +32,7 @@ func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
3232
// Write a second attribute again
3333
n, err = wr.Write([]byte(testStr))
3434

35-
assert.Equal(t, n, len(testStr))
35+
assert.Len(t, testStr, n)
3636
assert.NoError(t, err)
3737

3838
select {

modules/git/repo_commit_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ func TestRepository_CommitsBetweenIDs(t *testing.T) {
9797
for i, c := range cases {
9898
commits, err := bareRepo1.CommitsBetweenIDs(c.NewID, c.OldID)
9999
assert.NoError(t, err)
100-
assert.Equal(t, c.ExpectedCommits, len(commits), "case %d", i)
100+
assert.Len(t, commits, c.ExpectedCommits, "case %d", i)
101101
}
102102
}

modules/git/repo_tag_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestRepository_GetTags(t *testing.T) {
2626
return
2727
}
2828
assert.Len(t, tags, 2)
29-
assert.Equal(t, len(tags), total)
29+
assert.Len(t, tags, total)
3030
assert.EqualValues(t, "signed-tag", tags[0].Name)
3131
assert.EqualValues(t, "36f97d9a96457e2bab511db30fe2db03893ebc64", tags[0].ID.String())
3232
assert.EqualValues(t, "tag", tags[0].Type)

modules/indexer/code/indexer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func testIndexer(name string, t *testing.T, indexer Indexer) {
6969
t.Run(kw.Keyword, func(t *testing.T) {
7070
total, res, langs, err := indexer.Search(context.TODO(), kw.RepoIDs, "", kw.Keyword, 1, 10, false)
7171
assert.NoError(t, err)
72-
assert.EqualValues(t, len(kw.IDs), total)
72+
assert.Len(t, kw.IDs, int(total))
7373
assert.Len(t, langs, kw.Langs)
7474

7575
ids := make([]int64, 0, len(res))

modules/lfs/http_client_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func TestHTTPClientDownload(t *testing.T) {
162162
assert.NoError(t, err)
163163

164164
assert.Equal(t, "download", batchRequest.Operation)
165-
assert.Equal(t, 1, len(batchRequest.Objects))
165+
assert.Len(t, batchRequest.Objects, 1)
166166
assert.Equal(t, p.Oid, batchRequest.Objects[0].Oid)
167167
assert.Equal(t, p.Size, batchRequest.Objects[0].Size)
168168

@@ -269,7 +269,7 @@ func TestHTTPClientUpload(t *testing.T) {
269269
assert.NoError(t, err)
270270

271271
assert.Equal(t, "upload", batchRequest.Operation)
272-
assert.Equal(t, 1, len(batchRequest.Objects))
272+
assert.Len(t, batchRequest.Objects, 1)
273273
assert.Equal(t, p.Oid, batchRequest.Objects[0].Oid)
274274
assert.Equal(t, p.Size, batchRequest.Objects[0].Size)
275275

modules/log/file_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestFileLogger(t *testing.T) {
5151

5252
fileLogger := NewFileLogger()
5353
realFileLogger, ok := fileLogger.(*FileLogger)
54-
assert.Equal(t, true, ok)
54+
assert.True(t, ok)
5555

5656
location, _ := time.LoadLocation("EST")
5757

modules/markup/html_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -593,5 +593,5 @@ func TestIssue18471(t *testing.T) {
593593
}, strings.NewReader(data), &res)
594594

595595
assert.NoError(t, err)
596-
assert.Equal(t, res.String(), "<a href=\"http://domain/org/repo/compare/783b039...da951ce\" class=\"compare\"><code class=\"nohighlight\">783b039...da951ce</code></a>")
596+
assert.Equal(t, "<a href=\"http://domain/org/repo/compare/783b039...da951ce\" class=\"compare\"><code class=\"nohighlight\">783b039...da951ce</code></a>", res.String())
597597
}

modules/packages/container/metadata_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestParseImageConfig(t *testing.T) {
3333
assert.Equal(t, projectURL, metadata.ProjectURL)
3434
assert.Equal(t, repositoryURL, metadata.RepositoryURL)
3535
assert.Equal(t, documentationURL, metadata.DocumentationURL)
36-
assert.Equal(t, []string{"do it 1", "do it 2"}, metadata.ImageLayers)
36+
assert.ElementsMatch(t, []string{"do it 1", "do it 2"}, metadata.ImageLayers)
3737
assert.Equal(
3838
t,
3939
map[string]string{

modules/paginator/paginator_test.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -70,49 +70,49 @@ func TestPaginator(t *testing.T) {
7070
t.Run("Generate pages", func(t *testing.T) {
7171
p := New(0, 10, 1, 0)
7272
pages := p.Pages()
73-
assert.Equal(t, 0, len(pages))
73+
assert.Empty(t, pages)
7474
})
7575

7676
t.Run("Only current page", func(t *testing.T) {
7777
p := New(0, 10, 1, 1)
7878
pages := p.Pages()
79-
assert.Equal(t, 1, len(pages))
79+
assert.Len(t, pages, 1)
8080
assert.Equal(t, 1, pages[0].Num())
8181
assert.True(t, pages[0].IsCurrent())
8282

8383
p = New(1, 10, 1, 1)
8484
pages = p.Pages()
85-
assert.Equal(t, 1, len(pages))
85+
assert.Len(t, pages, 1)
8686
assert.Equal(t, 1, pages[0].Num())
8787
assert.True(t, pages[0].IsCurrent())
8888
})
8989

9090
t.Run("Total page number is less or equal", func(t *testing.T) {
9191
p := New(1, 10, 1, 2)
9292
pages := p.Pages()
93-
assert.Equal(t, 1, len(pages))
93+
assert.Len(t, pages, 1)
9494
assert.Equal(t, 1, pages[0].Num())
9595
assert.True(t, pages[0].IsCurrent())
9696

9797
p = New(11, 10, 1, 2)
9898
pages = p.Pages()
99-
assert.Equal(t, 2, len(pages))
99+
assert.Len(t, pages, 2)
100100
assert.Equal(t, 1, pages[0].Num())
101101
assert.True(t, pages[0].IsCurrent())
102102
assert.Equal(t, 2, pages[1].Num())
103103
assert.False(t, pages[1].IsCurrent())
104104

105105
p = New(11, 10, 2, 2)
106106
pages = p.Pages()
107-
assert.Equal(t, 2, len(pages))
107+
assert.Len(t, pages, 2)
108108
assert.Equal(t, 1, pages[0].Num())
109109
assert.False(t, pages[0].IsCurrent())
110110
assert.Equal(t, 2, pages[1].Num())
111111
assert.True(t, pages[1].IsCurrent())
112112

113113
p = New(25, 10, 2, 3)
114114
pages = p.Pages()
115-
assert.Equal(t, 3, len(pages))
115+
assert.Len(t, pages, 3)
116116
assert.Equal(t, 1, pages[0].Num())
117117
assert.False(t, pages[0].IsCurrent())
118118
assert.Equal(t, 2, pages[1].Num())
@@ -125,7 +125,7 @@ func TestPaginator(t *testing.T) {
125125
// ... 2
126126
p := New(11, 10, 2, 1)
127127
pages := p.Pages()
128-
assert.Equal(t, 2, len(pages))
128+
assert.Len(t, pages, 2)
129129
assert.Equal(t, -1, pages[0].Num())
130130
assert.False(t, pages[0].IsCurrent())
131131
assert.Equal(t, 2, pages[1].Num())
@@ -134,7 +134,7 @@ func TestPaginator(t *testing.T) {
134134
// ... 2 3
135135
p = New(21, 10, 2, 2)
136136
pages = p.Pages()
137-
assert.Equal(t, 3, len(pages))
137+
assert.Len(t, pages, 3)
138138
assert.Equal(t, -1, pages[0].Num())
139139
assert.False(t, pages[0].IsCurrent())
140140
assert.Equal(t, 2, pages[1].Num())
@@ -145,7 +145,7 @@ func TestPaginator(t *testing.T) {
145145
// ... 2 3 4
146146
p = New(31, 10, 3, 3)
147147
pages = p.Pages()
148-
assert.Equal(t, 4, len(pages))
148+
assert.Len(t, pages, 4)
149149
assert.Equal(t, -1, pages[0].Num())
150150
assert.False(t, pages[0].IsCurrent())
151151
assert.Equal(t, 2, pages[1].Num())
@@ -158,7 +158,7 @@ func TestPaginator(t *testing.T) {
158158
// ... 3 4 5
159159
p = New(41, 10, 4, 3)
160160
pages = p.Pages()
161-
assert.Equal(t, 4, len(pages))
161+
assert.Len(t, pages, 4)
162162
assert.Equal(t, -1, pages[0].Num())
163163
assert.False(t, pages[0].IsCurrent())
164164
assert.Equal(t, 3, pages[1].Num())
@@ -171,7 +171,7 @@ func TestPaginator(t *testing.T) {
171171
// ... 4 5 6 7 8 9 10
172172
p = New(100, 10, 9, 7)
173173
pages = p.Pages()
174-
assert.Equal(t, 8, len(pages))
174+
assert.Len(t, pages, 8)
175175
assert.Equal(t, -1, pages[0].Num())
176176
assert.False(t, pages[0].IsCurrent())
177177
assert.Equal(t, 4, pages[1].Num())
@@ -194,7 +194,7 @@ func TestPaginator(t *testing.T) {
194194
// 1 ...
195195
p := New(21, 10, 1, 1)
196196
pages := p.Pages()
197-
assert.Equal(t, 2, len(pages))
197+
assert.Len(t, pages, 2)
198198
assert.Equal(t, 1, pages[0].Num())
199199
assert.True(t, pages[0].IsCurrent())
200200
assert.Equal(t, -1, pages[1].Num())
@@ -203,7 +203,7 @@ func TestPaginator(t *testing.T) {
203203
// 1 2 ...
204204
p = New(21, 10, 1, 2)
205205
pages = p.Pages()
206-
assert.Equal(t, 3, len(pages))
206+
assert.Len(t, pages, 3)
207207
assert.Equal(t, 1, pages[0].Num())
208208
assert.True(t, pages[0].IsCurrent())
209209
assert.Equal(t, 2, pages[1].Num())
@@ -214,7 +214,7 @@ func TestPaginator(t *testing.T) {
214214
// 1 2 3 ...
215215
p = New(31, 10, 2, 3)
216216
pages = p.Pages()
217-
assert.Equal(t, 4, len(pages))
217+
assert.Len(t, pages, 4)
218218
assert.Equal(t, 1, pages[0].Num())
219219
assert.False(t, pages[0].IsCurrent())
220220
assert.Equal(t, 2, pages[1].Num())
@@ -227,7 +227,7 @@ func TestPaginator(t *testing.T) {
227227
// 1 2 3 ...
228228
p = New(41, 10, 2, 3)
229229
pages = p.Pages()
230-
assert.Equal(t, 4, len(pages))
230+
assert.Len(t, pages, 4)
231231
assert.Equal(t, 1, pages[0].Num())
232232
assert.False(t, pages[0].IsCurrent())
233233
assert.Equal(t, 2, pages[1].Num())
@@ -240,7 +240,7 @@ func TestPaginator(t *testing.T) {
240240
// 1 2 3 4 5 6 7 ...
241241
p = New(100, 10, 1, 7)
242242
pages = p.Pages()
243-
assert.Equal(t, 8, len(pages))
243+
assert.Len(t, pages, 8)
244244
assert.Equal(t, 1, pages[0].Num())
245245
assert.True(t, pages[0].IsCurrent())
246246
assert.Equal(t, 2, pages[1].Num())
@@ -261,7 +261,7 @@ func TestPaginator(t *testing.T) {
261261
// 1 2 3 4 5 6 7 ...
262262
p = New(100, 10, 2, 7)
263263
pages = p.Pages()
264-
assert.Equal(t, 8, len(pages))
264+
assert.Len(t, pages, 8)
265265
assert.Equal(t, 1, pages[0].Num())
266266
assert.False(t, pages[0].IsCurrent())
267267
assert.Equal(t, 2, pages[1].Num())
@@ -284,7 +284,7 @@ func TestPaginator(t *testing.T) {
284284
// ... 2 3 ...
285285
p := New(35, 10, 2, 2)
286286
pages := p.Pages()
287-
assert.Equal(t, 4, len(pages))
287+
assert.Len(t, pages, 4)
288288
assert.Equal(t, -1, pages[0].Num())
289289
assert.False(t, pages[0].IsCurrent())
290290
assert.Equal(t, 2, pages[1].Num())
@@ -297,7 +297,7 @@ func TestPaginator(t *testing.T) {
297297
// ... 2 3 4 ...
298298
p = New(49, 10, 3, 3)
299299
pages = p.Pages()
300-
assert.Equal(t, 5, len(pages))
300+
assert.Len(t, pages, 5)
301301
assert.Equal(t, -1, pages[0].Num())
302302
assert.False(t, pages[0].IsCurrent())
303303
assert.Equal(t, 2, pages[1].Num())

modules/queue/unique_queue_disk_channel_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func TestPersistableChannelUniqueQueue(t *testing.T) {
208208

209209
mapLock.Lock()
210210
assert.Equal(t, 101, len(executedInitial[name])+len(executedEmpty[name]))
211-
assert.Equal(t, 0, len(hasEmpty[name]))
211+
assert.Empty(t, hasEmpty[name])
212212
mapLock.Unlock()
213213
})
214214
close(done)

modules/secret/secret_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ func TestEncryptDecrypt(t *testing.T) {
1515

1616
hex, _ = EncryptSecret("foo", "baz")
1717
str, _ = DecryptSecret("foo", hex)
18-
assert.Equal(t, str, "baz")
18+
assert.Equal(t, "baz", str)
1919

2020
hex, _ = EncryptSecret("bar", "baz")
2121
str, _ = DecryptSecret("foo", hex)
22-
assert.NotEqual(t, str, "baz")
22+
assert.NotEqual(t, "baz", str)
2323
}

modules/storage/local_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ func TestLocalStorageIterator(t *testing.T) {
8989
return nil
9090
})
9191
assert.NoError(t, err)
92-
assert.Equal(t, count, len(expected))
92+
assert.Len(t, expected, count)
9393
}
9494
}

0 commit comments

Comments
 (0)