Skip to content

Commit

Permalink
Merge branch 'main' into docker/package
Browse files Browse the repository at this point in the history
  • Loading branch information
hiifong authored Dec 15, 2024
2 parents bab4b87 + b01b0b9 commit ad35e01
Show file tree
Hide file tree
Showing 118 changed files with 531 additions and 455 deletions.
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ linters:
- revive
- staticcheck
- stylecheck
- tenv
- testifylint
- typecheck
- unconvert
- unused
Expand All @@ -34,6 +36,10 @@ output:
show-stats: true

linters-settings:
testifylint:
disable:
- go-require
- require-error
stylecheck:
checks: ["all", "-ST1005", "-ST1003"]
nakedret:
Expand Down
6 changes: 3 additions & 3 deletions models/actions/runner_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestGetLatestRunnerToken(t *testing.T) {
token := unittest.AssertExistsAndLoadBean(t, &ActionRunnerToken{ID: 3})
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
assert.NoError(t, err)
assert.EqualValues(t, token, expectedToken)
assert.EqualValues(t, expectedToken, token)
}

func TestNewRunnerToken(t *testing.T) {
Expand All @@ -26,7 +26,7 @@ func TestNewRunnerToken(t *testing.T) {
assert.NoError(t, err)
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
assert.NoError(t, err)
assert.EqualValues(t, token, expectedToken)
assert.EqualValues(t, expectedToken, token)
}

func TestUpdateRunnerToken(t *testing.T) {
Expand All @@ -36,5 +36,5 @@ func TestUpdateRunnerToken(t *testing.T) {
assert.NoError(t, UpdateRunnerToken(db.DefaultContext, token))
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
assert.NoError(t, err)
assert.EqualValues(t, token, expectedToken)
assert.EqualValues(t, expectedToken, token)
}
5 changes: 2 additions & 3 deletions models/activities/user_heatmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package activities_test

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -91,11 +90,11 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
assert.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, "testcase '%s'", tc.desc)

// Test JSON rendering
jsonData, err := json.Marshal(heatmap)
assert.NoError(t, err)
assert.Equal(t, tc.JSONResult, string(jsonData))
assert.JSONEq(t, tc.JSONResult, string(jsonData))
}
}
4 changes: 2 additions & 2 deletions models/auth/oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestOAuth2Application_GenerateClientSecret(t *testing.T) {
app := unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: 1})
secret, err := app.GenerateClientSecret(db.DefaultContext)
assert.NoError(t, err)
assert.True(t, len(secret) > 0)
assert.NotEmpty(t, secret)
unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: 1, ClientSecret: app.ClientSecret})
}

Expand Down Expand Up @@ -165,7 +165,7 @@ func TestOAuth2Grant_GenerateNewAuthorizationCode(t *testing.T) {
code, err := grant.GenerateNewAuthorizationCode(db.DefaultContext, "https://example2.com/callback", "CjvyTLSdR47G5zYenDA-eDWW4lRrO8yvjcWwbD_deOg", "S256")
assert.NoError(t, err)
assert.NotNil(t, code)
assert.True(t, len(code.Code) > 32) // secret length > 32
assert.Greater(t, len(code.Code), 32) // secret length > 32
}

func TestOAuth2Grant_TableName(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions models/db/iterate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func TestIterate(t *testing.T) {
if !has {
return db.ErrNotExist{Resource: "repo_unit", ID: repoUnit.ID}
}
assert.EqualValues(t, repoUnit.RepoID, repoUnit.RepoID)
assert.EqualValues(t, repoUnit.CreatedUnix, repoUnit.CreatedUnix)
return nil
})
assert.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions models/git/commit_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestGetCommitStatuses(t *testing.T) {
SHA: sha1,
})
assert.NoError(t, err)
assert.Equal(t, int(maxResults), 5)
assert.Equal(t, 5, int(maxResults))
assert.Len(t, statuses, 5)

assert.Equal(t, "ci/awesomeness", statuses[0].Context)
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestGetCommitStatuses(t *testing.T) {
SHA: sha1,
})
assert.NoError(t, err)
assert.Equal(t, int(maxResults), 5)
assert.Equal(t, 5, int(maxResults))
assert.Empty(t, statuses)
}

Expand Down
3 changes: 1 addition & 2 deletions models/git/protected_branch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package git

