Merge pull request 'Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v1.60.1 (forgejo)' (#4953) from renovate/forgejo-github.com-golangci-golangci-lint-cmd-golangci-lint-1.x into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4953
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-08-19 07:38:14 +00:00
commit 51620ab0f3
35 changed files with 65 additions and 70 deletions

View file

@ -29,7 +29,7 @@ XGO_VERSION := go-1.21.x
AIR_PACKAGE ?= github.com/air-verse/air@v1 # renovate: datasource=go 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 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 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 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 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 SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0 # renovate: datasource=go

View file

@ -535,14 +535,14 @@ Forgejo or set your environment appropriately.`, "")
index := bytes.IndexByte(rs.Data, byte(0)) index := bytes.IndexByte(rs.Data, byte(0))
if index >= len(rs.Data) { 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 index < 0 {
if len(rs.Data) == 10 && rs.Data[9] == '\n' { if len(rs.Data) == 10 && rs.Data[9] == '\n' {
index = 9 index = 9
} else { } 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)
} }
} }

View file

@ -117,7 +117,7 @@ func TestDelayWriter(t *testing.T) {
defer test.MockVariableValue(&setting.InternalToken, "Random")() defer test.MockVariableValue(&setting.InternalToken, "Random")()
defer test.MockVariableValue(&setting.InstallLock, true)() defer test.MockVariableValue(&setting.InstallLock, true)()
defer test.MockVariableValue(&setting.Git.VerbosePush, 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. // Setup the Stdin.
f, err := os.OpenFile(t.TempDir()+"/stdin", os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o666) f, err := os.OpenFile(t.TempDir()+"/stdin", os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o666)

View file

@ -4,7 +4,6 @@
package activities_test package activities_test
import ( import (
"fmt"
"testing" "testing"
"time" "time"
@ -92,7 +91,7 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
assert.Len(t, actions, contributions, "invalid action count: did the test data became too old?") assert.Len(t, actions, contributions, "invalid action count: did the test data became too old?")
assert.Equal(t, count, int64(contributions)) 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 // Test JSON rendering
jsonData, err := json.Marshal(heatmap) jsonData, err := json.Marshal(heatmap)

View file

@ -114,7 +114,7 @@ func readArmoredSign(r io.Reader) (body io.Reader, err error) {
return nil, err return nil, err
} }
if block.Type != openpgp.SignatureType { 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 return block.Body, nil
} }
@ -139,7 +139,7 @@ func tryGetKeyIDFromSignature(sig *packet.Signature) string {
if sig.IssuerKeyId != nil && (*sig.IssuerKeyId) != 0 { if sig.IssuerKeyId != nil && (*sig.IssuerKeyId) != 0 {
return fmt.Sprintf("%016X", *sig.IssuerKeyId) 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 fmt.Sprintf("%016X", sig.IssuerFingerprint[12:20])
} }
return "" return ""

View file

@ -22,7 +22,7 @@ func TestOAuth2Application_GenerateClientSecret(t *testing.T) {
app := unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: 1}) app := unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: 1})
secret, err := app.GenerateClientSecret(db.DefaultContext) secret, err := app.GenerateClientSecret(db.DefaultContext)
require.NoError(t, err) require.NoError(t, err)
assert.Positive(t, len(secret)) assert.NotEmpty(t, secret)
unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: 1, ClientSecret: app.ClientSecret}) unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: 1, ClientSecret: app.ClientSecret})
} }

View file

@ -4,7 +4,6 @@
package git package git
import ( import (
"fmt"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -65,14 +64,6 @@ func TestBranchRuleMatch(t *testing.T) {
for _, kase := range kases { for _, kase := range kases {
pb := ProtectedBranch{RuleName: kase.Rule} pb := ProtectedBranch{RuleName: kase.Rule}
var should, infact string assert.EqualValues(t, kase.ExpectedMatch, pb.Match(kase.BranchName), "%s - %s", kase.BranchName, kase.Rule)
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),
)
} }
} }

View file

@ -83,7 +83,7 @@ func UnwrapLDAPSourceCfg(x *xorm.Engine) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to unmarshal %s: %w", source.Cfg, err) 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) bs, err := json.Marshal(wrapped.Source)
if err != nil { if err != nil {
return err return err

View file

@ -57,8 +57,8 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
err := x.Table("attachment").Where("issue_id > 0").Find(&issueAttachments) err := x.Table("attachment").Where("issue_id > 0").Find(&issueAttachments)
require.NoError(t, err) require.NoError(t, err)
for _, attach := range issueAttachments { for _, attach := range issueAttachments {
assert.Greater(t, attach.RepoID, int64(0)) assert.Positive(t, attach.RepoID)
assert.Greater(t, attach.IssueID, int64(0)) assert.Positive(t, attach.IssueID)
var issue Issue var issue Issue
has, err := x.ID(attach.IssueID).Get(&issue) has, err := x.ID(attach.IssueID).Get(&issue)
require.NoError(t, err) require.NoError(t, err)
@ -70,8 +70,8 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
err = x.Table("attachment").Where("release_id > 0").Find(&releaseAttachments) err = x.Table("attachment").Where("release_id > 0").Find(&releaseAttachments)
require.NoError(t, err) require.NoError(t, err)
for _, attach := range releaseAttachments { for _, attach := range releaseAttachments {
assert.Greater(t, attach.RepoID, int64(0)) assert.Positive(t, attach.RepoID)
assert.Greater(t, attach.ReleaseID, int64(0)) assert.Positive(t, attach.ReleaseID)
var release Release var release Release
has, err := x.ID(attach.ReleaseID).Get(&release) has, err := x.ID(attach.ReleaseID).Get(&release)
require.NoError(t, err) require.NoError(t, err)

View file

@ -743,7 +743,7 @@ func GetUserRepositories(ctx context.Context, opts *SearchRepoOptions) (Reposito
cond = cond.And(builder.Eq{"is_private": false}) 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)) cond = cond.And(builder.In("lower_name", opts.LowerNames))
} }

View file

@ -598,7 +598,7 @@ func Test_ValidateUser(t *testing.T) {
{ID: 2, Visibility: structs.VisibleTypePrivate}: true, {ID: 2, Visibility: structs.VisibleTypePrivate}: true,
} }
for kase, expected := range kases { 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))
} }
} }

View file

@ -73,7 +73,9 @@ func (cc *cacheContext) Expired() bool {
return timeNow().Sub(cc.created) > cacheContextLifetime 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, Since there are both WithCacheContext and WithNoCacheContext,

View file

@ -114,7 +114,7 @@ type LogNameStatusCommitData struct {
// Next returns the next LogStatusCommitData // Next returns the next LogStatusCommitData
func (g *LogNameStatusRepoParser) Next(treepath string, paths2ids map[string]int, changed []bool, maxpathlen int) (*LogNameStatusCommitData, error) { func (g *LogNameStatusRepoParser) Next(treepath string, paths2ids map[string]int, changed []bool, maxpathlen int) (*LogNameStatusCommitData, error) {
var err error var err error
if g.next == nil || len(g.next) == 0 { if len(g.next) == 0 {
g.buffull = false g.buffull = false
g.next, err = g.rd.ReadSlice('\x00') g.next, err = g.rd.ReadSlice('\x00')
if err != nil { if err != nil {

View file

@ -401,7 +401,7 @@ func (f *valuedField) Render() string {
} }
func (f *valuedField) Value() 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 { func (f *valuedField) Options() []*valuedOption {

View file

@ -258,42 +258,42 @@ func ValidatePackageSpec(p *Package) error {
} }
for _, cd := range p.VersionMetadata.CheckDepends { for _, cd := range p.VersionMetadata.CheckDepends {
if !rePkgVer.MatchString(cd) { 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 { for _, d := range p.VersionMetadata.Depends {
if !rePkgVer.MatchString(d) { if !rePkgVer.MatchString(d) {
return util.NewInvalidArgumentErrorf("invalid dependency: " + d) return util.NewInvalidArgumentErrorf("invalid dependency: %s", d)
} }
} }
for _, md := range p.VersionMetadata.MakeDepends { for _, md := range p.VersionMetadata.MakeDepends {
if !rePkgVer.MatchString(md) { 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 { for _, p := range p.VersionMetadata.Provides {
if !rePkgVer.MatchString(p) { if !rePkgVer.MatchString(p) {
return util.NewInvalidArgumentErrorf("invalid provides: " + p) return util.NewInvalidArgumentErrorf("invalid provides: %s", p)
} }
} }
for _, p := range p.VersionMetadata.Conflicts { for _, p := range p.VersionMetadata.Conflicts {
if !rePkgVer.MatchString(p) { if !rePkgVer.MatchString(p) {
return util.NewInvalidArgumentErrorf("invalid conflicts: " + p) return util.NewInvalidArgumentErrorf("invalid conflicts: %s", p)
} }
} }
for _, p := range p.VersionMetadata.Replaces { for _, p := range p.VersionMetadata.Replaces {
if !rePkgVer.MatchString(p) { if !rePkgVer.MatchString(p) {
return util.NewInvalidArgumentErrorf("invalid replaces: " + p) return util.NewInvalidArgumentErrorf("invalid replaces: %s", p)
} }
} }
for _, p := range p.VersionMetadata.Replaces { for _, p := range p.VersionMetadata.Replaces {
if !rePkgVer.MatchString(p) { if !rePkgVer.MatchString(p) {
return util.NewInvalidArgumentErrorf("invalid xdata: " + p) return util.NewInvalidArgumentErrorf("invalid xdata: %s", p)
} }
} }
for _, od := range p.VersionMetadata.OptDepends { for _, od := range p.VersionMetadata.OptDepends {
if !reOptDep.MatchString(od) { 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 { for _, bf := range p.VersionMetadata.Backup {

View file

@ -120,7 +120,7 @@ func (q *baseChannel) RemoveAll(ctx context.Context) error {
q.mu.Lock() q.mu.Lock()
defer q.mu.Unlock() defer q.mu.Unlock()
for q.c != nil && len(q.c) > 0 { for len(q.c) > 0 {
<-q.c <-q.c
} }

View file

@ -173,8 +173,8 @@ func testWorkerPoolQueuePersistence(t *testing.T, queueSetting setting.QueueSett
q2() // restart the queue to continue to execute the tasks in it q2() // restart the queue to continue to execute the tasks in it
assert.NotZero(t, len(tasksQ1)) assert.NotEmpty(t, tasksQ1)
assert.NotZero(t, len(tasksQ2)) assert.NotEmpty(t, tasksQ2)
assert.EqualValues(t, testCount, len(tasksQ1)+len(tasksQ2)) assert.EqualValues(t, testCount, len(tasksQ1)+len(tasksQ2))
} }

View file

@ -752,7 +752,7 @@ func EditPullRequest(ctx *context.APIContext) {
// update allow edits // update allow edits
if form.AllowMaintainerEdit != nil { if form.AllowMaintainerEdit != nil {
if err := pull_service.SetAllowEdits(ctx, ctx.Doer, pr, *form.AllowMaintainerEdit); err != 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)) ctx.Error(http.StatusForbidden, "SetAllowEdits", fmt.Sprintf("SetAllowEdits: %s", err))
return return
} }

View file

@ -1821,7 +1821,7 @@ func SetAllowEdits(ctx *context.Context) {
} }
if err := pull_service.SetAllowEdits(ctx, ctx.Doer, pr, form.AllowMaintainerEdit); err != 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) ctx.Error(http.StatusForbidden)
return return
} }

View file

@ -8,6 +8,7 @@ import (
"bytes" "bytes"
gocontext "context" gocontext "context"
"encoding/base64" "encoding/base64"
"errors"
"fmt" "fmt"
"html/template" "html/template"
"image" "image"
@ -753,12 +754,12 @@ func checkHomeCodeViewable(ctx *context.Context) {
} }
if firstUnit != nil { if firstUnit != nil {
ctx.Redirect(fmt.Sprintf("%s%s", ctx.Repo.Repository.Link(), firstUnit.URI)) ctx.Redirect(ctx.Repo.Repository.Link() + firstUnit.URI)
return 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) { func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) {

View file

@ -761,7 +761,7 @@ func UsernameSubRoute(ctx *context.Context) {
} }
// check view permissions // check view permissions
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) { 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 false
} }
return true return true

View file

@ -56,7 +56,7 @@ func OwnerProfile(ctx *context.Context) {
func userProfile(ctx *context.Context) { func userProfile(ctx *context.Context) {
// check view permissions // check view permissions
if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) { if !user_model.IsUserVisibleToViewer(ctx, ctx.ContextUser, ctx.Doer) {
ctx.NotFound("user", fmt.Errorf(ctx.ContextUser.Name)) ctx.NotFound("User not visible", nil)
return return
} }

View file

@ -34,7 +34,9 @@ import (
"github.com/nektos/act/pkg/model" "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. // withMethod sets the notification method that this context currently executes.
// Used for debugging/ troubleshooting purposes. // Used for debugging/ troubleshooting purposes.

View file

@ -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 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) log.Info("%-v was scheduled to automerge by an unauthorized user", pr)
return return
} }

View file

@ -5,7 +5,6 @@
package gitdiff package gitdiff
import ( import (
"fmt"
"strconv" "strconv"
"strings" "strings"
"testing" "testing"
@ -645,9 +644,9 @@ func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) {
MaxFiles: setting.Git.MaxGitDiffFiles, MaxFiles: setting.Git.MaxGitDiffFiles,
WhitespaceBehavior: behavior, 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 { 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)
} }
} }
} }

View file

@ -289,7 +289,7 @@ func TestRelease_Update(t *testing.T) {
IsTag: false, IsTag: false,
} }
require.NoError(t, CreateRelease(gitRepo, release, "", []*AttachmentChange{})) require.NoError(t, CreateRelease(gitRepo, release, "", []*AttachmentChange{}))
assert.Greater(t, release.ID, int64(0)) assert.Positive(t, release.ID)
release.IsDraft = false release.IsDraft = false
tagName := release.TagName tagName := release.TagName

View file

@ -40,7 +40,7 @@ func TestAPIListStopWatches(t *testing.T) {
assert.EqualValues(t, issue.Title, apiWatches[0].IssueTitle) assert.EqualValues(t, issue.Title, apiWatches[0].IssueTitle)
assert.EqualValues(t, repo.Name, apiWatches[0].RepoName) assert.EqualValues(t, repo.Name, apiWatches[0].RepoName)
assert.EqualValues(t, repo.OwnerName, apiWatches[0].RepoOwnerName) assert.EqualValues(t, repo.OwnerName, apiWatches[0].RepoOwnerName)
assert.Greater(t, apiWatches[0].Seconds, int64(0)) assert.Positive(t, apiWatches[0].Seconds)
} }
} }

View file

@ -5,6 +5,7 @@ package integration
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "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)) remoteAddress := fmt.Sprintf("%s%s/%s", u.String(), url.PathEscape(user.Name), url.PathEscape(mirrorRepo.Name))
deletePushMirrors := repo_model.DeletePushMirrors deletePushMirrors := repo_model.DeletePushMirrors
deletePushMirrorsError := "deletePushMirrorsError" deletePushMirrorsError := errors.New("deletePushMirrorsError")
deletePushMirrorsFail := func(ctx context.Context, opts repo_model.PushMirrorOptions) error { deletePushMirrorsFail := func(ctx context.Context, opts repo_model.PushMirrorOptions) error {
return fmt.Errorf(deletePushMirrorsError) return deletePushMirrorsError
} }
addPushMirrorRemote := mirror_service.AddPushMirrorRemote addPushMirrorRemote := mirror_service.AddPushMirrorRemote
addPushMirrorRemoteError := "addPushMirrorRemoteError" addPushMirrorRemoteError := errors.New("addPushMirrorRemoteError")
addPushMirrorRemoteFail := func(ctx context.Context, m *repo_model.PushMirror, addr string) error { addPushMirrorRemoteFail := func(ctx context.Context, m *repo_model.PushMirror, addr string) error {
return fmt.Errorf(addPushMirrorRemoteError) return addPushMirrorRemoteError
} }
for _, testCase := range []struct { for _, testCase := range []struct {
@ -81,7 +82,7 @@ func testAPIPushMirror(t *testing.T, u *url.URL) {
}, },
{ {
name: "fail to add and delete", name: "fail to add and delete",
message: deletePushMirrorsError, message: deletePushMirrorsError.Error(),
status: http.StatusInternalServerError, status: http.StatusInternalServerError,
mirrorCount: 1, mirrorCount: 1,
setup: func() { setup: func() {
@ -91,7 +92,7 @@ func testAPIPushMirror(t *testing.T, u *url.URL) {
}, },
{ {
name: "fail to add", name: "fail to add",
message: addPushMirrorRemoteError, message: addPushMirrorRemoteError.Error(),
status: http.StatusInternalServerError, status: http.StatusInternalServerError,
mirrorCount: 0, mirrorCount: 0,
setup: func() { setup: func() {

View file

@ -266,17 +266,17 @@ func TestAPIDeleteReleaseByTagName(t *testing.T) {
createNewReleaseUsingAPI(t, token, owner, repo, "release-tag", "", "Release Tag", "test") createNewReleaseUsingAPI(t, token, owner, repo, "release-tag", "", "Release Tag", "test")
// delete release // 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) AddTokenAuth(token)
_ = MakeRequest(t, req, http.StatusNoContent) _ = MakeRequest(t, req, http.StatusNoContent)
// make sure release is deleted // 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) AddTokenAuth(token)
_ = MakeRequest(t, req, http.StatusNotFound) _ = MakeRequest(t, req, http.StatusNotFound)
// delete release tag too // 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) AddTokenAuth(token)
_ = MakeRequest(t, req, http.StatusNoContent) _ = MakeRequest(t, req, http.StatusNoContent)
} }

View file

@ -39,7 +39,7 @@ func TestAPIRepoTeams(t *testing.T) {
if assert.Len(t, teams, 2) { if assert.Len(t, teams, 2) {
assert.EqualValues(t, "Owners", teams[0].Name) assert.EqualValues(t, "Owners", teams[0].Name)
assert.True(t, teams[0].CanCreateOrgRepo) 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, "owner", teams[0].Permission)
assert.EqualValues(t, "test_team", teams[1].Name) assert.EqualValues(t, "test_team", teams[1].Name)

View file

@ -42,7 +42,7 @@ func (doc *HTMLDoc) AssertDropdown(t testing.TB, name string) *goquery.Selection
t.Helper() t.Helper()
dropdownGroup := doc.Find(fmt.Sprintf(".dropdown:has(input[name='%s'])", name)) 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 return dropdownGroup
} }
@ -60,13 +60,13 @@ func (doc *HTMLDoc) AssertDropdownHasSelectedOption(t testing.TB, dropdownName,
dropdownGroup := doc.AssertDropdown(t, dropdownName) dropdownGroup := doc.AssertDropdown(t, dropdownName)
selectedValue, _ := dropdownGroup.Find(fmt.Sprintf("input[name='%s']", dropdownName)).Attr("value") 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 { dropdownValues := dropdownGroup.Find(".menu [data-value]").Map(func(i int, s *goquery.Selection) string {
value, _ := s.Attr("data-value") value, _ := s.Attr("data-value")
return 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 // Find gets the descendants of each element in the current set of

View file

@ -83,7 +83,7 @@ func TestMigrate(t *testing.T) {
{svc: structs.ForgejoService}, {svc: structs.ForgejoService},
} { } {
// Step 0: verify the repo is available // 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) _ = session.MakeRequest(t, req, http.StatusOK)
// Step 1: get the Gitea migration form // Step 1: get the Gitea migration form
req = NewRequestf(t, "GET", "/repo/migrate/?service_type=%d", s.svc) req = NewRequestf(t, "GET", "/repo/migrate/?service_type=%d", s.svc)

View file

@ -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") link, exists := htmlDoc.doc.Find(fmt.Sprintf("form.ui.form[action=\"%s\"]", forkURL)).Attr("action")
assert.True(t, exists, "The template has changed") 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") _, 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{ req = NewRequestWithValues(t, "POST", link, map[string]string{
"_csrf": htmlDoc.GetCSRF(), "_csrf": htmlDoc.GetCSRF(),
"uid": fmt.Sprintf("%d", forkOwner.ID), "uid": fmt.Sprintf("%d", forkOwner.ID),

View file

@ -444,7 +444,7 @@ func TestViewRepoDirectory(t *testing.T) {
repoSummary := htmlDoc.doc.Find(".repository-summary") repoSummary := htmlDoc.doc.Find(".repository-summary")
repoFilesTable := htmlDoc.doc.Find("#repo-files-table") 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, description.Length())
assert.Zero(t, repoTopics.Length()) assert.Zero(t, repoTopics.Length())

View file

@ -291,7 +291,7 @@ func TestListStopWatches(t *testing.T) {
assert.EqualValues(t, issue.Title, apiWatches[0].IssueTitle) assert.EqualValues(t, issue.Title, apiWatches[0].IssueTitle)
assert.EqualValues(t, repo.Name, apiWatches[0].RepoName) assert.EqualValues(t, repo.Name, apiWatches[0].RepoName)
assert.EqualValues(t, repo.OwnerName, apiWatches[0].RepoOwnerName) assert.EqualValues(t, repo.OwnerName, apiWatches[0].RepoOwnerName)
assert.Greater(t, apiWatches[0].Seconds, int64(0)) assert.Positive(t, apiWatches[0].Seconds)
} }
} }