Use more specific test methods (#24265)

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
KN4CK3R 2023-04-22 23:56:27 +02:00 committed by GitHub
parent ac384c4e1d
commit f1173d6879
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 117 additions and 117 deletions

View File

@ -67,7 +67,7 @@ func TestMigratePackages(t *testing.T) {
entries, err := os.ReadDir(p)
assert.NoError(t, err)
assert.EqualValues(t, 2, len(entries))
assert.Len(t, entries, 2)
assert.EqualValues(t, "01", entries[0].Name())
assert.EqualValues(t, "tmp", entries[1].Name())
}

View File

@ -40,7 +40,7 @@ func TestFind(t *testing.T) {
var repoUnits []repo_model.RepoUnit
err = db.Find(db.DefaultContext, &opts, &repoUnits)
assert.NoError(t, err)
assert.EqualValues(t, repoUnitCount, len(repoUnits))
assert.Len(t, repoUnits, repoUnitCount)
cnt, err := db.Count(db.DefaultContext, &opts, new(repo_model.RepoUnit))
assert.NoError(t, err)

View File

@ -88,12 +88,12 @@ func TestFindRenamedBranch(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
branch, exist, err := git_model.FindRenamedBranch(db.DefaultContext, 1, "dev")
assert.NoError(t, err)
assert.Equal(t, true, exist)
assert.True(t, exist)
assert.Equal(t, "master", branch.To)
_, exist, err = git_model.FindRenamedBranch(db.DefaultContext, 1, "unknow")
assert.NoError(t, err)
assert.Equal(t, false, exist)
assert.False(t, exist)
}
func TestRenameBranch(t *testing.T) {
@ -115,7 +115,7 @@ func TestRenameBranch(t *testing.T) {
return nil
}))
assert.Equal(t, true, _isDefault)
assert.True(t, _isDefault)
repo1 = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
assert.Equal(t, "main", repo1.DefaultBranch)

View File

@ -109,11 +109,11 @@ func TestHasUnmergedPullRequestsByHeadInfo(t *testing.T) {
exist, err := issues_model.HasUnmergedPullRequestsByHeadInfo(db.DefaultContext, 1, "branch2")
assert.NoError(t, err)
assert.Equal(t, true, exist)
assert.True(t, exist)
exist, err = issues_model.HasUnmergedPullRequestsByHeadInfo(db.DefaultContext, 1, "not_exist_branch")
assert.NoError(t, err)
assert.Equal(t, false, exist)
assert.False(t, exist)
}
func TestGetUnmergedPullRequestsByHeadInfo(t *testing.T) {

View File

@ -35,7 +35,7 @@ func TestAddTime(t *testing.T) {
assert.Equal(t, int64(3661), tt.Time)
comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{Type: issues_model.CommentTypeAddTimeManual, PosterID: 3, IssueID: 1})
assert.Equal(t, comment.Content, "1 hour 1 minute")
assert.Equal(t, "1 hour 1 minute", comment.Content)
}
func TestGetTrackedTimes(t *testing.T) {

View File

@ -152,7 +152,7 @@ func init() {
Query()
assert.NoError(t, err)
assert.EqualValues(t, label.int("NumIssues"), len(issueLabels), "Unexpected number of issue for label id: %d", label.int("ID"))
assert.Len(t, issueLabels, label.int("NumIssues"), "Unexpected number of issue for label id: %d", label.int("ID"))
issueIDs := make([]int, len(issueLabels))
for i, issueLabel := range issueLabels {

View File

@ -36,10 +36,10 @@ func TestGetUserEmailsByNames(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
// ignore none active user email
assert.Equal(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user9"}))
assert.Equal(t, []string{"user8@example.com", "user5@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user5"}))
assert.ElementsMatch(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user9"}))
assert.ElementsMatch(t, []string{"user8@example.com", "user5@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user5"}))
assert.Equal(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user7"}))
assert.ElementsMatch(t, []string{"user8@example.com"}, user_model.GetUserEmailsByNames(db.DefaultContext, []string{"user8", "user7"}))
}
func TestCanCreateOrganization(t *testing.T) {

View File

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

View File

@ -97,6 +97,6 @@ func TestRepository_CommitsBetweenIDs(t *testing.T) {
for i, c := range cases {
commits, err := bareRepo1.CommitsBetweenIDs(c.NewID, c.OldID)
assert.NoError(t, err)
assert.Equal(t, c.ExpectedCommits, len(commits), "case %d", i)
assert.Len(t, commits, c.ExpectedCommits, "case %d", i)
}
}

View File

@ -26,7 +26,7 @@ func TestRepository_GetTags(t *testing.T) {
return
}
assert.Len(t, tags, 2)
assert.Equal(t, len(tags), total)
assert.Len(t, tags, total)
assert.EqualValues(t, "signed-tag", tags[0].Name)
assert.EqualValues(t, "36f97d9a96457e2bab511db30fe2db03893ebc64", tags[0].ID.String())
assert.EqualValues(t, "tag", tags[0].Type)

View File

@ -69,7 +69,7 @@ func testIndexer(name string, t *testing.T, indexer Indexer) {
t.Run(kw.Keyword, func(t *testing.T) {
total, res, langs, err := indexer.Search(context.TODO(), kw.RepoIDs, "", kw.Keyword, 1, 10, false)
assert.NoError(t, err)
assert.EqualValues(t, len(kw.IDs), total)
assert.Len(t, kw.IDs, int(total))
assert.Len(t, langs, kw.Langs)
ids := make([]int64, 0, len(res))

View File

@ -162,7 +162,7 @@ func TestHTTPClientDownload(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "download", batchRequest.Operation)
assert.Equal(t, 1, len(batchRequest.Objects))
assert.Len(t, batchRequest.Objects, 1)
assert.Equal(t, p.Oid, batchRequest.Objects[0].Oid)
assert.Equal(t, p.Size, batchRequest.Objects[0].Size)
@ -269,7 +269,7 @@ func TestHTTPClientUpload(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "upload", batchRequest.Operation)
assert.Equal(t, 1, len(batchRequest.Objects))
assert.Len(t, batchRequest.Objects, 1)
assert.Equal(t, p.Oid, batchRequest.Objects[0].Oid)
assert.Equal(t, p.Size, batchRequest.Objects[0].Size)

View File

@ -51,7 +51,7 @@ func TestFileLogger(t *testing.T) {
fileLogger := NewFileLogger()
realFileLogger, ok := fileLogger.(*FileLogger)
assert.Equal(t, true, ok)
assert.True(t, ok)
location, _ := time.LoadLocation("EST")

View File

@ -593,5 +593,5 @@ func TestIssue18471(t *testing.T) {
}, strings.NewReader(data), &res)
assert.NoError(t, err)
assert.Equal(t, res.String(), "<a href=\"http://domain/org/repo/compare/783b039...da951ce\" class=\"compare\"><code class=\"nohighlight\">783b039...da951ce</code></a>")
assert.Equal(t, "<a href=\"http://domain/org/repo/compare/783b039...da951ce\" class=\"compare\"><code class=\"nohighlight\">783b039...da951ce</code></a>", res.String())
}

View File

@ -33,7 +33,7 @@ func TestParseImageConfig(t *testing.T) {
assert.Equal(t, projectURL, metadata.ProjectURL)
assert.Equal(t, repositoryURL, metadata.RepositoryURL)
assert.Equal(t, documentationURL, metadata.DocumentationURL)
assert.Equal(t, []string{"do it 1", "do it 2"}, metadata.ImageLayers)
assert.ElementsMatch(t, []string{"do it 1", "do it 2"}, metadata.ImageLayers)
assert.Equal(
t,
map[string]string{

View File

@ -70,19 +70,19 @@ func TestPaginator(t *testing.T) {
t.Run("Generate pages", func(t *testing.T) {
p := New(0, 10, 1, 0)
pages := p.Pages()
assert.Equal(t, 0, len(pages))
assert.Empty(t, pages)
})
t.Run("Only current page", func(t *testing.T) {
p := New(0, 10, 1, 1)
pages := p.Pages()
assert.Equal(t, 1, len(pages))
assert.Len(t, pages, 1)
assert.Equal(t, 1, pages[0].Num())
assert.True(t, pages[0].IsCurrent())
p = New(1, 10, 1, 1)
pages = p.Pages()
assert.Equal(t, 1, len(pages))
assert.Len(t, pages, 1)
assert.Equal(t, 1, pages[0].Num())
assert.True(t, pages[0].IsCurrent())
})
@ -90,13 +90,13 @@ func TestPaginator(t *testing.T) {
t.Run("Total page number is less or equal", func(t *testing.T) {
p := New(1, 10, 1, 2)
pages := p.Pages()
assert.Equal(t, 1, len(pages))
assert.Len(t, pages, 1)
assert.Equal(t, 1, pages[0].Num())
assert.True(t, pages[0].IsCurrent())
p = New(11, 10, 1, 2)
pages = p.Pages()
assert.Equal(t, 2, len(pages))
assert.Len(t, pages, 2)
assert.Equal(t, 1, pages[0].Num())
assert.True(t, pages[0].IsCurrent())
assert.Equal(t, 2, pages[1].Num())
@ -104,7 +104,7 @@ func TestPaginator(t *testing.T) {
p = New(11, 10, 2, 2)
pages = p.Pages()
assert.Equal(t, 2, len(pages))
assert.Len(t, pages, 2)
assert.Equal(t, 1, pages[0].Num())
assert.False(t, pages[0].IsCurrent())
assert.Equal(t, 2, pages[1].Num())
@ -112,7 +112,7 @@ func TestPaginator(t *testing.T) {
p = New(25, 10, 2, 3)
pages = p.Pages()
assert.Equal(t, 3, len(pages))
assert.Len(t, pages, 3)
assert.Equal(t, 1, pages[0].Num())
assert.False(t, pages[0].IsCurrent())
assert.Equal(t, 2, pages[1].Num())
@ -125,7 +125,7 @@ func TestPaginator(t *testing.T) {
// ... 2
p := New(11, 10, 2, 1)
pages := p.Pages()
assert.Equal(t, 2, len(pages))
assert.Len(t, pages, 2)
assert.Equal(t, -1, pages[0].Num())
assert.False(t, pages[0].IsCurrent())
assert.Equal(t, 2, pages[1].Num())
@ -134,7 +134,7 @@ func TestPaginator(t *testing.T) {
// ... 2 3
p = New(21, 10, 2, 2)
pages = p.Pages()
assert.Equal(t, 3, len(pages))
assert.Len(t, pages, 3)
assert.Equal(t, -1, pages[0].Num())
assert.False(t, pages[0].IsCurrent())
assert.Equal(t, 2, pages[1].Num())
@ -145,7 +145,7 @@ func TestPaginator(t *testing.T) {
// ... 2 3 4
p = New(31, 10, 3, 3)
pages = p.Pages()
assert.Equal(t, 4, len(pages))
assert.Len(t, pages, 4)
assert.Equal(t, -1, pages[0].Num())
assert.False(t, pages[0].IsCurrent())
assert.Equal(t, 2, pages[1].Num())
@ -158,7 +158,7 @@ func TestPaginator(t *testing.T) {
// ... 3 4 5
p = New(41, 10, 4, 3)
pages = p.Pages()
assert.Equal(t, 4, len(pages))
assert.Len(t, pages, 4)
assert.Equal(t, -1, pages[0].Num())
assert.False(t, pages[0].IsCurrent())
assert.Equal(t, 3, pages[1].Num())
@ -171,7 +171,7 @@ func TestPaginator(t *testing.T) {
// ... 4 5 6 7 8 9 10
p = New(100, 10, 9, 7)
pages = p.Pages()
assert.Equal(t, 8, len(pages))
assert.Len(t, pages, 8)
assert.Equal(t, -1, pages[0].Num())
assert.False(t, pages[0].IsCurrent())
assert.Equal(t, 4, pages[1].Num())
@ -194,7 +194,7 @@ func TestPaginator(t *testing.T) {
// 1 ...
p := New(21, 10, 1, 1)
pages := p.Pages()
assert.Equal(t, 2, len(pages))
assert.Len(t, pages, 2)
assert.Equal(t, 1, pages[0].Num())
assert.True(t, pages[0].IsCurrent())
assert.Equal(t, -1, pages[1].Num())
@ -203,7 +203,7 @@ func TestPaginator(t *testing.T) {
// 1 2 ...
p = New(21, 10, 1, 2)
pages = p.Pages()
assert.Equal(t, 3, len(pages))
assert.Len(t, pages, 3)
assert.Equal(t, 1, pages[0].Num())
assert.True(t, pages[0].IsCurrent())
assert.Equal(t, 2, pages[1].Num())
@ -214,7 +214,7 @@ func TestPaginator(t *testing.T) {
// 1 2 3 ...
p = New(31, 10, 2, 3)
pages = p.Pages()
assert.Equal(t, 4, len(pages))
assert.Len(t, pages, 4)
assert.Equal(t, 1, pages[0].Num())
assert.False(t, pages[0].IsCurrent())
assert.Equal(t, 2, pages[1].Num())
@ -227,7 +227,7 @@ func TestPaginator(t *testing.T) {
// 1 2 3 ...
p = New(41, 10, 2, 3)
pages = p.Pages()
assert.Equal(t, 4, len(pages))
assert.Len(t, pages, 4)
assert.Equal(t, 1, pages[0].Num())
assert.False(t, pages[0].IsCurrent())
assert.Equal(t, 2, pages[1].Num())
@ -240,7 +240,7 @@ func TestPaginator(t *testing.T) {
// 1 2 3 4 5 6 7 ...
p = New(100, 10, 1, 7)
pages = p.Pages()
assert.Equal(t, 8, len(pages))
assert.Len(t, pages, 8)
assert.Equal(t, 1, pages[0].Num())
assert.True(t, pages[0].IsCurrent())
assert.Equal(t, 2, pages[1].Num())
@ -261,7 +261,7 @@ func TestPaginator(t *testing.T) {
// 1 2 3 4 5 6 7 ...
p = New(100, 10, 2, 7)
pages = p.Pages()
assert.Equal(t, 8, len(pages))
assert.Len(t, pages, 8)
assert.Equal(t, 1, pages[0].Num())
assert.False(t, pages[0].IsCurrent())
assert.Equal(t, 2, pages[1].Num())
@ -284,7 +284,7 @@ func TestPaginator(t *testing.T) {
// ... 2 3 ...
p := New(35, 10, 2, 2)
pages := p.Pages()
assert.Equal(t, 4, len(pages))
assert.Len(t, pages, 4)
assert.Equal(t, -1, pages[0].Num())
assert.False(t, pages[0].IsCurrent())
assert.Equal(t, 2, pages[1].Num())
@ -297,7 +297,7 @@ func TestPaginator(t *testing.T) {
// ... 2 3 4 ...
p = New(49, 10, 3, 3)
pages = p.Pages()
assert.Equal(t, 5, len(pages))
assert.Len(t, pages, 5)
assert.Equal(t, -1, pages[0].Num())
assert.False(t, pages[0].IsCurrent())
assert.Equal(t, 2, pages[1].Num())

View File

@ -208,7 +208,7 @@ func TestPersistableChannelUniqueQueue(t *testing.T) {
mapLock.Lock()
assert.Equal(t, 101, len(executedInitial[name])+len(executedEmpty[name]))
assert.Equal(t, 0, len(hasEmpty[name]))
assert.Empty(t, hasEmpty[name])
mapLock.Unlock()
})
close(done)

View File

@ -15,9 +15,9 @@ func TestEncryptDecrypt(t *testing.T) {
hex, _ = EncryptSecret("foo", "baz")
str, _ = DecryptSecret("foo", hex)
assert.Equal(t, str, "baz")
assert.Equal(t, "baz", str)
hex, _ = EncryptSecret("bar", "baz")
str, _ = DecryptSecret("foo", hex)
assert.NotEqual(t, str, "baz")
assert.NotEqual(t, "baz", str)
}

View File

@ -89,6 +89,6 @@ func TestLocalStorageIterator(t *testing.T) {
return nil
})
assert.NoError(t, err)
assert.Equal(t, count, len(expected))
assert.Len(t, expected, count)
}
}

View File

@ -22,26 +22,26 @@ func TestLogChecker(t *testing.T) {
log.Info("test")
filtered, stopped := lc.Check(100 * time.Millisecond)
assert.EqualValues(t, []bool{false, false}, filtered)
assert.EqualValues(t, false, stopped)
assert.ElementsMatch(t, []bool{false, false}, filtered)
assert.False(t, stopped)
log.Info("First")
filtered, stopped = lc.Check(100 * time.Millisecond)
assert.EqualValues(t, []bool{true, false}, filtered)
assert.EqualValues(t, false, stopped)
assert.ElementsMatch(t, []bool{true, false}, filtered)
assert.False(t, stopped)
log.Info("Second")
filtered, stopped = lc.Check(100 * time.Millisecond)
assert.EqualValues(t, []bool{true, false}, filtered)
assert.EqualValues(t, false, stopped)
assert.ElementsMatch(t, []bool{true, false}, filtered)
assert.False(t, stopped)
log.Info("Third")
filtered, stopped = lc.Check(100 * time.Millisecond)
assert.EqualValues(t, []bool{true, true}, filtered)
assert.EqualValues(t, false, stopped)
assert.ElementsMatch(t, []bool{true, true}, filtered)
assert.False(t, stopped)
log.Info("End")
filtered, stopped = lc.Check(100 * time.Millisecond)
assert.EqualValues(t, []bool{true, true}, filtered)
assert.EqualValues(t, true, stopped)
assert.ElementsMatch(t, []bool{true, true}, filtered)
assert.True(t, stopped)
}

View File

@ -51,8 +51,8 @@ sub = Changed Sub String
assert.Equal(t, `test value; <span style="color: red; background: none;">more text</span>`, result)
langs, descs := ls.ListLangNameDesc()
assert.Equal(t, []string{"lang1", "lang2"}, langs)
assert.Equal(t, []string{"Lang1", "Lang2"}, descs)
assert.ElementsMatch(t, []string{"lang1", "lang2"}, langs)
assert.ElementsMatch(t, []string{"Lang1", "Lang2"}, descs)
found := ls.Has("lang1", "no-such")
assert.False(t, found)

View File

@ -74,15 +74,15 @@ func TestSliceEqual(t *testing.T) {
}
func TestSliceRemoveAll(t *testing.T) {
assert.Equal(t, SliceRemoveAll([]int{2, 0, 2, 3}, 0), []int{2, 2, 3})
assert.Equal(t, SliceRemoveAll([]int{2, 0, 2, 3}, 2), []int{0, 3})
assert.Equal(t, SliceRemoveAll([]int{0, 0, 0, 0}, 0), []int{})
assert.Equal(t, SliceRemoveAll([]int{2, 0, 2, 3}, 4), []int{2, 0, 2, 3})
assert.Equal(t, SliceRemoveAll([]int{}, 0), []int{})
assert.Equal(t, SliceRemoveAll([]int(nil), 0), []int(nil))
assert.Equal(t, SliceRemoveAll([]int{}, 0), []int{})
assert.ElementsMatch(t, []int{2, 2, 3}, SliceRemoveAll([]int{2, 0, 2, 3}, 0))
assert.ElementsMatch(t, []int{0, 3}, SliceRemoveAll([]int{2, 0, 2, 3}, 2))
assert.Empty(t, SliceRemoveAll([]int{0, 0, 0, 0}, 0))
assert.ElementsMatch(t, []int{2, 0, 2, 3}, SliceRemoveAll([]int{2, 0, 2, 3}, 4))
assert.Empty(t, SliceRemoveAll([]int{}, 0))
assert.ElementsMatch(t, []int(nil), SliceRemoveAll([]int(nil), 0))
assert.Empty(t, SliceRemoveAll([]int{}, 0))
assert.Equal(t, SliceRemoveAll([]string{"2", "0", "2", "3"}, "0"), []string{"2", "2", "3"})
assert.Equal(t, SliceRemoveAll([]float64{2, 0, 2, 3}, 0), []float64{2, 2, 3})
assert.Equal(t, SliceRemoveAll([]bool{false, true, false}, true), []bool{false, false})
assert.ElementsMatch(t, []string{"2", "2", "3"}, SliceRemoveAll([]string{"2", "0", "2", "3"}, "0"))
assert.ElementsMatch(t, []float64{2, 2, 3}, SliceRemoveAll([]float64{2, 0, 2, 3}, 0))
assert.ElementsMatch(t, []bool{false, false}, SliceRemoveAll([]bool{false, true, false}, true))
}

View File

@ -25,7 +25,7 @@ func TestSplitString(t *testing.T) {
assert.Equal(t, c.ellipsis+c.input[len(c.leftSub):], r, "test split %s at %d, expected rightSub: %q", c.input, c.n, c.input[len(c.leftSub):])
} else {
assert.Equal(t, c.leftSub, l, "test split %q at %d, expected leftSub: %q", c.input, c.n, c.leftSub)
assert.Equal(t, "", r, "test split %q at %d, expected rightSub: %q", c.input, c.n, "")
assert.Empty(t, r, "test split %q at %d, expected rightSub: %q", c.input, c.n, "")
}
}
}

View File

@ -20,7 +20,7 @@ func TestDeleteNotPassedAssignee(t *testing.T) {
// Fake issue with assignees
issue, err := issues_model.GetIssueWithAttrsByID(1)
assert.NoError(t, err)
assert.EqualValues(t, 1, len(issue.Assignees))
assert.Len(t, issue.Assignees, 1)
user1, err := user_model.GetUserByID(db.DefaultContext, 1) // This user is already assigned (see the definition in fixtures), so running UpdateAssignee should unassign him
assert.NoError(t, err)
@ -33,10 +33,10 @@ func TestDeleteNotPassedAssignee(t *testing.T) {
// Clean everyone
err = DeleteNotPassedAssignee(db.DefaultContext, issue, user1, []*user_model.User{})
assert.NoError(t, err)
assert.EqualValues(t, 0, len(issue.Assignees))
assert.Empty(t, issue.Assignees)
// Check they're gone
assert.NoError(t, issue.LoadAssignees(db.DefaultContext))
assert.EqualValues(t, 0, len(issue.Assignees))
assert.Empty(t, issue.Assignees)
assert.Empty(t, issue.Assignee)
}

View File

@ -37,7 +37,7 @@ func TestIssue_DeleteIssue(t *testing.T) {
issueIDs, err := issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1)
assert.NoError(t, err)
assert.EqualValues(t, 5, len(issueIDs))
assert.Len(t, issueIDs, 5)
issue := &issues_model.Issue{
RepoID: 1,
@ -48,7 +48,7 @@ func TestIssue_DeleteIssue(t *testing.T) {
assert.NoError(t, err)
issueIDs, err = issues_model.GetIssueIDsByRepoID(db.DefaultContext, 1)
assert.NoError(t, err)
assert.EqualValues(t, 4, len(issueIDs))
assert.Len(t, issueIDs, 4)
// check attachment removal
attachments, err := repo_model.GetAttachmentsByIssueID(db.DefaultContext, 4)
@ -57,7 +57,7 @@ func TestIssue_DeleteIssue(t *testing.T) {
assert.NoError(t, err)
err = deleteIssue(db.DefaultContext, issue)
assert.NoError(t, err)
assert.EqualValues(t, 2, len(attachments))
assert.Len(t, attachments, 2)
for i := range attachments {
attachment, err := repo_model.GetAttachmentByUUID(db.DefaultContext, attachments[i].UUID)
assert.Error(t, err)

View File

@ -30,7 +30,7 @@ func TestCheckUnadoptedRepositories_Add(t *testing.T) {
}
assert.Equal(t, total, unadopted.index)
assert.Equal(t, end-start, len(unadopted.repositories))
assert.Len(t, unadopted.repositories, end-start)
}
func TestCheckUnadoptedRepositories(t *testing.T) {
@ -41,7 +41,7 @@ func TestCheckUnadoptedRepositories(t *testing.T) {
unadopted := &unadoptedRepositories{start: 0, end: 100}
err := checkUnadoptedRepositories(db.DefaultContext, "notauser", []string{"repo"}, unadopted)
assert.NoError(t, err)
assert.Equal(t, 0, len(unadopted.repositories))
assert.Empty(t, unadopted.repositories)
//
// Unadopted repository is returned
// Existing (adopted) repository is not returned
@ -59,7 +59,7 @@ func TestCheckUnadoptedRepositories(t *testing.T) {
unadopted = &unadoptedRepositories{start: 0, end: 100}
err = checkUnadoptedRepositories(db.DefaultContext, userName, []string{repoName}, unadopted)
assert.NoError(t, err)
assert.Equal(t, 0, len(unadopted.repositories))
assert.Empty(t, unadopted.repositories)
assert.Equal(t, 0, unadopted.index)
}

View File

@ -123,7 +123,7 @@ func TestAPIListUsers(t *testing.T) {
}
assert.True(t, found)
numberOfUsers := unittest.GetCount(t, &user_model.User{}, "type = 0")
assert.Equal(t, numberOfUsers, len(users))
assert.Len(t, users, numberOfUsers)
}
func TestAPIListUsersNotLoggedIn(t *testing.T) {

View File

@ -68,7 +68,7 @@ func TestAPIListCommentAttachments(t *testing.T) {
var apiAttachments []*api.Attachment
DecodeJSON(t, resp, &apiAttachments)
expectedCount := unittest.GetCount(t, &repo_model.Attachment{CommentID: comment.ID})
assert.EqualValues(t, expectedCount, len(apiAttachments))
assert.Len(t, apiAttachments, expectedCount)
unittest.AssertExistsAndLoadBean(t, &repo_model.Attachment{ID: apiAttachments[0].ID, CommentID: comment.ID})
}

View File

@ -85,7 +85,7 @@ func TestAPIListIssueComments(t *testing.T) {
DecodeJSON(t, resp, &comments)
expectedCount := unittest.GetCount(t, &issues_model.Comment{IssueID: issue.ID},
unittest.Cond("type = ?", issues_model.CommentTypeComment))
assert.EqualValues(t, expectedCount, len(comments))
assert.Len(t, comments, expectedCount)
}
func TestAPICreateComment(t *testing.T) {
@ -196,5 +196,5 @@ func TestAPIListIssueTimeline(t *testing.T) {
var comments []*api.TimelineComment
DecodeJSON(t, resp, &comments)
expectedCount := unittest.GetCount(t, &issues_model.Comment{IssueID: issue.ID})
assert.EqualValues(t, expectedCount, len(comments))
assert.Len(t, comments, expectedCount)
}

View File

@ -48,5 +48,5 @@ func TestAPIReposValidateDefaultIssueConfig(t *testing.T) {
DecodeJSON(t, resp, &issueConfigValidation)
assert.True(t, issueConfigValidation.Valid)
assert.Equal(t, issueConfigValidation.Message, "")
assert.Empty(t, issueConfigValidation.Message)
}

Some files were not shown because too many files have changed in this diff Show More