import (
"fmt"
"testing"

"code.gitea.io/gitea/models/db"
Expand Down Expand Up @@ -76,7 +75,7 @@ func TestBranchRuleMatch(t *testing.T) {
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),
"%s should%s match %s but it is%s", kase.BranchName, should, kase.Rule, infact,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion models/issues/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestFetchCodeComments(t *testing.T) {
}

func TestAsCommentType(t *testing.T) {
assert.Equal(t, issues_model.CommentType(0), issues_model.CommentTypeComment)
assert.Equal(t, issues_model.CommentTypeComment, issues_model.CommentType(0))
assert.Equal(t, issues_model.CommentTypeUndefined, issues_model.AsCommentType(""))
assert.Equal(t, issues_model.CommentTypeUndefined, issues_model.AsCommentType("nonsense"))
assert.Equal(t, issues_model.CommentTypeComment, issues_model.AsCommentType("comment"))
Expand Down
2 changes: 1 addition & 1 deletion models/issues/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func assertCreateIssues(t *testing.T, isPull bool) {
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 1})
milestone := unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{ID: 1})
assert.EqualValues(t, milestone.ID, 1)
assert.EqualValues(t, 1, milestone.ID)
reaction := &issues_model.Reaction{
Type: "heart",
UserID: owner.ID,
Expand Down
6 changes: 3 additions & 3 deletions models/issues/issue_watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ func TestGetIssueWatchers(t *testing.T) {
iws, err := issues_model.GetIssueWatchers(db.DefaultContext, 1, db.ListOptions{})
assert.NoError(t, err)
// Watcher is inactive, thus 0
assert.Len(t, iws, 0)
assert.Empty(t, iws)

iws, err = issues_model.GetIssueWatchers(db.DefaultContext, 2, db.ListOptions{})
assert.NoError(t, err)
// Watcher is explicit not watching
assert.Len(t, iws, 0)
assert.Empty(t, iws)

iws, err = issues_model.GetIssueWatchers(db.DefaultContext, 5, db.ListOptions{})
assert.NoError(t, err)
// Issue has no Watchers
assert.Len(t, iws, 0)
assert.Empty(t, iws)

iws, err = issues_model.GetIssueWatchers(db.DefaultContext, 7, db.ListOptions{})
assert.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions models/issues/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func TestLabel_LoadSelectedLabelsAfterClick(t *testing.T) {
// First test : with negative and scope
label.LoadSelectedLabelsAfterClick([]int64{1, -8}, []string{"", "scope"})
assert.Equal(t, "1", label.QueryString)
assert.Equal(t, true, label.IsSelected)
assert.True(t, label.IsSelected)

// Second test : with duplicates
label.LoadSelectedLabelsAfterClick([]int64{1, 7, 1, 7, 7}, []string{"", "scope", "", "scope", "scope"})
assert.Equal(t, "1,8", label.QueryString)
assert.Equal(t, false, label.IsSelected)
assert.False(t, label.IsSelected)

// Third test : empty set
label.LoadSelectedLabelsAfterClick([]int64{}, []string{})
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestGetLabelsByIssueID(t *testing.T) {

labels, err = issues_model.GetLabelsByIssueID(db.DefaultContext, unittest.NonexistentID)
assert.NoError(t, err)
assert.Len(t, labels, 0)
assert.Empty(t, labels)
}

func TestUpdateLabel(t *testing.T) {
Expand All @@ -271,7 +271,7 @@ func TestUpdateLabel(t *testing.T) {
assert.EqualValues(t, label.Color, newLabel.Color)
assert.EqualValues(t, label.Name, newLabel.Name)
assert.EqualValues(t, label.Description, newLabel.Description)
assert.EqualValues(t, newLabel.ArchivedUnix, 0)
assert.EqualValues(t, 0, newLabel.ArchivedUnix)
unittest.CheckConsistencyFor(t, &issues_model.Label{}, &repo_model.Repository{})
}

Expand Down
2 changes: 1 addition & 1 deletion models/issues/milestone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestGetMilestonesByRepoID(t *testing.T) {
IsClosed: optional.Some(false),
})
assert.NoError(t, err)
assert.Len(t, milestones, 0)
assert.Empty(t, milestones)
}

func TestGetMilestones(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion models/issues/pull_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestPullRequestList_LoadReviewCommentsCounts(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, reviewComments, 2)
for _, pr := range prs {
assert.EqualValues(t, reviewComments[pr.IssueID], 1)
assert.EqualValues(t, 1, reviewComments[pr.IssueID])
}
}

Expand Down
2 changes: 1 addition & 1 deletion models/issues/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestLoadRequestedReviewers(t *testing.T) {
assert.NoError(t, pull.LoadIssue(db.DefaultContext))
issue := pull.Issue
assert.NoError(t, issue.LoadRepo(db.DefaultContext))
assert.Len(t, pull.RequestedReviewers, 0)
assert.Empty(t, pull.RequestedReviewers)

user1, err := user_model.GetUserByID(db.DefaultContext, 1)
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion models/issues/stopwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestCancelStopwatch(t *testing.T) {

_ = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{Type: issues_model.CommentTypeCancelTracking, PosterID: user1.ID, IssueID: issue1.ID})

assert.Nil(t, issues_model.CancelStopwatch(db.DefaultContext, user1, issue2))
assert.NoError(t, issues_model.CancelStopwatch(db.DefaultContext, user1, issue2))
}

func TestStopwatchExists(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions models/issues/tracked_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestGetTrackedTimes(t *testing.T) {

times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: -1})
assert.NoError(t, err)
assert.Len(t, times, 0)
assert.Empty(t, times)

// by User
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{UserID: 1})
Expand All @@ -60,7 +60,7 @@ func TestGetTrackedTimes(t *testing.T) {

times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{UserID: 3})
assert.NoError(t, err)
assert.Len(t, times, 0)
assert.Empty(t, times)

// by Repo
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{RepositoryID: 2})
Expand All @@ -69,15 +69,15 @@ func TestGetTrackedTimes(t *testing.T) {
assert.Equal(t, int64(1), times[0].Time)
issue, err := issues_model.GetIssueByID(db.DefaultContext, times[0].IssueID)
assert.NoError(t, err)
assert.Equal(t, issue.RepoID, int64(2))
assert.Equal(t, int64(2), issue.RepoID)

times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{RepositoryID: 1})
assert.NoError(t, err)
assert.Len(t, times, 5)

