aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
Diffstat (limited to 'services')
-rw-r--r--services/actions/auth_test.go12
-rw-r--r--services/auth/oauth2_test.go2
-rw-r--r--services/auth/source/oauth2/source_sync_test.go8
-rw-r--r--services/convert/pull_review_test.go2
-rw-r--r--services/cron/tasks_test.go2
-rw-r--r--services/feed/feed_test.go6
-rw-r--r--services/gitdiff/gitdiff_test.go5
-rw-r--r--services/migrations/gitlab_test.go2
-rw-r--r--services/org/team_test.go2
-rw-r--r--services/pull/reviewer_test.go4
-rw-r--r--services/release/release_test.go2
-rw-r--r--services/repository/archiver/archiver_test.go5
-rw-r--r--services/repository/license_test.go2
-rw-r--r--services/repository/transfer_test.go2
-rw-r--r--services/webhook/packagist_test.go30
-rw-r--r--services/webhook/webhook_test.go4
16 files changed, 44 insertions, 46 deletions
diff --git a/services/actions/auth_test.go b/services/actions/auth_test.go
index 12db2bae56..85e7409105 100644
--- a/services/actions/auth_test.go
+++ b/services/actions/auth_test.go
@@ -17,19 +17,19 @@ import (
func TestCreateAuthorizationToken(t *testing.T) {
var taskID int64 = 23
token, err := CreateAuthorizationToken(taskID, 1, 2)
- assert.Nil(t, err)
+ assert.NoError(t, err)
assert.NotEqual(t, "", token)
claims := jwt.MapClaims{}
_, err = jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (any, error) {
return setting.GetGeneralTokenSigningSecret(), nil
})
- assert.Nil(t, err)
+ assert.NoError(t, err)
scp, ok := claims["scp"]
assert.True(t, ok, "Has scp claim in jwt token")
assert.Contains(t, scp, "Actions.Results:1:2")
taskIDClaim, ok := claims["TaskID"]
assert.True(t, ok, "Has TaskID claim in jwt token")
- assert.Equal(t, float64(taskID), taskIDClaim, "Supplied taskid must match stored one")
+ assert.InDelta(t, float64(taskID), taskIDClaim, 0, "Supplied taskid must match stored one")
acClaim, ok := claims["ac"]
assert.True(t, ok, "Has ac claim in jwt token")
ac, ok := acClaim.(string)
@@ -43,14 +43,14 @@ func TestCreateAuthorizationToken(t *testing.T) {
func TestParseAuthorizationToken(t *testing.T) {
var taskID int64 = 23
token, err := CreateAuthorizationToken(taskID, 1, 2)
- assert.Nil(t, err)
+ assert.NoError(t, err)
assert.NotEqual(t, "", token)
headers := http.Header{}
headers.Set("Authorization", "Bearer "+token)
rTaskID, err := ParseAuthorizationToken(&http.Request{
Header: headers,
})
- assert.Nil(t, err)
+ assert.NoError(t, err)
assert.Equal(t, taskID, rTaskID)
}
@@ -59,6 +59,6 @@ func TestParseAuthorizationTokenNoAuthHeader(t *testing.T) {
rTaskID, err := ParseAuthorizationToken(&http.Request{
Header: headers,
})
- assert.Nil(t, err)
+ assert.NoError(t, err)
assert.Equal(t, int64(0), rTaskID)
}
diff --git a/services/auth/oauth2_test.go b/services/auth/oauth2_test.go
index 75c231ff7a..b706847e8e 100644
--- a/services/auth/oauth2_test.go
+++ b/services/auth/oauth2_test.go
@@ -28,7 +28,7 @@ func TestUserIDFromToken(t *testing.T) {
o := OAuth2{}
uid := o.userIDFromToken(context.Background(), token, ds)
assert.Equal(t, int64(user_model.ActionsUserID), uid)
- assert.Equal(t, ds["IsActionsToken"], true)
+ assert.Equal(t, true, ds["IsActionsToken"])
assert.Equal(t, ds["ActionsTaskID"], int64(RunningTaskID))
})
}
diff --git a/services/auth/source/oauth2/source_sync_test.go b/services/auth/source/oauth2/source_sync_test.go
index 25408e8727..893ed62502 100644
--- a/services/auth/source/oauth2/source_sync_test.go
+++ b/services/auth/source/oauth2/source_sync_test.go
@@ -64,8 +64,8 @@ func TestSource(t *testing.T) {
ok, err := user_model.GetExternalLogin(context.Background(), e)
assert.NoError(t, err)
assert.True(t, ok)
- assert.Equal(t, e.RefreshToken, "refresh")
- assert.Equal(t, e.AccessToken, "token")
+ assert.Equal(t, "refresh", e.RefreshToken)
+ assert.Equal(t, "token", e.AccessToken)
u, err := user_model.GetUserByID(context.Background(), user.ID)
assert.NoError(t, err)
@@ -89,8 +89,8 @@ func TestSource(t *testing.T) {
ok, err := user_model.GetExternalLogin(context.Background(), e)
assert.NoError(t, err)
assert.True(t, ok)
- assert.Equal(t, e.RefreshToken, "")
- assert.Equal(t, e.AccessToken, "")
+ assert.Equal(t, "", e.RefreshToken)
+ assert.Equal(t, "", e.AccessToken)
u, err := user_model.GetUserByID(context.Background(), user.ID)
assert.NoError(t, err)
diff --git a/services/convert/pull_review_test.go b/services/convert/pull_review_test.go
index 6886950280..a1296fafd4 100644
--- a/services/convert/pull_review_test.go
+++ b/services/convert/pull_review_test.go
@@ -40,7 +40,7 @@ func Test_ToPullReview(t *testing.T) {
user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
prList, err := ToPullReviewList(db.DefaultContext, reviewList, user4)
assert.NoError(t, err)
- assert.Len(t, prList, 0)
+ assert.Empty(t, prList)
})
t.Run("Admin User", func(t *testing.T) {
diff --git a/services/cron/tasks_test.go b/services/cron/tasks_test.go
index 979371a022..ab22403ede 100644
--- a/services/cron/tasks_test.go
+++ b/services/cron/tasks_test.go
@@ -12,7 +12,7 @@ import (
)
func TestAddTaskToScheduler(t *testing.T) {
- assert.Len(t, scheduler.Jobs(), 0)
+ assert.Empty(t, scheduler.Jobs())
defer scheduler.Clear()
// no seconds
diff --git a/services/feed/feed_test.go b/services/feed/feed_test.go
index 6f1cb9a969..1e4d029e18 100644
--- a/services/feed/feed_test.go
+++ b/services/feed/feed_test.go
@@ -41,7 +41,7 @@ func TestGetFeeds(t *testing.T) {
OnlyPerformedBy: false,
})
assert.NoError(t, err)
- assert.Len(t, actions, 0)
+ assert.Empty(t, actions)
assert.Equal(t, int64(0), count)
}
@@ -57,7 +57,7 @@ func TestGetFeedsForRepos(t *testing.T) {
IncludePrivate: true,
})
assert.NoError(t, err)
- assert.Len(t, actions, 0)
+ assert.Empty(t, actions)
assert.Equal(t, int64(0), count)
// public repo & no login
@@ -119,7 +119,7 @@ func TestGetFeeds2(t *testing.T) {
IncludeDeleted: true,
})
assert.NoError(t, err)
- assert.Len(t, actions, 0)
+ assert.Empty(t, actions)
assert.Equal(t, int64(0), count)
}
diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go
index adcac355a7..2351c5da87 100644
--- a/services/gitdiff/gitdiff_test.go
+++ b/services/gitdiff/gitdiff_test.go
@@ -5,7 +5,6 @@
package gitdiff
import (
- "fmt"
"strconv"
"strings"
"testing"
@@ -643,9 +642,9 @@ func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) {
MaxFiles: setting.Git.MaxGitDiffFiles,
WhitespaceBehavior: behavior,
})
- assert.NoError(t, err, fmt.Sprintf("Error when diff with %s", behavior))
+ assert.NoError(t, err, "Error when diff with %s", behavior)
for _, f := range diffs.Files {
- assert.True(t, len(f.Sections) > 0, fmt.Sprintf("%s should have sections", f.Name))
+ assert.NotEmpty(t, f.Sections, "%s should have sections", f.Name)
}
}
}
diff --git a/services/migrations/gitlab_test.go b/services/migrations/gitlab_test.go
index 0b9eeaed54..eccfc4def1 100644
--- a/services/migrations/gitlab_test.go
+++ b/services/migrations/gitlab_test.go
@@ -50,7 +50,7 @@ func TestGitlabDownloadRepo(t *testing.T) {
topics, err := downloader.GetTopics()
assert.NoError(t, err)
- assert.True(t, len(topics) == 2)
+ assert.Len(t, topics, 2)
assert.EqualValues(t, []string{"migration", "test"}, topics)
milestones, err := downloader.GetMilestones()
diff --git a/services/org/team_test.go b/services/org/team_test.go
index 58b8e0803c..98addac8f8 100644
--- a/services/org/team_test.go
+++ b/services/org/team_test.go
@@ -121,7 +121,7 @@ func TestDeleteTeam(t *testing.T) {
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
accessMode, err := access_model.AccessLevel(db.DefaultContext, user, repo)
assert.NoError(t, err)
- assert.True(t, accessMode < perm.AccessModeWrite)
+ assert.Less(t, accessMode, perm.AccessModeWrite)
}
func TestAddTeamMember(t *testing.T) {
diff --git a/services/pull/reviewer_test.go b/services/pull/reviewer_test.go
index 1ff373bafb..b106e2e89f 100644
--- a/services/pull/reviewer_test.go
+++ b/services/pull/reviewer_test.go
@@ -30,7 +30,7 @@ func TestRepoGetReviewers(t *testing.T) {
// should not include doer and remove the poster
reviewers, err = pull_service.GetReviewers(ctx, repo1, 11, 2)
assert.NoError(t, err)
- assert.Len(t, reviewers, 0)
+ assert.Empty(t, reviewers)
// should not include PR poster, if PR poster would be otherwise eligible
reviewers, err = pull_service.GetReviewers(ctx, repo1, 11, 4)
@@ -43,7 +43,7 @@ func TestRepoGetReviewers(t *testing.T) {
reviewers, err = pull_service.GetReviewers(ctx, repo2, 2, 4)
assert.NoError(t, err)
assert.Len(t, reviewers, 1)
- assert.EqualValues(t, reviewers[0].ID, 2)
+ assert.EqualValues(t, 2, reviewers[0].ID)
// test private org repo
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
diff --git a/services/release/release_test.go b/services/release/release_test.go
index 3d0681f1e1..95a54832b9 100644
--- a/services/release/release_test.go
+++ b/services/release/release_test.go
@@ -228,7 +228,7 @@ func TestRelease_Update(t *testing.T) {
IsTag: false,
}
assert.NoError(t, CreateRelease(gitRepo, release, nil, ""))
- assert.Greater(t, release.ID, int64(0))
+ assert.Positive(t, release.ID)
release.IsDraft = false
tagName := release.TagName
diff --git a/services/repository/archiver/archiver_test.go b/services/repository/archiver/archiver_test.go
index 2ab18edf49..1d0c6e513d 100644
--- a/services/repository/archiver/archiver_test.go
+++ b/services/repository/archiver/archiver_test.go
@@ -4,7 +4,6 @@
package archiver
import (
- "errors"
"testing"
"time"
@@ -121,7 +120,7 @@ func TestArchive_Basic(t *testing.T) {
// It's fine to go ahead and set it to nil now.
assert.Equal(t, zipReq, zipReq2)
- assert.False(t, zipReq == zipReq2)
+ assert.NotSame(t, zipReq, zipReq2)
// Same commit, different compression formats should have different names.
// Ideally, the extension would match what we originally requested.
@@ -131,5 +130,5 @@ func TestArchive_Basic(t *testing.T) {
func TestErrUnknownArchiveFormat(t *testing.T) {
err := ErrUnknownArchiveFormat{RequestFormat: "master"}
- assert.True(t, errors.Is(err, ErrUnknownArchiveFormat{}))
+ assert.ErrorIs(t, err, ErrUnknownArchiveFormat{})
}
diff --git a/services/repository/license_test.go b/services/repository/license_test.go
index 39e9738145..9d3e0f36e3 100644
--- a/services/repository/license_test.go
+++ b/services/repository/license_test.go
@@ -65,7 +65,7 @@ func Test_detectLicense(t *testing.T) {
result, err := detectLicense(strings.NewReader(tests[2].arg + tests[3].arg + tests[4].arg))
assert.NoError(t, err)
t.Run("multiple licenses test", func(t *testing.T) {
- assert.Equal(t, 3, len(result))
+ assert.Len(t, result, 3)
assert.Contains(t, result, tests[2].want[0])
assert.Contains(t, result, tests[3].want[0])
assert.Contains(t, result, tests[4].want[0])
diff --git a/services/repository/transfer_test.go b/services/repository/transfer_test.go
index 67799eddcc..0401701ba5 100644
--- a/services/repository/transfer_test.go
+++ b/services/repository/transfer_test.go
@@ -103,7 +103,7 @@ func TestRepositoryTransfer(t *testing.T) {
assert.NoError(t, models.CreatePendingRepositoryTransfer(db.DefaultContext, doer, user2, repo.ID, nil))
transfer, err = models.GetPendingRepositoryTransfer(db.DefaultContext, repo)
- assert.Nil(t, err)
+ assert.NoError(t, err)
assert.NoError(t, transfer.LoadAttributes(db.DefaultContext))
assert.Equal(t, "user2", transfer.Recipient.Name)
diff --git a/services/webhook/packagist_test.go b/services/webhook/packagist_test.go
index e9b0695baa..f47807fa6e 100644
--- a/services/webhook/packagist_test.go
+++ b/services/webhook/packagist_test.go
@@ -25,7 +25,7 @@ func TestPackagistPayload(t *testing.T) {
pl, err := pc.Create(p)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
})
t.Run("Delete", func(t *testing.T) {
@@ -33,7 +33,7 @@ func TestPackagistPayload(t *testing.T) {
pl, err := pc.Delete(p)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
})
t.Run("Fork", func(t *testing.T) {
@@ -41,7 +41,7 @@ func TestPackagistPayload(t *testing.T) {
pl, err := pc.Fork(p)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
})
t.Run("Push", func(t *testing.T) {
@@ -59,12 +59,12 @@ func TestPackagistPayload(t *testing.T) {
p.Action = api.HookIssueOpened
pl, err := pc.Issue(p)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
p.Action = api.HookIssueClosed
pl, err = pc.Issue(p)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
})
t.Run("IssueComment", func(t *testing.T) {
@@ -72,7 +72,7 @@ func TestPackagistPayload(t *testing.T) {
pl, err := pc.IssueComment(p)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
})
t.Run("PullRequest", func(t *testing.T) {
@@ -80,7 +80,7 @@ func TestPackagistPayload(t *testing.T) {
pl, err := pc.PullRequest(p)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
})
t.Run("PullRequestComment", func(t *testing.T) {
@@ -88,7 +88,7 @@ func TestPackagistPayload(t *testing.T) {
pl, err := pc.IssueComment(p)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
})
t.Run("Review", func(t *testing.T) {
@@ -97,7 +97,7 @@ func TestPackagistPayload(t *testing.T) {
pl, err := pc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
})
t.Run("Repository", func(t *testing.T) {
@@ -105,7 +105,7 @@ func TestPackagistPayload(t *testing.T) {
pl, err := pc.Repository(p)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
})
t.Run("Package", func(t *testing.T) {
@@ -113,7 +113,7 @@ func TestPackagistPayload(t *testing.T) {
pl, err := pc.Package(p)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
})
t.Run("Wiki", func(t *testing.T) {
@@ -122,17 +122,17 @@ func TestPackagistPayload(t *testing.T) {
p.Action = api.HookWikiCreated
pl, err := pc.Wiki(p)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
p.Action = api.HookWikiEdited
pl, err = pc.Wiki(p)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
p.Action = api.HookWikiDeleted
pl, err = pc.Wiki(p)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
})
t.Run("Release", func(t *testing.T) {
@@ -140,7 +140,7 @@ func TestPackagistPayload(t *testing.T) {
pl, err := pc.Release(p)
require.NoError(t, err)
- require.Equal(t, pl, PackagistPayload{})
+ require.Equal(t, PackagistPayload{}, pl)
})
}
diff --git a/services/webhook/webhook_test.go b/services/webhook/webhook_test.go
index 5f5c146232..63cbce1771 100644
--- a/services/webhook/webhook_test.go
+++ b/services/webhook/webhook_test.go
@@ -21,11 +21,11 @@ func TestWebhook_GetSlackHook(t *testing.T) {
Meta: `{"channel": "foo", "username": "username", "color": "blue"}`,
}
slackHook := GetSlackHook(w)
- assert.Equal(t, *slackHook, SlackMeta{
+ assert.Equal(t, SlackMeta{
Channel: "foo",
Username: "username",
Color: "blue",
- })
+ }, *slackHook)
}
func TestPrepareWebhooks(t *testing.T) {