diff --git a/Makefile b/Makefile index e254aebe9..46eb45c66 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ XGO_VERSION := go-1.21.x AIR_PACKAGE ?= github.com/air-verse/air@v1 # renovate: datasource=go EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3.0.3 # renovate: datasource=go GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.7.0 # renovate: datasource=go -GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 # renovate: datasource=go +GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.1 # renovate: datasource=go GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11 # renovate: datasource=go MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.6.0 # renovate: datasource=go SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0 # renovate: datasource=go diff --git a/cmd/hook.go b/cmd/hook.go index eec93aece..edab61197 100644 --- a/cmd/hook.go +++ b/cmd/hook.go @@ -535,14 +535,14 @@ Forgejo or set your environment appropriately.`, "") index := bytes.IndexByte(rs.Data, byte(0)) if index >= len(rs.Data) { - return fail(ctx, "Protocol: format error", "pkt-line: format error "+fmt.Sprint(rs.Data)) + return fail(ctx, "Protocol: format error", "pkt-line: format error %s", rs.Data) } if index < 0 { if len(rs.Data) == 10 && rs.Data[9] == '\n' { index = 9 } else { - return fail(ctx, "Protocol: format error", "pkt-line: format error "+fmt.Sprint(rs.Data)) + return fail(ctx, "Protocol: format error", "pkt-line: format error %s", rs.Data) } } diff --git a/cmd/hook_test.go b/cmd/hook_test.go index 890b236c7..514eb917e 100644 --- a/cmd/hook_test.go +++ b/cmd/hook_test.go @@ -117,7 +117,7 @@ func TestDelayWriter(t *testing.T) { defer test.MockVariableValue(&setting.InternalToken, "Random")() defer test.MockVariableValue(&setting.InstallLock, true)() defer test.MockVariableValue(&setting.Git.VerbosePush, true)() - require.NoError(t, os.Setenv("SSH_ORIGINAL_COMMAND", "true")) + t.Setenv("SSH_ORIGINAL_COMMAND", "true") // Setup the Stdin. f, err := os.OpenFile(t.TempDir()+"/stdin", os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o666) diff --git a/models/activities/user_heatmap_test.go b/models/activities/user_heatmap_test.go index 7063da8bd..316ea7d76 100644 --- a/models/activities/user_heatmap_test.go +++ b/models/activities/user_heatmap_test.go @@ -4,7 +4,6 @@ package activities_test import ( - "fmt" "testing" "time" @@ -92,7 +91,7 @@ func TestGetUserHeatmapDataByUser(t *testing.T) { require.NoError(t, err) assert.Len(t, actions, contributions, "invalid action count: did the test data became too old?") assert.Equal(t, count, int64(contributions)) - assert.Equal(t, tc.CountResult, contributions, fmt.Sprintf("testcase '%s'", tc.desc)) + assert.Equal(t, tc.CountResult, contributions, tc.desc) // Test JSON rendering jsonData, err := json.Marshal(heatmap) diff --git a/models/asymkey/gpg_key_common.go b/models/asymkey/gpg_key_common.go index b1b4f1eb5..db1912c31 100644 --- a/models/asymkey/gpg_key_common.go +++ b/models/asymkey/gpg_key_common.go @@ -114,7 +114,7 @@ func readArmoredSign(r io.Reader) (body io.Reader, err error) { return nil, err } if block.Type != openpgp.SignatureType { - return nil, fmt.Errorf("expected '" + openpgp.SignatureType + "', got: " + block.Type) + return nil, fmt.Errorf("expected %q, got: %s", openpgp.SignatureType, block.Type) } return block.Body, nil } @@ -139,7 +139,7 @@ func tryGetKeyIDFromSignature(sig *packet.Signature) string { if sig.IssuerKeyId != nil && (*sig.IssuerKeyId) != 0 { return fmt.Sprintf("%016X", *sig.IssuerKeyId) } - if sig.IssuerFingerprint != nil && len(sig.IssuerFingerprint) > 0 { + if len(sig.IssuerFingerprint) > 0 { return fmt.Sprintf("%016X", sig.IssuerFingerprint[12:20]) } return "" diff --git a/models/auth/oauth2_test.go b/models/auth/oauth2_test.go index c43d9d36c..94b506ed4 100644 --- a/models/auth/oauth2_test.go +++ b/models/auth/oauth2_test.go @@ -22,7 +22,7 @@ func TestOAuth2Application_GenerateClientSecret(t *testing.T) { app := unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: 1}) secret, err := app.GenerateClientSecret(db.DefaultContext) require.NoError(t, err) - assert.Positive(t, len(secret)) + assert.NotEmpty(t, secret) unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: 1, ClientSecret: app.ClientSecret}) } diff --git a/models/git/protected_branch_test.go b/models/git/protected_branch_test.go index 1962859a8..278fa9fee 100644 --- a/models/git/protected_branch_test.go +++ b/models/git/protected_branch_test.go @@ -4,7 +4,6 @@ package git import ( - "fmt" "testing" "github.com/stretchr/testify/assert" @@ -65,14 +64,6 @@ func TestBranchRuleMatch(t *testing.T) { for _, kase := range kases { pb := ProtectedBranch{RuleName: kase.Rule} - var should, infact string - if !kase.ExpectedMatch { - should = " not" - } else { - infact = " not" - } - assert.EqualValues(t, kase.ExpectedMatch, pb.Match(kase.BranchName), - fmt.Sprintf("%s should%s match %s but it is%s", kase.BranchName, should, kase.Rule, infact), - ) + assert.EqualValues(t, kase.ExpectedMatch, pb.Match(kase.BranchName), "%s - %s", kase.BranchName, kase.Rule) } } diff --git a/models/migrations/v1_16/v189.go b/models/migrations/v1_16/v189.go index afd93b0ea..564964505 100644 --- a/models/migrations/v1_16/v189.go +++ b/models/migrations/v1_16/v189.go @@ -83,7 +83,7 @@ func UnwrapLDAPSourceCfg(x *xorm.Engine) error { if err != nil { return fmt.Errorf("failed to unmarshal %s: %w", source.Cfg, err) } - if wrapped.Source != nil && len(wrapped.Source) > 0 { + if len(wrapped.Source) > 0 { bs, err := json.Marshal(wrapped.Source) if err != nil { return err diff --git a/models/migrations/v1_16/v193_test.go b/models/migrations/v1_16/v193_test.go index 1ead74f96..0da670888 100644 --- a/models/migrations/v1_16/v193_test.go +++ b/models/migrations/v1_16/v193_test.go @@ -57,8 +57,8 @@ func Test_AddRepoIDForAttachment(t *testing.T) { err := x.Table("attachment").Where("issue_id > 0").Find(&issueAttachments) require.NoError(t, err) for _, attach := range issueAttachments { - assert.Greater(t, attach.RepoID, int64(0)) - assert.Greater(t, attach.IssueID, int64(0)) + assert.Positive(t, attach.RepoID) + assert.Positive(t, attach.IssueID) var issue Issue has, err := x.ID(attach.IssueID).Get(&issue) require.NoError(t, err) @@ -70,8 +70,8 @@ func Test_AddRepoIDForAttachment(t *testing.T) { err = x.Table("attachment").Where("release_id > 0").Find(&releaseAttachments) require.NoError(t, err) for _, attach := range releaseAttachments { - assert.Greater(t, attach.RepoID, int64(0)) - assert.Greater(t, attach.ReleaseID, int64(0)) + assert.Positive(t, attach.RepoID) + assert.Positive(t, attach.ReleaseID) var release Release has, err := x.ID(attach.ReleaseID).Get(&release) require.NoError(t, err) diff --git a/models/repo/repo_list.go b/models/repo/repo_list.go index 6cce2d33a..162f933fb 100644 --- a/models/repo/repo_list.go +++ b/models/repo/repo_list.go @@ -743,7 +743,7 @@ func GetUserRepositories(ctx context.Context, opts *SearchRepoOptions) (Reposito cond = cond.And(builder.Eq{"is_private": false}) } - if opts.LowerNames != nil && len(opts.LowerNames) > 0 { + if len(opts.LowerNames) > 0 { cond = cond.And(builder.In("lower_name", opts.LowerNames)) } diff --git a/models/user/user_test.go b/models/user/user_test.go index ba29cbc3a..8f4350f77 100644 --- a/models/user/user_test.go +++ b/models/user/user_test.go @@ -598,7 +598,7 @@ func Test_ValidateUser(t *testing.T) { {ID: 2, Visibility: structs.VisibleTypePrivate}: true, } for kase, expected := range kases { - assert.EqualValues(t, expected, nil == user_model.ValidateUser(kase), fmt.Sprintf("case: %+v", kase)) + assert.EqualValues(t, expected, nil == user_model.ValidateUser(kase)) } } diff --git a/modules/cache/context.go b/modules/cache/context.go index 62bbf5dcb..5f0ca81e8 100644 --- a/modules/cache/context.go +++ b/modules/cache/context.go @@ -73,7 +73,9 @@ func (cc *cacheContext) Expired() bool { return timeNow().Sub(cc.created) > cacheContextLifetime } -var cacheContextKey = struct{}{} +type cacheContextType = struct{ useless struct{} } + +var cacheContextKey = cacheContextType{useless: struct{}{}} /* Since there are both WithCacheContext and WithNoCacheContext, diff --git a/modules/git/log_name_status.go b/modules/git/log_name_status.go index 9e345f3ee..1fd58abfc 100644 --- a/modules/git/log_name_status.go +++ b/modules/git/log_name_status.go @@ -114,7 +114,7 @@ type LogNameStatusCommitData struct { // Next returns the next LogStatusCommitData func (g *LogNameStatusRepoParser) Next(treepath string, paths2ids map[string]int, changed []bool, maxpathlen int) (*LogNameStatusCommitData, error) { var err error - if g.next == nil || len(g.next) == 0 { + if len(g.next) == 0 { g.buffull = false g.next, err = g.rd.ReadSlice('\x00') if err != nil { diff --git a/modules/issue/template/template.go b/modules/issue/template/template.go index 0a105c723..967bed026 100644 --- a/modules/issue/template/template.go +++ b/modules/issue/template/template.go @@ -401,7 +401,7 @@ func (f *valuedField) Render() string { } func (f *valuedField) Value() string { - return strings.TrimSpace(f.Get(fmt.Sprintf("form-field-" + f.ID))) + return strings.TrimSpace(f.Get("form-field-" + f.ID)) } func (f *valuedField) Options() []*valuedOption { diff --git a/modules/packages/arch/metadata.go b/modules/packages/arch/metadata.go index 9b443899b..8fba53e58 100644 --- a/modules/packages/arch/metadata.go +++ b/modules/packages/arch/metadata.go @@ -258,42 +258,42 @@ func ValidatePackageSpec(p *Package) error { } for _, cd := range p.VersionMetadata.CheckDepends { if !rePkgVer.MatchString(cd) { - return util.NewInvalidArgumentErrorf("invalid check dependency: " + cd) + return util.NewInvalidArgumentErrorf("invalid check dependency: %s", cd) } } for _, d := range p.VersionMetadata.Depends { if !rePkgVer.MatchString(d) { - return util.NewInvalidArgumentErrorf("invalid dependency: " + d) + return util.NewInvalidArgumentErrorf("invalid dependency: %s", d) } } for _, md := range p.VersionMetadata.MakeDepends { if !rePkgVer.MatchString(md) { - return util.NewInvalidArgumentErrorf("invalid make dependency: " + md) + return util.NewInvalidArgumentErrorf("invalid make dependency: %s", md) } } for _, p := range p.VersionMetadata.Provides { if !rePkgVer.MatchString(p) { - return util.NewInvalidArgumentErrorf("invalid provides: " + p) + return util.NewInvalidArgumentErrorf("invalid provides: %s", p) } } for _, p := range p.VersionMetadata.Conflicts { if !rePkgVer.MatchString(p) { - return util.NewInvalidArgumentErrorf("invalid conflicts: " + p) + return util.NewInvalidArgumentErrorf("invalid conflicts: %s", p) } } for _, p := range p.VersionMetadata.Replaces { if !rePkgVer.MatchString(p) { - return util.NewInvalidArgumentErrorf("invalid replaces: " + p) + return util.NewInvalidArgumentErrorf("invalid replaces: %s", p) } } for _, p := range p.VersionMetadata.Replaces { if !rePkgVer.MatchString(p) { - return util.NewInvalidArgumentErrorf("invalid xdata: " + p) + return util.NewInvalidArgumentErrorf("invalid xdata: %s", p) } } for _, od := range p.VersionMetadata.OptDepends { if !reOptDep.MatchString(od) { - return util.NewInvalidArgumentErrorf("invalid optional dependency: " + od) + return util.NewInvalidArgumentErrorf("invalid optional dependency: %s", od) } } for _, bf := range p.VersionMetadata.Backup { diff --git a/modules/queue/base_channel.go b/modules/queue/base_channel.go index d03c72bda..dd8ccb15f 100644 --- a/modules/queue/base_channel.go +++ b/modules/queue/base_channel.go @@ -120,7 +120,7 @@ func (q *baseChannel) RemoveAll(ctx context.Context) error { q.mu.Lock() defer q.mu.Unlock() - for q.c != nil && len(q.c) > 0 { + for len(q.c) > 0 { <-q.c } diff --git a/modules/queue/workerqueue_test.go b/modules/queue/workerqueue_test.go index 112a16c8e..4cfe8ede9 100644 --- a/modules/queue/workerqueue_test.go +++ b/modules/queue/workerqueue_test.go @@ -173,8 +173,8 @@ func testWorkerPoolQueuePersistence(t *testing.T, queueSetting setting.QueueSett q2() // restart the queue to continue to execute the tasks in it - assert.NotZero(t, len(tasksQ1)) - assert.NotZero(t, len(tasksQ2)) + assert.NotEmpty(t, tasksQ1) + assert.NotEmpty(t, tasksQ2) assert.EqualValues(t, testCount, len(tasksQ1)+len(tasksQ2)) } diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 4ae4d0881..97937fa93 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -752,7 +752,7 @@ func EditPullRequest(ctx *context.APIContext) { // update allow edits if form.AllowMaintainerEdit != nil { if err := pull_service.SetAllowEdits(ctx, ctx.Doer, pr, *form.AllowMaintainerEdit); err != nil { - if errors.Is(pull_service.ErrUserHasNoPermissionForAction, err) { + if errors.Is(err, pull_service.ErrUserHasNoPermissionForAction) { ctx.Error(http.StatusForbidden, "SetAllowEdits", fmt.Sprintf("SetAllowEdits: %s", err)) return } diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 56a46f7f0..d2b0f5b0f 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -1821,7 +1821,7 @@ func SetAllowEdits(ctx *context.Context) { } if err := pull_service.SetAllowEdits(ctx, ctx.Doer, pr, form.AllowMaintainerEdit); err != nil { - if errors.Is(pull_service.ErrUserHasNoPermissionForAction, err) { + if errors.Is(err, pull_service.ErrUserHasNoPermissionForAction) { ctx.Error(http.StatusForbidden) return } diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index bc4376756..e96691764 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -8,6 +8,7 @@ import ( "bytes" gocontext "context" "encoding/base64" + "errors" "fmt" "html/template" "image" @@ -753,12 +754,12 @@ func checkHomeCodeViewable(ctx *context.Context) { } if firstUnit != nil { - ctx.Redirect(fmt.Sprintf("%s%s", ctx.Repo.Repository.Link(), firstUnit.URI)) + ctx.Redirect(ctx.Repo.Repository.Link() + firstUnit.URI) return } } - ctx.NotFound("Home", fmt.Errorf(ctx.Locale.TrString("units.error.no_unit_allowed_repo"))) + ctx.NotFound("Home", errors.New(ctx.Locale.TrString("units.error.no_unit_allowed_repo"))) } func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) { diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 0a1b08c57..55d579eb2 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -761,7 +761,7 @@ func UsernameSubRoute(ctx *context.Context) { } // check view permissions if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) { - ctx.NotFound("user", fmt.Errorf(ctx.ContextUser.Name)) + ctx.NotFound("User not visible", nil) return false } return true diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 24b0db2f1..78069318f 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -56,7 +56,7 @@ func OwnerProfile(ctx *context.Context) { func userProfile(ctx *context.Context) { // check view permissions if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) { - ctx.NotFound("user", fmt.Errorf(ctx.ContextUser.Name)) + ctx.NotFound("User not visible", nil) return } diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 4196cf768..86897d5cb 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -34,7 +34,9 @@ import ( "github.com/nektos/act/pkg/model" ) -var methodCtxKey struct{} +type methodCtx struct{} + +var methodCtxKey = methodCtx{} // withMethod sets the notification method that this context currently executes. // Used for debugging/ troubleshooting purposes. diff --git a/services/automerge/automerge.go b/services/automerge/automerge.go index 10f3c28d5..972961603 100644 --- a/services/automerge/automerge.go +++ b/services/automerge/automerge.go @@ -276,7 +276,7 @@ func handlePullRequestAutoMerge(pullID int64, sha string) { } if err := pull_service.CheckPullMergeable(ctx, doer, &perm, pr, pull_service.MergeCheckTypeGeneral, false); err != nil { - if errors.Is(pull_service.ErrUserNotAllowedToMerge, err) { + if errors.Is(err, pull_service.ErrUserNotAllowedToMerge) { log.Info("%-v was scheduled to automerge by an unauthorized user", pr) return } diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go index 40285f811..f2c099d55 100644 --- a/services/gitdiff/gitdiff_test.go +++ b/services/gitdiff/gitdiff_test.go @@ -5,7 +5,6 @@ package gitdiff import ( - "fmt" "strconv" "strings" "testing" @@ -645,9 +644,9 @@ func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) { MaxFiles: setting.Git.MaxGitDiffFiles, WhitespaceBehavior: behavior, }) - require.NoError(t, err, fmt.Sprintf("Error when diff with %s", behavior)) + require.NoError(t, err, "Error when diff with %s", behavior) for _, f := range diffs.Files { - assert.Positive(t, len(f.Sections), fmt.Sprintf("%s should have sections", f.Name)) + assert.NotEmpty(t, f.Sections, "%s should have sections", f.Name) } } } diff --git a/services/release/release_test.go b/services/release/release_test.go index 0cd655b31..026bba825 100644 --- a/services/release/release_test.go +++ b/services/release/release_test.go @@ -289,7 +289,7 @@ func TestRelease_Update(t *testing.T) { IsTag: false, } require.NoError(t, CreateRelease(gitRepo, release, "", []*AttachmentChange{})) - assert.Greater(t, release.ID, int64(0)) + assert.Positive(t, release.ID) release.IsDraft = false tagName := release.TagName diff --git a/tests/integration/api_issue_stopwatch_test.go b/tests/integration/api_issue_stopwatch_test.go index 230667821..4765787e6 100644 --- a/tests/integration/api_issue_stopwatch_test.go +++ b/tests/integration/api_issue_stopwatch_test.go @@ -40,7 +40,7 @@ func TestAPIListStopWatches(t *testing.T) { assert.EqualValues(t, issue.Title, apiWatches[0].IssueTitle) assert.EqualValues(t, repo.Name, apiWatches[0].RepoName) assert.EqualValues(t, repo.OwnerName, apiWatches[0].RepoOwnerName) - assert.Greater(t, apiWatches[0].Seconds, int64(0)) + assert.Positive(t, apiWatches[0].Seconds) } } diff --git a/tests/integration/api_push_mirror_test.go b/tests/integration/api_push_mirror_test.go index f0ef67075..24d533051 100644 --- a/tests/integration/api_push_mirror_test.go +++ b/tests/integration/api_push_mirror_test.go @@ -5,6 +5,7 @@ package integration import ( "context" + "errors" "fmt" "net/http" "net/url" @@ -52,15 +53,15 @@ func testAPIPushMirror(t *testing.T, u *url.URL) { remoteAddress := fmt.Sprintf("%s%s/%s", u.String(), url.PathEscape(user.Name), url.PathEscape(mirrorRepo.Name)) deletePushMirrors := repo_model.DeletePushMirrors - deletePushMirrorsError := "deletePushMirrorsError" + deletePushMirrorsError := errors.New("deletePushMirrorsError") deletePushMirrorsFail := func(ctx context.Context, opts repo_model.PushMirrorOptions) error { - return fmt.Errorf(deletePushMirrorsError) + return deletePushMirrorsError } addPushMirrorRemote := mirror_service.AddPushMirrorRemote - addPushMirrorRemoteError := "addPushMirrorRemoteError" + addPushMirrorRemoteError := errors.New("addPushMirrorRemoteError") addPushMirrorRemoteFail := func(ctx context.Context, m *repo_model.PushMirror, addr string) error { - return fmt.Errorf(addPushMirrorRemoteError) + return addPushMirrorRemoteError } for _, testCase := range []struct { @@ -81,7 +82,7 @@ func testAPIPushMirror(t *testing.T, u *url.URL) { }, { name: "fail to add and delete", - message: deletePushMirrorsError, + message: deletePushMirrorsError.Error(), status: http.StatusInternalServerError, mirrorCount: 1, setup: func() { @@ -91,7 +92,7 @@ func testAPIPushMirror(t *testing.T, u *url.URL) { }, { name: "fail to add", - message: addPushMirrorRemoteError, + message: addPushMirrorRemoteError.Error(), status: http.StatusInternalServerError, mirrorCount: 0, setup: func() { diff --git a/tests/integration/api_releases_test.go b/tests/integration/api_releases_test.go index 92b484560..ad29343b7 100644 --- a/tests/integration/api_releases_test.go +++ b/tests/integration/api_releases_test.go @@ -266,17 +266,17 @@ func TestAPIDeleteReleaseByTagName(t *testing.T) { createNewReleaseUsingAPI(t, token, owner, repo, "release-tag", "", "Release Tag", "test") // delete release - req := NewRequestf(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/releases/tags/release-tag", owner.Name, repo.Name)). + req := NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%s/releases/tags/release-tag", owner.Name, repo.Name). AddTokenAuth(token) _ = MakeRequest(t, req, http.StatusNoContent) // make sure release is deleted - req = NewRequestf(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/releases/tags/release-tag", owner.Name, repo.Name)). + req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%s/releases/tags/release-tag", owner.Name, repo.Name). AddTokenAuth(token) _ = MakeRequest(t, req, http.StatusNotFound) // delete release tag too - req = NewRequestf(t, http.MethodDelete, fmt.Sprintf("/api/v1/repos/%s/%s/tags/release-tag", owner.Name, repo.Name)). + req = NewRequestf(t, http.MethodDelete, "/api/v1/repos/%s/%s/tags/release-tag", owner.Name, repo.Name). AddTokenAuth(token) _ = MakeRequest(t, req, http.StatusNoContent) } diff --git a/tests/integration/api_repo_teams_test.go b/tests/integration/api_repo_teams_test.go index 558bac815..91bfd66b3 100644 --- a/tests/integration/api_repo_teams_test.go +++ b/tests/integration/api_repo_teams_test.go @@ -39,7 +39,7 @@ func TestAPIRepoTeams(t *testing.T) { if assert.Len(t, teams, 2) { assert.EqualValues(t, "Owners", teams[0].Name) assert.True(t, teams[0].CanCreateOrgRepo) - assert.True(t, util.SliceSortedEqual(unit.AllUnitKeyNames(), teams[0].Units), fmt.Sprintf("%v == %v", unit.AllUnitKeyNames(), teams[0].Units)) + assert.True(t, util.SliceSortedEqual(unit.AllUnitKeyNames(), teams[0].Units)) assert.EqualValues(t, "owner", teams[0].Permission) assert.EqualValues(t, "test_team", teams[1].Name) diff --git a/tests/integration/html_helper.go b/tests/integration/html_helper.go index f6768714a..802dcb05a 100644 --- a/tests/integration/html_helper.go +++ b/tests/integration/html_helper.go @@ -42,7 +42,7 @@ func (doc *HTMLDoc) AssertDropdown(t testing.TB, name string) *goquery.Selection t.Helper() dropdownGroup := doc.Find(fmt.Sprintf(".dropdown:has(input[name='%s'])", name)) - assert.Equal(t, 1, dropdownGroup.Length(), fmt.Sprintf("%s dropdown does not exist", name)) + assert.Equal(t, 1, dropdownGroup.Length(), "%s dropdown does not exist", name) return dropdownGroup } @@ -60,13 +60,13 @@ func (doc *HTMLDoc) AssertDropdownHasSelectedOption(t testing.TB, dropdownName, dropdownGroup := doc.AssertDropdown(t, dropdownName) selectedValue, _ := dropdownGroup.Find(fmt.Sprintf("input[name='%s']", dropdownName)).Attr("value") - assert.Equal(t, expectedValue, selectedValue, fmt.Sprintf("%s dropdown doesn't have expected value selected", dropdownName)) + assert.Equal(t, expectedValue, selectedValue, "%s dropdown doesn't have expected value selected", dropdownName) dropdownValues := dropdownGroup.Find(".menu [data-value]").Map(func(i int, s *goquery.Selection) string { value, _ := s.Attr("data-value") return value }) - assert.Contains(t, dropdownValues, expectedValue, fmt.Sprintf("%s dropdown doesn't have an option with expected value", dropdownName)) + assert.Contains(t, dropdownValues, expectedValue, "%s dropdown doesn't have an option with expected value", dropdownName) } // Find gets the descendants of each element in the current set of diff --git a/tests/integration/migrate_test.go b/tests/integration/migrate_test.go index 123f975ca..43cfc4f37 100644 --- a/tests/integration/migrate_test.go +++ b/tests/integration/migrate_test.go @@ -83,7 +83,7 @@ func TestMigrate(t *testing.T) { {svc: structs.ForgejoService}, } { // Step 0: verify the repo is available - req := NewRequestf(t, "GET", fmt.Sprintf("/%s/%s", ownerName, repoName)) + req := NewRequestf(t, "GET", "/%s/%s", ownerName, repoName) _ = session.MakeRequest(t, req, http.StatusOK) // Step 1: get the Gitea migration form req = NewRequestf(t, "GET", "/repo/migrate/?service_type=%d", s.svc) diff --git a/tests/integration/repo_fork_test.go b/tests/integration/repo_fork_test.go index 38cbc3af2..262774983 100644 --- a/tests/integration/repo_fork_test.go +++ b/tests/integration/repo_fork_test.go @@ -45,7 +45,7 @@ func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkO link, exists := htmlDoc.doc.Find(fmt.Sprintf("form.ui.form[action=\"%s\"]", forkURL)).Attr("action") assert.True(t, exists, "The template has changed") _, exists = htmlDoc.doc.Find(fmt.Sprintf(".owner.dropdown .item[data-value=\"%d\"]", forkOwner.ID)).Attr("data-value") - assert.True(t, exists, fmt.Sprintf("Fork owner '%s' is not present in select box", forkOwnerName)) + assert.True(t, exists, "Fork owner %q is not present in select box", forkOwnerName) req = NewRequestWithValues(t, "POST", link, map[string]string{ "_csrf": htmlDoc.GetCSRF(), "uid": fmt.Sprintf("%d", forkOwner.ID), diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index 367d13163..bf8a7eb69 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -444,7 +444,7 @@ func TestViewRepoDirectory(t *testing.T) { repoSummary := htmlDoc.doc.Find(".repository-summary") repoFilesTable := htmlDoc.doc.Find("#repo-files-table") - assert.NotZero(t, len(repoFilesTable.Nodes)) + assert.NotEmpty(t, repoFilesTable.Nodes) assert.Zero(t, description.Length()) assert.Zero(t, repoTopics.Length()) diff --git a/tests/integration/user_test.go b/tests/integration/user_test.go index e5e819dfe..e53f7f1e8 100644 --- a/tests/integration/user_test.go +++ b/tests/integration/user_test.go @@ -291,7 +291,7 @@ func TestListStopWatches(t *testing.T) { assert.EqualValues(t, issue.Title, apiWatches[0].IssueTitle) assert.EqualValues(t, repo.Name, apiWatches[0].RepoName) assert.EqualValues(t, repo.OwnerName, apiWatches[0].RepoOwnerName) - assert.Greater(t, apiWatches[0].Seconds, int64(0)) + assert.Positive(t, apiWatches[0].Seconds) } }