times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{RepositoryID: 10})
assert.NoError(t, err)
assert.Len(t, times, 0)
assert.Empty(t, times)
}

func TestTotalTimesForEachUser(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions models/migrations/v1_16/v193_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
err := x.Table("attachment").Where("issue_id > 0").Find(&issueAttachments)
assert.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)
assert.NoError(t, err)
Expand All @@ -69,8 +69,8 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
err = x.Table("attachment").Where("release_id > 0").Find(&releaseAttachments)
assert.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)
assert.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions models/migrations/v1_22/v286_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ func Test_RepositoryFormat(t *testing.T) {
repo = new(Repository)
ok, err := x.ID(2).Get(repo)
assert.NoError(t, err)
assert.EqualValues(t, true, ok)
assert.True(t, ok)
assert.EqualValues(t, "sha1", repo.ObjectFormatName)

repo = new(Repository)
ok, err = x.ID(id).Get(repo)
assert.NoError(t, err)
assert.EqualValues(t, true, ok)
assert.True(t, ok)
assert.EqualValues(t, "sha256", repo.ObjectFormatName)
}
2 changes: 1 addition & 1 deletion models/migrations/v1_22/v294_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Test_AddUniqueIndexForProjectIssue(t *testing.T) {

tables, err := x.DBMetas()
assert.NoError(t, err)
assert.EqualValues(t, 1, len(tables))
assert.Len(t, tables, 1)
found := false
for _, index := range tables[0].Indexes {
if index.Type == schemas.UniqueType {
Expand Down
2 changes: 1 addition & 1 deletion models/organization/org_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestFindOrgs(t *testing.T) {
IncludePrivate: false,
})
assert.NoError(t, err)
assert.Len(t, orgs, 0)
assert.Empty(t, orgs)

total, err := db.Count[organization.Organization](db.DefaultContext, organization.FindOrgOptions{
UserID: 4,
Expand Down
2 changes: 1 addition & 1 deletion models/organization/org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func TestGetOrgUsersByOrgID(t *testing.T) {
OrgID: unittest.NonexistentID,
})
assert.NoError(t, err)
assert.Len(t, orgUsers, 0)
assert.Empty(t, orgUsers)
}

func TestChangeOrgUserStatus(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion models/perm/access_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestAccessMode(t *testing.T) {
m := ParseAccessMode(name)
assert.Equal(t, AccessMode(i), m)
}
assert.Equal(t, AccessMode(4), AccessModeOwner)
assert.Equal(t, AccessModeOwner, AccessMode(4))
assert.Equal(t, "owner", AccessModeOwner.ToString())
assert.Equal(t, AccessModeNone, ParseAccessMode("owner"))
assert.Equal(t, AccessModeNone, ParseAccessMode("invalid"))
Expand Down
5 changes: 2 additions & 3 deletions models/project/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package project

import (
"fmt"
"strings"
"testing"

"code.gitea.io/gitea/models/db"
Expand Down Expand Up @@ -66,7 +65,7 @@ func Test_moveIssuesToAnotherColumn(t *testing.T) {

issues, err = column1.GetIssues(db.DefaultContext)
assert.NoError(t, err)
assert.Len(t, issues, 0)
assert.Empty(t, issues)

issues, err = column2.GetIssues(db.DefaultContext)
assert.NoError(t, err)
Expand Down Expand Up @@ -123,5 +122,5 @@ func Test_NewColumn(t *testing.T) {
ProjectID: project1.ID,
})
assert.Error(t, err)
assert.True(t, strings.Contains(err.Error(), "maximum number of columns reached"))
assert.Contains(t, err.Error(), "maximum number of columns reached")
}
Loading

0 comments on commit ad35e01

Please sign in to comment.