mirror of https://github.com/go-gitea/gitea.git
Enable tenv and testifylint rules (#32852)
Enables tenv and testifylint linters closes: https://github.com/go-gitea/gitea/issues/32842
This commit is contained in:
parent
df9a78cd04
commit
33e8e82c4b
|
@ -19,6 +19,8 @@ linters:
|
||||||
- revive
|
- revive
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- stylecheck
|
- stylecheck
|
||||||
|
- tenv
|
||||||
|
- testifylint
|
||||||
- typecheck
|
- typecheck
|
||||||
- unconvert
|
- unconvert
|
||||||
- unused
|
- unused
|
||||||
|
@ -34,6 +36,10 @@ output:
|
||||||
show-stats: true
|
show-stats: true
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
|
testifylint:
|
||||||
|
disable:
|
||||||
|
- go-require
|
||||||
|
- require-error
|
||||||
stylecheck:
|
stylecheck:
|
||||||
checks: ["all", "-ST1005", "-ST1003"]
|
checks: ["all", "-ST1005", "-ST1003"]
|
||||||
nakedret:
|
nakedret:
|
||||||
|
|
|
@ -17,7 +17,7 @@ func TestGetLatestRunnerToken(t *testing.T) {
|
||||||
token := unittest.AssertExistsAndLoadBean(t, &ActionRunnerToken{ID: 3})
|
token := unittest.AssertExistsAndLoadBean(t, &ActionRunnerToken{ID: 3})
|
||||||
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
|
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, token, expectedToken)
|
assert.EqualValues(t, expectedToken, token)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewRunnerToken(t *testing.T) {
|
func TestNewRunnerToken(t *testing.T) {
|
||||||
|
@ -26,7 +26,7 @@ func TestNewRunnerToken(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
|
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, token, expectedToken)
|
assert.EqualValues(t, expectedToken, token)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateRunnerToken(t *testing.T) {
|
func TestUpdateRunnerToken(t *testing.T) {
|
||||||
|
@ -36,5 +36,5 @@ func TestUpdateRunnerToken(t *testing.T) {
|
||||||
assert.NoError(t, UpdateRunnerToken(db.DefaultContext, token))
|
assert.NoError(t, UpdateRunnerToken(db.DefaultContext, token))
|
||||||
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
|
expectedToken, err := GetLatestRunnerToken(db.DefaultContext, 1, 0)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, token, expectedToken)
|
assert.EqualValues(t, expectedToken, token)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package activities_test
|
package activities_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -91,11 +90,11 @@ func TestGetUserHeatmapDataByUser(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.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, "testcase '%s'", tc.desc)
|
||||||
|
|
||||||
// Test JSON rendering
|
// Test JSON rendering
|
||||||
jsonData, err := json.Marshal(heatmap)
|
jsonData, err := json.Marshal(heatmap)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, tc.JSONResult, string(jsonData))
|
assert.JSONEq(t, tc.JSONResult, string(jsonData))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,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)
|
||||||
assert.NoError(t, err)
|
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})
|
unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: 1, ClientSecret: app.ClientSecret})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ func TestOAuth2Grant_GenerateNewAuthorizationCode(t *testing.T) {
|
||||||
code, err := grant.GenerateNewAuthorizationCode(db.DefaultContext, "https://example2.com/callback", "CjvyTLSdR47G5zYenDA-eDWW4lRrO8yvjcWwbD_deOg", "S256")
|
code, err := grant.GenerateNewAuthorizationCode(db.DefaultContext, "https://example2.com/callback", "CjvyTLSdR47G5zYenDA-eDWW4lRrO8yvjcWwbD_deOg", "S256")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, code)
|
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) {
|
func TestOAuth2Grant_TableName(t *testing.T) {
|
||||||
|
|
|
@ -38,8 +38,6 @@ func TestIterate(t *testing.T) {
|
||||||
if !has {
|
if !has {
|
||||||
return db.ErrNotExist{Resource: "repo_unit", ID: repoUnit.ID}
|
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
|
return nil
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -34,7 +34,7 @@ func TestGetCommitStatuses(t *testing.T) {
|
||||||
SHA: sha1,
|
SHA: sha1,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, int(maxResults), 5)
|
assert.Equal(t, 5, int(maxResults))
|
||||||
assert.Len(t, statuses, 5)
|
assert.Len(t, statuses, 5)
|
||||||
|
|
||||||
assert.Equal(t, "ci/awesomeness", statuses[0].Context)
|
assert.Equal(t, "ci/awesomeness", statuses[0].Context)
|
||||||
|
@ -63,7 +63,7 @@ func TestGetCommitStatuses(t *testing.T) {
|
||||||
SHA: sha1,
|
SHA: sha1,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, int(maxResults), 5)
|
assert.Equal(t, 5, int(maxResults))
|
||||||
assert.Empty(t, statuses)
|
assert.Empty(t, statuses)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package git
|
package git
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
@ -76,7 +75,7 @@ func TestBranchRuleMatch(t *testing.T) {
|
||||||
infact = " not"
|
infact = " not"
|
||||||
}
|
}
|
||||||
assert.EqualValues(t, kase.ExpectedMatch, pb.Match(kase.BranchName),
|
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,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func TestFetchCodeComments(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAsCommentType(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(""))
|
||||||
assert.Equal(t, issues_model.CommentTypeUndefined, issues_model.AsCommentType("nonsense"))
|
assert.Equal(t, issues_model.CommentTypeUndefined, issues_model.AsCommentType("nonsense"))
|
||||||
assert.Equal(t, issues_model.CommentTypeComment, issues_model.AsCommentType("comment"))
|
assert.Equal(t, issues_model.CommentTypeComment, issues_model.AsCommentType("comment"))
|
||||||
|
|
|
@ -434,7 +434,7 @@ func assertCreateIssues(t *testing.T, isPull bool) {
|
||||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
||||||
label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 1})
|
label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 1})
|
||||||
milestone := unittest.AssertExistsAndLoadBean(t, &issues_model.Milestone{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{
|
reaction := &issues_model.Reaction{
|
||||||
Type: "heart",
|
Type: "heart",
|
||||||
UserID: owner.ID,
|
UserID: owner.ID,
|
||||||
|
|
|
@ -48,17 +48,17 @@ func TestGetIssueWatchers(t *testing.T) {
|
||||||
iws, err := issues_model.GetIssueWatchers(db.DefaultContext, 1, db.ListOptions{})
|
iws, err := issues_model.GetIssueWatchers(db.DefaultContext, 1, db.ListOptions{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// Watcher is inactive, thus 0
|
// Watcher is inactive, thus 0
|
||||||
assert.Len(t, iws, 0)
|
assert.Empty(t, iws)
|
||||||
|
|
||||||
iws, err = issues_model.GetIssueWatchers(db.DefaultContext, 2, db.ListOptions{})
|
iws, err = issues_model.GetIssueWatchers(db.DefaultContext, 2, db.ListOptions{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// Watcher is explicit not watching
|
// Watcher is explicit not watching
|
||||||
assert.Len(t, iws, 0)
|
assert.Empty(t, iws)
|
||||||
|
|
||||||
iws, err = issues_model.GetIssueWatchers(db.DefaultContext, 5, db.ListOptions{})
|
iws, err = issues_model.GetIssueWatchers(db.DefaultContext, 5, db.ListOptions{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
// Issue has no Watchers
|
// Issue has no Watchers
|
||||||
assert.Len(t, iws, 0)
|
assert.Empty(t, iws)
|
||||||
|
|
||||||
iws, err = issues_model.GetIssueWatchers(db.DefaultContext, 7, db.ListOptions{})
|
iws, err = issues_model.GetIssueWatchers(db.DefaultContext, 7, db.ListOptions{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -31,12 +31,12 @@ func TestLabel_LoadSelectedLabelsAfterClick(t *testing.T) {
|
||||||
// First test : with negative and scope
|
// First test : with negative and scope
|
||||||
label.LoadSelectedLabelsAfterClick([]int64{1, -8}, []string{"", "scope"})
|
label.LoadSelectedLabelsAfterClick([]int64{1, -8}, []string{"", "scope"})
|
||||||
assert.Equal(t, "1", label.QueryString)
|
assert.Equal(t, "1", label.QueryString)
|
||||||
assert.Equal(t, true, label.IsSelected)
|
assert.True(t, label.IsSelected)
|
||||||
|
|
||||||
// Second test : with duplicates
|
// Second test : with duplicates
|
||||||
label.LoadSelectedLabelsAfterClick([]int64{1, 7, 1, 7, 7}, []string{"", "scope", "", "scope", "scope"})
|
label.LoadSelectedLabelsAfterClick([]int64{1, 7, 1, 7, 7}, []string{"", "scope", "", "scope", "scope"})
|
||||||
assert.Equal(t, "1,8", label.QueryString)
|
assert.Equal(t, "1,8", label.QueryString)
|
||||||
assert.Equal(t, false, label.IsSelected)
|
assert.False(t, label.IsSelected)
|
||||||
|
|
||||||
// Third test : empty set
|
// Third test : empty set
|
||||||
label.LoadSelectedLabelsAfterClick([]int64{}, []string{})
|
label.LoadSelectedLabelsAfterClick([]int64{}, []string{})
|
||||||
|
@ -248,7 +248,7 @@ func TestGetLabelsByIssueID(t *testing.T) {
|
||||||
|
|
||||||
labels, err = issues_model.GetLabelsByIssueID(db.DefaultContext, unittest.NonexistentID)
|
labels, err = issues_model.GetLabelsByIssueID(db.DefaultContext, unittest.NonexistentID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, labels, 0)
|
assert.Empty(t, labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateLabel(t *testing.T) {
|
func TestUpdateLabel(t *testing.T) {
|
||||||
|
@ -271,7 +271,7 @@ func TestUpdateLabel(t *testing.T) {
|
||||||
assert.EqualValues(t, label.Color, newLabel.Color)
|
assert.EqualValues(t, label.Color, newLabel.Color)
|
||||||
assert.EqualValues(t, label.Name, newLabel.Name)
|
assert.EqualValues(t, label.Name, newLabel.Name)
|
||||||
assert.EqualValues(t, label.Description, newLabel.Description)
|
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{})
|
unittest.CheckConsistencyFor(t, &issues_model.Label{}, &repo_model.Repository{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ func TestGetMilestonesByRepoID(t *testing.T) {
|
||||||
IsClosed: optional.Some(false),
|
IsClosed: optional.Some(false),
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, milestones, 0)
|
assert.Empty(t, milestones)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetMilestones(t *testing.T) {
|
func TestGetMilestones(t *testing.T) {
|
||||||
|
|
|
@ -40,7 +40,7 @@ func TestPullRequestList_LoadReviewCommentsCounts(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, reviewComments, 2)
|
assert.Len(t, reviewComments, 2)
|
||||||
for _, pr := range prs {
|
for _, pr := range prs {
|
||||||
assert.EqualValues(t, reviewComments[pr.IssueID], 1)
|
assert.EqualValues(t, 1, reviewComments[pr.IssueID])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ func TestLoadRequestedReviewers(t *testing.T) {
|
||||||
assert.NoError(t, pull.LoadIssue(db.DefaultContext))
|
assert.NoError(t, pull.LoadIssue(db.DefaultContext))
|
||||||
issue := pull.Issue
|
issue := pull.Issue
|
||||||
assert.NoError(t, issue.LoadRepo(db.DefaultContext))
|
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)
|
user1, err := user_model.GetUserByID(db.DefaultContext, 1)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -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})
|
_ = 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) {
|
func TestStopwatchExists(t *testing.T) {
|
||||||
|
|
|
@ -50,7 +50,7 @@ func TestGetTrackedTimes(t *testing.T) {
|
||||||
|
|
||||||
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: -1})
|
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{IssueID: -1})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, times, 0)
|
assert.Empty(t, times)
|
||||||
|
|
||||||
// by User
|
// by User
|
||||||
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{UserID: 1})
|
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{UserID: 1})
|
||||||
|
@ -60,7 +60,7 @@ func TestGetTrackedTimes(t *testing.T) {
|
||||||
|
|
||||||
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{UserID: 3})
|
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{UserID: 3})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, times, 0)
|
assert.Empty(t, times)
|
||||||
|
|
||||||
// by Repo
|
// by Repo
|
||||||
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{RepositoryID: 2})
|
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{RepositoryID: 2})
|
||||||
|
@ -69,7 +69,7 @@ func TestGetTrackedTimes(t *testing.T) {
|
||||||
assert.Equal(t, int64(1), times[0].Time)
|
assert.Equal(t, int64(1), times[0].Time)
|
||||||
issue, err := issues_model.GetIssueByID(db.DefaultContext, times[0].IssueID)
|
issue, err := issues_model.GetIssueByID(db.DefaultContext, times[0].IssueID)
|
||||||
assert.NoError(t, err)
|
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})
|
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{RepositoryID: 1})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -77,7 +77,7 @@ func TestGetTrackedTimes(t *testing.T) {
|
||||||
|
|
||||||
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{RepositoryID: 10})
|
times, err = issues_model.GetTrackedTimes(db.DefaultContext, &issues_model.FindTrackedTimesOptions{RepositoryID: 10})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, times, 0)
|
assert.Empty(t, times)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTotalTimesForEachUser(t *testing.T) {
|
func TestTotalTimesForEachUser(t *testing.T) {
|
||||||
|
|
|
@ -56,8 +56,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)
|
||||||
assert.NoError(t, err)
|
assert.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)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -69,8 +69,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)
|
||||||
assert.NoError(t, err)
|
assert.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)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -107,12 +107,12 @@ func Test_RepositoryFormat(t *testing.T) {
|
||||||
repo = new(Repository)
|
repo = new(Repository)
|
||||||
ok, err := x.ID(2).Get(repo)
|
ok, err := x.ID(2).Get(repo)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, true, ok)
|
assert.True(t, ok)
|
||||||
assert.EqualValues(t, "sha1", repo.ObjectFormatName)
|
assert.EqualValues(t, "sha1", repo.ObjectFormatName)
|
||||||
|
|
||||||
repo = new(Repository)
|
repo = new(Repository)
|
||||||
ok, err = x.ID(id).Get(repo)
|
ok, err = x.ID(id).Get(repo)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, true, ok)
|
assert.True(t, ok)
|
||||||
assert.EqualValues(t, "sha256", repo.ObjectFormatName)
|
assert.EqualValues(t, "sha256", repo.ObjectFormatName)
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ func Test_AddUniqueIndexForProjectIssue(t *testing.T) {
|
||||||
|
|
||||||
tables, err := x.DBMetas()
|
tables, err := x.DBMetas()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 1, len(tables))
|
assert.Len(t, tables, 1)
|
||||||
found := false
|
found := false
|
||||||
for _, index := range tables[0].Indexes {
|
for _, index := range tables[0].Indexes {
|
||||||
if index.Type == schemas.UniqueType {
|
if index.Type == schemas.UniqueType {
|
||||||
|
|
|
@ -40,7 +40,7 @@ func TestFindOrgs(t *testing.T) {
|
||||||
IncludePrivate: false,
|
IncludePrivate: false,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, orgs, 0)
|
assert.Empty(t, orgs)
|
||||||
|
|
||||||
total, err := db.Count[organization.Organization](db.DefaultContext, organization.FindOrgOptions{
|
total, err := db.Count[organization.Organization](db.DefaultContext, organization.FindOrgOptions{
|
||||||
UserID: 4,
|
UserID: 4,
|
||||||
|
|
|
@ -283,7 +283,7 @@ func TestGetOrgUsersByOrgID(t *testing.T) {
|
||||||
OrgID: unittest.NonexistentID,
|
OrgID: unittest.NonexistentID,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, orgUsers, 0)
|
assert.Empty(t, orgUsers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChangeOrgUserStatus(t *testing.T) {
|
func TestChangeOrgUserStatus(t *testing.T) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ func TestAccessMode(t *testing.T) {
|
||||||
m := ParseAccessMode(name)
|
m := ParseAccessMode(name)
|
||||||
assert.Equal(t, AccessMode(i), m)
|
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, "owner", AccessModeOwner.ToString())
|
||||||
assert.Equal(t, AccessModeNone, ParseAccessMode("owner"))
|
assert.Equal(t, AccessModeNone, ParseAccessMode("owner"))
|
||||||
assert.Equal(t, AccessModeNone, ParseAccessMode("invalid"))
|
assert.Equal(t, AccessModeNone, ParseAccessMode("invalid"))
|
||||||
|
|
|
@ -5,7 +5,6 @@ package project
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
@ -66,7 +65,7 @@ func Test_moveIssuesToAnotherColumn(t *testing.T) {
|
||||||
|
|
||||||
issues, err = column1.GetIssues(db.DefaultContext)
|
issues, err = column1.GetIssues(db.DefaultContext)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, issues, 0)
|
assert.Empty(t, issues)
|
||||||
|
|
||||||
issues, err = column2.GetIssues(db.DefaultContext)
|
issues, err = column2.GetIssues(db.DefaultContext)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -123,5 +122,5 @@ func Test_NewColumn(t *testing.T) {
|
||||||
ProjectID: project1.ID,
|
ProjectID: project1.ID,
|
||||||
})
|
})
|
||||||
assert.Error(t, err)
|
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")
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,8 +144,8 @@ func TestGetRepositoryByURL(t *testing.T) {
|
||||||
assert.NotNil(t, repo)
|
assert.NotNil(t, repo)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, repo.ID, int64(2))
|
assert.Equal(t, int64(2), repo.ID)
|
||||||
assert.Equal(t, repo.OwnerID, int64(2))
|
assert.Equal(t, int64(2), repo.OwnerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
test(t, "https://try.gitea.io/user2/repo2")
|
test(t, "https://try.gitea.io/user2/repo2")
|
||||||
|
@ -159,8 +159,8 @@ func TestGetRepositoryByURL(t *testing.T) {
|
||||||
assert.NotNil(t, repo)
|
assert.NotNil(t, repo)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, repo.ID, int64(2))
|
assert.Equal(t, int64(2), repo.ID)
|
||||||
assert.Equal(t, repo.OwnerID, int64(2))
|
assert.Equal(t, int64(2), repo.OwnerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
test(t, "git+ssh://sshuser@try.gitea.io/user2/repo2")
|
test(t, "git+ssh://sshuser@try.gitea.io/user2/repo2")
|
||||||
|
@ -177,8 +177,8 @@ func TestGetRepositoryByURL(t *testing.T) {
|
||||||
assert.NotNil(t, repo)
|
assert.NotNil(t, repo)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, repo.ID, int64(2))
|
assert.Equal(t, int64(2), repo.ID)
|
||||||
assert.Equal(t, repo.OwnerID, int64(2))
|
assert.Equal(t, int64(2), repo.OwnerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
test(t, "sshuser@try.gitea.io:user2/repo2")
|
test(t, "sshuser@try.gitea.io:user2/repo2")
|
||||||
|
|
|
@ -52,7 +52,7 @@ func TestRepository_GetStargazers2(t *testing.T) {
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
||||||
gazers, err := repo_model.GetStargazers(db.DefaultContext, repo, db.ListOptions{Page: 0})
|
gazers, err := repo_model.GetStargazers(db.DefaultContext, repo, db.ListOptions{Page: 0})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, gazers, 0)
|
assert.Empty(t, gazers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClearRepoStars(t *testing.T) {
|
func TestClearRepoStars(t *testing.T) {
|
||||||
|
@ -71,5 +71,5 @@ func TestClearRepoStars(t *testing.T) {
|
||||||
|
|
||||||
gazers, err := repo_model.GetStargazers(db.DefaultContext, repo, db.ListOptions{Page: 0})
|
gazers, err := repo_model.GetStargazers(db.DefaultContext, repo, db.ListOptions{Page: 0})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, gazers, 0)
|
assert.Empty(t, gazers)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ func TestRepoAssignees(t *testing.T) {
|
||||||
users, err := repo_model.GetRepoAssignees(db.DefaultContext, repo2)
|
users, err := repo_model.GetRepoAssignees(db.DefaultContext, repo2)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, users, 1)
|
assert.Len(t, users, 1)
|
||||||
assert.Equal(t, users[0].ID, int64(2))
|
assert.Equal(t, int64(2), users[0].ID)
|
||||||
|
|
||||||
repo21 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 21})
|
repo21 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 21})
|
||||||
users, err = repo_model.GetRepoAssignees(db.DefaultContext, repo21)
|
users, err = repo_model.GetRepoAssignees(db.DefaultContext, repo21)
|
||||||
|
|
|
@ -41,7 +41,7 @@ func TestGetWatchers(t *testing.T) {
|
||||||
|
|
||||||
watches, err = repo_model.GetWatchers(db.DefaultContext, unittest.NonexistentID)
|
watches, err = repo_model.GetWatchers(db.DefaultContext, unittest.NonexistentID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, watches, 0)
|
assert.Empty(t, watches)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRepository_GetWatchers(t *testing.T) {
|
func TestRepository_GetWatchers(t *testing.T) {
|
||||||
|
@ -58,7 +58,7 @@ func TestRepository_GetWatchers(t *testing.T) {
|
||||||
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 9})
|
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 9})
|
||||||
watchers, err = repo_model.GetRepoWatchers(db.DefaultContext, repo.ID, db.ListOptions{Page: 1})
|
watchers, err = repo_model.GetRepoWatchers(db.DefaultContext, repo.ID, db.ListOptions{Page: 1})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, watchers, 0)
|
assert.Empty(t, watchers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWatchIfAuto(t *testing.T) {
|
func TestWatchIfAuto(t *testing.T) {
|
||||||
|
|
|
@ -79,7 +79,7 @@ func AssertExistsAndLoadMap(t assert.TestingT, table string, conditions ...any)
|
||||||
e := db.GetEngine(db.DefaultContext).Table(table)
|
e := db.GetEngine(db.DefaultContext).Table(table)
|
||||||
res, err := whereOrderConditions(e, conditions).Query()
|
res, err := whereOrderConditions(e, conditions).Query()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, len(res) == 1,
|
assert.Len(t, res, 1,
|
||||||
"Expected to find one row in %s (with conditions %+v), but found %d",
|
"Expected to find one row in %s (with conditions %+v), but found %d",
|
||||||
table, conditions, len(res),
|
table, conditions, len(res),
|
||||||
)
|
)
|
||||||
|
|
|
@ -97,8 +97,7 @@ func TestListEmails(t *testing.T) {
|
||||||
}
|
}
|
||||||
emails, count, err := user_model.SearchEmails(db.DefaultContext, opts)
|
emails, count, err := user_model.SearchEmails(db.DefaultContext, opts)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotEqual(t, int64(0), count)
|
assert.Greater(t, count, int64(5))
|
||||||
assert.True(t, count > 5)
|
|
||||||
|
|
||||||
contains := func(match func(s *user_model.SearchEmailResult) bool) bool {
|
contains := func(match func(s *user_model.SearchEmailResult) bool) bool {
|
||||||
for _, v := range emails {
|
for _, v := range emails {
|
||||||
|
|
|
@ -56,5 +56,5 @@ func TestSettings(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
settings, err = user_model.GetUserAllSettings(db.DefaultContext, 99)
|
settings, err = user_model.GetUserAllSettings(db.DefaultContext, 99)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, settings, 0)
|
assert.Empty(t, settings)
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,7 +201,7 @@ func TestNewGitSig(t *testing.T) {
|
||||||
assert.NotContains(t, sig.Name, "<")
|
assert.NotContains(t, sig.Name, "<")
|
||||||
assert.NotContains(t, sig.Name, ">")
|
assert.NotContains(t, sig.Name, ">")
|
||||||
assert.NotContains(t, sig.Name, "\n")
|
assert.NotContains(t, sig.Name, "\n")
|
||||||
assert.NotEqual(t, len(strings.TrimSpace(sig.Name)), 0)
|
assert.NotEmpty(t, strings.TrimSpace(sig.Name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ func TestDisplayName(t *testing.T) {
|
||||||
if len(strings.TrimSpace(user.FullName)) == 0 {
|
if len(strings.TrimSpace(user.FullName)) == 0 {
|
||||||
assert.Equal(t, user.Name, displayName)
|
assert.Equal(t, user.Name, displayName)
|
||||||
}
|
}
|
||||||
assert.NotEqual(t, len(strings.TrimSpace(displayName)), 0)
|
assert.NotEmpty(t, strings.TrimSpace(displayName))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,15 +322,15 @@ func TestGetMaileableUsersByIDs(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, results, 1)
|
assert.Len(t, results, 1)
|
||||||
if len(results) > 1 {
|
if len(results) > 1 {
|
||||||
assert.Equal(t, results[0].ID, 1)
|
assert.Equal(t, 1, results[0].ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
results, err = user_model.GetMaileableUsersByIDs(db.DefaultContext, []int64{1, 4}, true)
|
results, err = user_model.GetMaileableUsersByIDs(db.DefaultContext, []int64{1, 4}, true)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, results, 2)
|
assert.Len(t, results, 2)
|
||||||
if len(results) > 2 {
|
if len(results) > 2 {
|
||||||
assert.Equal(t, results[0].ID, 1)
|
assert.Equal(t, 1, results[0].ID)
|
||||||
assert.Equal(t, results[1].ID, 4)
|
assert.Equal(t, 4, results[1].ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,7 +499,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), "case: %+v", kase)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -570,11 +570,11 @@ func TestDisabledUserFeatures(t *testing.T) {
|
||||||
|
|
||||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
|
||||||
|
|
||||||
assert.Len(t, setting.Admin.UserDisabledFeatures.Values(), 0)
|
assert.Empty(t, setting.Admin.UserDisabledFeatures.Values())
|
||||||
|
|
||||||
// no features should be disabled with a plain login type
|
// no features should be disabled with a plain login type
|
||||||
assert.LessOrEqual(t, user.LoginType, auth.Plain)
|
assert.LessOrEqual(t, user.LoginType, auth.Plain)
|
||||||
assert.Len(t, user_model.DisabledFeaturesWithLoginType(user).Values(), 0)
|
assert.Empty(t, user_model.DisabledFeaturesWithLoginType(user).Values())
|
||||||
for _, f := range testValues.Values() {
|
for _, f := range testValues.Values() {
|
||||||
assert.False(t, user_model.IsFeatureDisabledWithLoginType(user, f))
|
assert.False(t, user_model.IsFeatureDisabledWithLoginType(user, f))
|
||||||
}
|
}
|
||||||
|
@ -600,5 +600,5 @@ func TestGetInactiveUsers(t *testing.T) {
|
||||||
interval := time.Now().Unix() - 1730468968 + 3600*24
|
interval := time.Now().Unix() - 1730468968 + 3600*24
|
||||||
users, err = user_model.GetInactiveUsers(db.DefaultContext, time.Duration(interval*int64(time.Second)))
|
users, err = user_model.GetInactiveUsers(db.DefaultContext, time.Duration(interval*int64(time.Second)))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, users, 0)
|
assert.Empty(t, users)
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ func TestWebhook_History(t *testing.T) {
|
||||||
webhook = unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 2})
|
webhook = unittest.AssertExistsAndLoadBean(t, &Webhook{ID: 2})
|
||||||
tasks, err = webhook.History(db.DefaultContext, 0)
|
tasks, err = webhook.History(db.DefaultContext, 0)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, tasks, 0)
|
assert.Empty(t, tasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWebhook_UpdateEvent(t *testing.T) {
|
func TestWebhook_UpdateEvent(t *testing.T) {
|
||||||
|
@ -206,7 +206,7 @@ func TestHookTasks(t *testing.T) {
|
||||||
|
|
||||||
hookTasks, err = HookTasks(db.DefaultContext, unittest.NonexistentID, 1)
|
hookTasks, err = HookTasks(db.DefaultContext, unittest.NonexistentID, 1)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, hookTasks, 0)
|
assert.Empty(t, hookTasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateHookTask(t *testing.T) {
|
func TestCreateHookTask(t *testing.T) {
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"regexp"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
@ -28,9 +27,9 @@ func TestActivityPubSignedPost(t *testing.T) {
|
||||||
|
|
||||||
expected := "BODY"
|
expected := "BODY"
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
assert.Regexp(t, regexp.MustCompile("^"+setting.Federation.DigestAlgorithm), r.Header.Get("Digest"))
|
assert.Regexp(t, "^"+setting.Federation.DigestAlgorithm, r.Header.Get("Digest"))
|
||||||
assert.Contains(t, r.Header.Get("Signature"), pubID)
|
assert.Contains(t, r.Header.Get("Signature"), pubID)
|
||||||
assert.Equal(t, r.Header.Get("Content-Type"), ActivityStreamsContentType)
|
assert.Equal(t, ActivityStreamsContentType, r.Header.Get("Content-Type"))
|
||||||
body, err := io.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, expected, string(body))
|
assert.Equal(t, expected, string(body))
|
||||||
|
|
|
@ -58,7 +58,7 @@ func TestLayered(t *testing.T) {
|
||||||
assertRead := func(expected string, expectedErr error, elems ...string) {
|
assertRead := func(expected string, expectedErr error, elems ...string) {
|
||||||
bs, err := assets.ReadFile(elems...)
|
bs, err := assets.ReadFile(elems...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
assert.ErrorAs(t, err, &expectedErr)
|
assert.ErrorIs(t, err, expectedErr)
|
||||||
} else {
|
} else {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, expected, string(bs))
|
assert.Equal(t, expected, string(bs))
|
||||||
|
|
|
@ -15,5 +15,5 @@ func TestPamAuth(t *testing.T) {
|
||||||
result, err := Auth("gitea", "user1", "false-pwd")
|
result, err := Auth("gitea", "user1", "false-pwd")
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.EqualError(t, err, "Authentication failure")
|
assert.EqualError(t, err, "Authentication failure")
|
||||||
assert.Len(t, result, 0)
|
assert.Len(t, result)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ func TestDummyHasher(t *testing.T) {
|
||||||
password, salt := "password", "ZogKvWdyEx"
|
password, salt := "password", "ZogKvWdyEx"
|
||||||
|
|
||||||
hash, err := dummy.Hash(password, salt)
|
hash, err := dummy.Hash(password, salt)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, hash, salt+":"+password)
|
assert.Equal(t, hash, salt+":"+password)
|
||||||
|
|
||||||
assert.True(t, dummy.VerifyPassword(password, hash, salt))
|
assert.True(t, dummy.VerifyPassword(password, hash, salt))
|
||||||
|
|
|
@ -6,7 +6,6 @@ package base
|
||||||
import (
|
import (
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -157,7 +156,7 @@ func TestStringsToInt64s(t *testing.T) {
|
||||||
testSuccess([]string{"1", "4", "16", "64", "256"}, []int64{1, 4, 16, 64, 256})
|
testSuccess([]string{"1", "4", "16", "64", "256"}, []int64{1, 4, 16, 64, 256})
|
||||||
|
|
||||||
ints, err := StringsToInt64s([]string{"-1", "a"})
|
ints, err := StringsToInt64s([]string{"-1", "a"})
|
||||||
assert.Len(t, ints, 0)
|
assert.Empty(t, ints)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,9 +171,9 @@ func TestInt64sToStrings(t *testing.T) {
|
||||||
// TODO: Test EntryIcon
|
// TODO: Test EntryIcon
|
||||||
|
|
||||||
func TestSetupGiteaRoot(t *testing.T) {
|
func TestSetupGiteaRoot(t *testing.T) {
|
||||||
_ = os.Setenv("GITEA_ROOT", "test")
|
t.Setenv("GITEA_ROOT", "test")
|
||||||
assert.Equal(t, "test", SetupGiteaRoot())
|
assert.Equal(t, "test", SetupGiteaRoot())
|
||||||
_ = os.Setenv("GITEA_ROOT", "")
|
t.Setenv("GITEA_ROOT", "")
|
||||||
assert.NotEqual(t, "test", SetupGiteaRoot())
|
assert.NotEqual(t, "test", SetupGiteaRoot())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ func TestPrepareFileNameAndType(t *testing.T) {
|
||||||
assert.Equal(t,
|
assert.Equal(t,
|
||||||
fmt.Sprintf("outFile=%s, outType=%s", expFile, expType),
|
fmt.Sprintf("outFile=%s, outType=%s", expFile, expType),
|
||||||
fmt.Sprintf("outFile=%s, outType=%s", outFile, outType),
|
fmt.Sprintf("outFile=%s, outType=%s", outFile, outType),
|
||||||
fmt.Sprintf("argFile=%s, argType=%s", argFile, argType),
|
"argFile=%s, argType=%s", argFile, argType,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ func TestHasPreviousCommitSha256(t *testing.T) {
|
||||||
parentSHA := MustIDFromString("b0ec7af4547047f12d5093e37ef8f1b3b5415ed8ee17894d43a34d7d34212e9c")
|
parentSHA := MustIDFromString("b0ec7af4547047f12d5093e37ef8f1b3b5415ed8ee17894d43a34d7d34212e9c")
|
||||||
notParentSHA := MustIDFromString("42e334efd04cd36eea6da0599913333c26116e1a537ca76e5b6e4af4dda00236")
|
notParentSHA := MustIDFromString("42e334efd04cd36eea6da0599913333c26116e1a537ca76e5b6e4af4dda00236")
|
||||||
assert.Equal(t, objectFormat, parentSHA.Type())
|
assert.Equal(t, objectFormat, parentSHA.Type())
|
||||||
assert.Equal(t, objectFormat.Name(), "sha256")
|
assert.Equal(t, "sha256", objectFormat.Name())
|
||||||
|
|
||||||
haz, err := commit.HasPreviousCommit(parentSHA)
|
haz, err := commit.HasPreviousCommit(parentSHA)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -343,9 +343,9 @@ func TestGetCommitFileStatusMerges(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, commitFileStatus.Added, expected.Added)
|
assert.Equal(t, expected.Added, commitFileStatus.Added)
|
||||||
assert.Equal(t, commitFileStatus.Removed, expected.Removed)
|
assert.Equal(t, expected.Removed, commitFileStatus.Removed)
|
||||||
assert.Equal(t, commitFileStatus.Modified, expected.Modified)
|
assert.Equal(t, expected.Modified, commitFileStatus.Modified)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_GetCommitBranchStart(t *testing.T) {
|
func Test_GetCommitBranchStart(t *testing.T) {
|
||||||
|
|
|
@ -73,9 +73,9 @@ func TestGrepSearch(t *testing.T) {
|
||||||
|
|
||||||
res, err = GrepSearch(context.Background(), repo, "no-such-content", GrepOptions{})
|
res, err = GrepSearch(context.Background(), repo, "no-such-content", GrepOptions{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, res, 0)
|
assert.Empty(t, res)
|
||||||
|
|
||||||
res, err = GrepSearch(context.Background(), &Repository{Path: "no-such-git-repo"}, "no-such-content", GrepOptions{})
|
res, err = GrepSearch(context.Background(), &Repository{Path: "no-such-git-repo"}, "no-such-content", GrepOptions{})
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Len(t, res, 0)
|
assert.Empty(t, res)
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,5 +100,5 @@ func TestParseTreeEntriesInvalid(t *testing.T) {
|
||||||
// there was a panic: "runtime error: slice bounds out of range" when the input was invalid: #20315
|
// there was a panic: "runtime error: slice bounds out of range" when the input was invalid: #20315
|
||||||
entries, err := ParseTreeEntries([]byte("100644 blob ea0d83c9081af9500ac9f804101b3fd0a5c293af"))
|
entries, err := ParseTreeEntries([]byte("100644 blob ea0d83c9081af9500ac9f804101b3fd0a5c293af"))
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Len(t, entries, 0)
|
assert.Empty(t, entries)
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ func TestRepository_GetBranches(t *testing.T) {
|
||||||
branches, countAll, err = bareRepo1.GetBranchNames(5, 1)
|
branches, countAll, err = bareRepo1.GetBranchNames(5, 1)
|
||||||
|
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, branches, 0)
|
assert.Empty(t, branches)
|
||||||
assert.EqualValues(t, 3, countAll)
|
assert.EqualValues(t, 3, countAll)
|
||||||
assert.ElementsMatch(t, []string{}, branches)
|
assert.ElementsMatch(t, []string{}, branches)
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func TestGetRefsBySha(t *testing.T) {
|
||||||
// do not exist
|
// do not exist
|
||||||
branches, err := bareRepo5.GetRefsBySha("8006ff9adbf0cb94da7dad9e537e53817f9fa5c0", "")
|
branches, err := bareRepo5.GetRefsBySha("8006ff9adbf0cb94da7dad9e537e53817f9fa5c0", "")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, branches, 0)
|
assert.Empty(t, branches)
|
||||||
|
|
||||||
// refs/pull/1/head
|
// refs/pull/1/head
|
||||||
branches, err = bareRepo5.GetRefsBySha("c83380d7056593c51a699d12b9c00627bd5743e9", PullPrefix)
|
branches, err = bareRepo5.GetRefsBySha("c83380d7056593c51a699d12b9c00627bd5743e9", PullPrefix)
|
||||||
|
|
|
@ -72,7 +72,7 @@ func TestReadPatch(t *testing.T) {
|
||||||
assert.Empty(t, noFile)
|
assert.Empty(t, noFile)
|
||||||
assert.Empty(t, noCommit)
|
assert.Empty(t, noCommit)
|
||||||
assert.Len(t, oldCommit, 40)
|
assert.Len(t, oldCommit, 40)
|
||||||
assert.True(t, oldCommit == "6e8e2a6f9efd71dbe6917816343ed8415ad696c3")
|
assert.Equal(t, "6e8e2a6f9efd71dbe6917816343ed8415ad696c3", oldCommit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadWritePullHead(t *testing.T) {
|
func TestReadWritePullHead(t *testing.T) {
|
||||||
|
@ -113,7 +113,7 @@ func TestReadWritePullHead(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Len(t, headContents, 40)
|
assert.Len(t, headContents, 40)
|
||||||
assert.True(t, headContents == newCommit)
|
assert.Equal(t, headContents, newCommit)
|
||||||
|
|
||||||
// Remove file after the test
|
// Remove file after the test
|
||||||
err = repo.RemoveReference(PullPrefix + "1/head")
|
err = repo.RemoveReference(PullPrefix + "1/head")
|
||||||
|
|
|
@ -113,7 +113,7 @@ var cases = []*testIndexerCase{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
assert.Equal(t, len(data), int(result.Total))
|
assert.Equal(t, len(data), int(result.Total))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -176,7 +176,7 @@ var cases = []*testIndexerCase{
|
||||||
IsPull: optional.Some(false),
|
IsPull: optional.Some(false),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.False(t, data[v.ID].IsPull)
|
assert.False(t, data[v.ID].IsPull)
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ var cases = []*testIndexerCase{
|
||||||
IsPull: optional.Some(true),
|
IsPull: optional.Some(true),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.True(t, data[v.ID].IsPull)
|
assert.True(t, data[v.ID].IsPull)
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ var cases = []*testIndexerCase{
|
||||||
IsClosed: optional.Some(false),
|
IsClosed: optional.Some(false),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.False(t, data[v.ID].IsClosed)
|
assert.False(t, data[v.ID].IsClosed)
|
||||||
}
|
}
|
||||||
|
@ -224,7 +224,7 @@ var cases = []*testIndexerCase{
|
||||||
IsClosed: optional.Some(true),
|
IsClosed: optional.Some(true),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.True(t, data[v.ID].IsClosed)
|
assert.True(t, data[v.ID].IsClosed)
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,7 @@ var cases = []*testIndexerCase{
|
||||||
MilestoneIDs: []int64{1, 2, 6},
|
MilestoneIDs: []int64{1, 2, 6},
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Contains(t, []int64{1, 2, 6}, data[v.ID].MilestoneID)
|
assert.Contains(t, []int64{1, 2, 6}, data[v.ID].MilestoneID)
|
||||||
}
|
}
|
||||||
|
@ -292,7 +292,7 @@ var cases = []*testIndexerCase{
|
||||||
MilestoneIDs: []int64{0},
|
MilestoneIDs: []int64{0},
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Equal(t, int64(0), data[v.ID].MilestoneID)
|
assert.Equal(t, int64(0), data[v.ID].MilestoneID)
|
||||||
}
|
}
|
||||||
|
@ -310,7 +310,7 @@ var cases = []*testIndexerCase{
|
||||||
ProjectID: optional.Some(int64(1)),
|
ProjectID: optional.Some(int64(1)),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Equal(t, int64(1), data[v.ID].ProjectID)
|
assert.Equal(t, int64(1), data[v.ID].ProjectID)
|
||||||
}
|
}
|
||||||
|
@ -328,7 +328,7 @@ var cases = []*testIndexerCase{
|
||||||
ProjectID: optional.Some(int64(0)),
|
ProjectID: optional.Some(int64(0)),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Equal(t, int64(0), data[v.ID].ProjectID)
|
assert.Equal(t, int64(0), data[v.ID].ProjectID)
|
||||||
}
|
}
|
||||||
|
@ -346,7 +346,7 @@ var cases = []*testIndexerCase{
|
||||||
ProjectColumnID: optional.Some(int64(1)),
|
ProjectColumnID: optional.Some(int64(1)),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Equal(t, int64(1), data[v.ID].ProjectColumnID)
|
assert.Equal(t, int64(1), data[v.ID].ProjectColumnID)
|
||||||
}
|
}
|
||||||
|
@ -364,7 +364,7 @@ var cases = []*testIndexerCase{
|
||||||
ProjectColumnID: optional.Some(int64(0)),
|
ProjectColumnID: optional.Some(int64(0)),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Equal(t, int64(0), data[v.ID].ProjectColumnID)
|
assert.Equal(t, int64(0), data[v.ID].ProjectColumnID)
|
||||||
}
|
}
|
||||||
|
@ -382,7 +382,7 @@ var cases = []*testIndexerCase{
|
||||||
PosterID: optional.Some(int64(1)),
|
PosterID: optional.Some(int64(1)),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Equal(t, int64(1), data[v.ID].PosterID)
|
assert.Equal(t, int64(1), data[v.ID].PosterID)
|
||||||
}
|
}
|
||||||
|
@ -400,7 +400,7 @@ var cases = []*testIndexerCase{
|
||||||
AssigneeID: optional.Some(int64(1)),
|
AssigneeID: optional.Some(int64(1)),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Equal(t, int64(1), data[v.ID].AssigneeID)
|
assert.Equal(t, int64(1), data[v.ID].AssigneeID)
|
||||||
}
|
}
|
||||||
|
@ -418,7 +418,7 @@ var cases = []*testIndexerCase{
|
||||||
AssigneeID: optional.Some(int64(0)),
|
AssigneeID: optional.Some(int64(0)),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Equal(t, int64(0), data[v.ID].AssigneeID)
|
assert.Equal(t, int64(0), data[v.ID].AssigneeID)
|
||||||
}
|
}
|
||||||
|
@ -436,7 +436,7 @@ var cases = []*testIndexerCase{
|
||||||
MentionID: optional.Some(int64(1)),
|
MentionID: optional.Some(int64(1)),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Contains(t, data[v.ID].MentionIDs, int64(1))
|
assert.Contains(t, data[v.ID].MentionIDs, int64(1))
|
||||||
}
|
}
|
||||||
|
@ -454,7 +454,7 @@ var cases = []*testIndexerCase{
|
||||||
ReviewedID: optional.Some(int64(1)),
|
ReviewedID: optional.Some(int64(1)),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Contains(t, data[v.ID].ReviewedIDs, int64(1))
|
assert.Contains(t, data[v.ID].ReviewedIDs, int64(1))
|
||||||
}
|
}
|
||||||
|
@ -472,7 +472,7 @@ var cases = []*testIndexerCase{
|
||||||
ReviewRequestedID: optional.Some(int64(1)),
|
ReviewRequestedID: optional.Some(int64(1)),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Contains(t, data[v.ID].ReviewRequestedIDs, int64(1))
|
assert.Contains(t, data[v.ID].ReviewRequestedIDs, int64(1))
|
||||||
}
|
}
|
||||||
|
@ -490,7 +490,7 @@ var cases = []*testIndexerCase{
|
||||||
SubscriberID: optional.Some(int64(1)),
|
SubscriberID: optional.Some(int64(1)),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.Contains(t, data[v.ID].SubscriberIDs, int64(1))
|
assert.Contains(t, data[v.ID].SubscriberIDs, int64(1))
|
||||||
}
|
}
|
||||||
|
@ -509,7 +509,7 @@ var cases = []*testIndexerCase{
|
||||||
UpdatedBeforeUnix: optional.Some(int64(30)),
|
UpdatedBeforeUnix: optional.Some(int64(30)),
|
||||||
},
|
},
|
||||||
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
Expected: func(t *testing.T, data map[int64]*internal.IndexerData, result *internal.SearchResult) {
|
||||||
assert.Equal(t, 5, len(result.Hits))
|
assert.Len(t, result.Hits, 5)
|
||||||
for _, v := range result.Hits {
|
for _, v := range result.Hits {
|
||||||
assert.GreaterOrEqual(t, data[v.ID].UpdatedUnix, int64(20))
|
assert.GreaterOrEqual(t, data[v.ID].UpdatedUnix, int64(20))
|
||||||
assert.LessOrEqual(t, data[v.ID].UpdatedUnix, int64(30))
|
assert.LessOrEqual(t, data[v.ID].UpdatedUnix, int64(30))
|
||||||
|
|
|
@ -96,7 +96,7 @@ func TestBasicTransferAdapter(t *testing.T) {
|
||||||
for n, c := range cases {
|
for n, c := range cases {
|
||||||
_, err := a.Download(context.Background(), c.link)
|
_, err := a.Download(context.Background(), c.link)
|
||||||
if len(c.expectederror) > 0 {
|
if len(c.expectederror) > 0 {
|
||||||
assert.True(t, strings.Contains(err.Error(), c.expectederror), "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
|
assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
|
||||||
} else {
|
} else {
|
||||||
assert.NoError(t, err, "case %d", n)
|
assert.NoError(t, err, "case %d", n)
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ func TestBasicTransferAdapter(t *testing.T) {
|
||||||
for n, c := range cases {
|
for n, c := range cases {
|
||||||
err := a.Upload(context.Background(), c.link, p, bytes.NewBufferString("dummy"))
|
err := a.Upload(context.Background(), c.link, p, bytes.NewBufferString("dummy"))
|
||||||
if len(c.expectederror) > 0 {
|
if len(c.expectederror) > 0 {
|
||||||
assert.True(t, strings.Contains(err.Error(), c.expectederror), "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
|
assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
|
||||||
} else {
|
} else {
|
||||||
assert.NoError(t, err, "case %d", n)
|
assert.NoError(t, err, "case %d", n)
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ func TestBasicTransferAdapter(t *testing.T) {
|
||||||
for n, c := range cases {
|
for n, c := range cases {
|
||||||
err := a.Verify(context.Background(), c.link, p)
|
err := a.Verify(context.Background(), c.link, p)
|
||||||
if len(c.expectederror) > 0 {
|
if len(c.expectederror) > 0 {
|
||||||
assert.True(t, strings.Contains(err.Error(), c.expectederror), "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
|
assert.Contains(t, err.Error(), c.expectederror, "case %d: '%s' should contain '%s'", n, err.Error(), c.expectederror)
|
||||||
} else {
|
} else {
|
||||||
assert.NoError(t, err, "case %d", n)
|
assert.NoError(t, err, "case %d", n)
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ func TestLogger(t *testing.T) {
|
||||||
logger := NewLoggerWithWriters(context.Background(), "test")
|
logger := NewLoggerWithWriters(context.Background(), "test")
|
||||||
|
|
||||||
dump := logger.DumpWriters()
|
dump := logger.DumpWriters()
|
||||||
assert.EqualValues(t, 0, len(dump))
|
assert.Empty(t, dump)
|
||||||
assert.EqualValues(t, NONE, logger.GetLevel())
|
assert.EqualValues(t, NONE, logger.GetLevel())
|
||||||
assert.False(t, logger.IsEnabled())
|
assert.False(t, logger.IsEnabled())
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ func TestLogger(t *testing.T) {
|
||||||
assert.EqualValues(t, DEBUG, logger.GetLevel())
|
assert.EqualValues(t, DEBUG, logger.GetLevel())
|
||||||
|
|
||||||
dump = logger.DumpWriters()
|
dump = logger.DumpWriters()
|
||||||
assert.EqualValues(t, 2, len(dump))
|
assert.Len(t, dump, 2)
|
||||||
|
|
||||||
logger.Trace("trace-level") // this level is not logged
|
logger.Trace("trace-level") // this level is not logged
|
||||||
logger.Debug("debug-level")
|
logger.Debug("debug-level")
|
||||||
|
|
|
@ -278,12 +278,12 @@ func TestRender_AutoLink(t *testing.T) {
|
||||||
test := func(input, expected string) {
|
test := func(input, expected string) {
|
||||||
var buffer strings.Builder
|
var buffer strings.Builder
|
||||||
err := PostProcessDefault(NewTestRenderContext(localMetas), strings.NewReader(input), &buffer)
|
err := PostProcessDefault(NewTestRenderContext(localMetas), strings.NewReader(input), &buffer)
|
||||||
assert.Equal(t, err, nil)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer.String()))
|
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer.String()))
|
||||||
|
|
||||||
buffer.Reset()
|
buffer.Reset()
|
||||||
err = PostProcessDefault(NewTestRenderContext(localMetas), strings.NewReader(input), &buffer)
|
err = PostProcessDefault(NewTestRenderContext(localMetas), strings.NewReader(input), &buffer)
|
||||||
assert.Equal(t, err, nil)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer.String()))
|
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class ConanPackageConan(ConanFile):
|
||||||
|
|
||||||
func TestParseConanfile(t *testing.T) {
|
func TestParseConanfile(t *testing.T) {
|
||||||
metadata, err := ParseConanfile(strings.NewReader(contentConanfile))
|
metadata, err := ParseConanfile(strings.NewReader(contentConanfile))
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, license, metadata.License)
|
assert.Equal(t, license, metadata.License)
|
||||||
assert.Equal(t, author, metadata.Author)
|
assert.Equal(t, author, metadata.Author)
|
||||||
assert.Equal(t, homepage, metadata.ProjectURL)
|
assert.Equal(t, homepage, metadata.ProjectURL)
|
||||||
|
|
|
@ -50,7 +50,7 @@ const (
|
||||||
func TestParseConaninfo(t *testing.T) {
|
func TestParseConaninfo(t *testing.T) {
|
||||||
info, err := ParseConaninfo(strings.NewReader(contentConaninfo))
|
info, err := ParseConaninfo(strings.NewReader(contentConaninfo))
|
||||||
assert.NotNil(t, info)
|
assert.NotNil(t, info)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(
|
assert.Equal(
|
||||||
t,
|
t,
|
||||||
map[string]string{
|
map[string]string{
|
||||||
|
|
|
@ -46,10 +46,10 @@ func testQueueBasic(t *testing.T, newFn func(cfg *BaseConfig) (baseQueue, error)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
if !isUnique {
|
if !isUnique {
|
||||||
assert.EqualValues(t, 2, cnt)
|
assert.EqualValues(t, 2, cnt)
|
||||||
assert.EqualValues(t, false, has) // non-unique queues don't check for duplicates
|
assert.False(t, has) // non-unique queues don't check for duplicates
|
||||||
} else {
|
} else {
|
||||||
assert.EqualValues(t, 1, cnt)
|
assert.EqualValues(t, 1, cnt)
|
||||||
assert.EqualValues(t, true, has)
|
assert.True(t, has)
|
||||||
}
|
}
|
||||||
|
|
||||||
// push another item
|
// push another item
|
||||||
|
@ -101,7 +101,7 @@ func testQueueBasic(t *testing.T, newFn func(cfg *BaseConfig) (baseQueue, error)
|
||||||
pushBlockTime = 30 * time.Millisecond
|
pushBlockTime = 30 * time.Millisecond
|
||||||
err = q.PushItem(ctx, []byte("item-full"))
|
err = q.PushItem(ctx, []byte("item-full"))
|
||||||
assert.ErrorIs(t, err, context.DeadlineExceeded)
|
assert.ErrorIs(t, err, context.DeadlineExceeded)
|
||||||
assert.True(t, time.Since(timeStart) >= pushBlockTime*2/3)
|
assert.GreaterOrEqual(t, time.Since(timeStart), pushBlockTime*2/3)
|
||||||
pushBlockTime = oldPushBlockTime
|
pushBlockTime = oldPushBlockTime
|
||||||
|
|
||||||
// remove all
|
// remove all
|
||||||
|
|
|
@ -172,8 +172,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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -526,7 +526,7 @@ func TestCustomizeCloseKeywords(t *testing.T) {
|
||||||
|
|
||||||
func TestParseCloseKeywords(t *testing.T) {
|
func TestParseCloseKeywords(t *testing.T) {
|
||||||
// Test parsing of CloseKeywords and ReopenKeywords
|
// Test parsing of CloseKeywords and ReopenKeywords
|
||||||
assert.Len(t, parseKeywords([]string{""}), 0)
|
assert.Empty(t, parseKeywords([]string{""}))
|
||||||
assert.Len(t, parseKeywords([]string{" aa ", " bb ", "99", "#", "", "this is", "cc"}), 3)
|
assert.Len(t, parseKeywords([]string{" aa ", " bb ", "99", "#", "", "this is", "cc"}), 3)
|
||||||
|
|
||||||
for _, test := range []struct {
|
for _, test := range []struct {
|
||||||
|
|
|
@ -62,15 +62,15 @@ func Test_calcSync(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
inserts, deletes, updates := calcSync(gitTags, dbReleases)
|
inserts, deletes, updates := calcSync(gitTags, dbReleases)
|
||||||
if assert.EqualValues(t, 1, len(inserts), "inserts") {
|
if assert.Len(t, inserts, 1, "inserts") {
|
||||||
assert.EqualValues(t, *gitTags[2], *inserts[0], "inserts equal")
|
assert.EqualValues(t, *gitTags[2], *inserts[0], "inserts equal")
|
||||||
}
|
}
|
||||||
|
|
||||||
if assert.EqualValues(t, 1, len(deletes), "deletes") {
|
if assert.Len(t, deletes, 1, "deletes") {
|
||||||
assert.EqualValues(t, 1, deletes[0], "deletes equal")
|
assert.EqualValues(t, 1, deletes[0], "deletes equal")
|
||||||
}
|
}
|
||||||
|
|
||||||
if assert.EqualValues(t, 1, len(updates), "updates") {
|
if assert.Len(t, updates, 1, "updates") {
|
||||||
assert.EqualValues(t, *gitTags[1], *updates[0], "updates equal")
|
assert.EqualValues(t, *gitTags[1], *updates[0], "updates equal")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,6 @@ EXTEND = true
|
||||||
_, err = getCronSettings(cfg, "test", extended)
|
_, err = getCronSettings(cfg, "test", extended)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, extended.Base)
|
assert.True(t, extended.Base)
|
||||||
assert.EqualValues(t, extended.Second, "white rabbit")
|
assert.EqualValues(t, "white rabbit", extended.Second)
|
||||||
assert.True(t, extended.Extend)
|
assert.True(t, extended.Extend)
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,5 +74,5 @@ DEFAULT_APPLICATIONS = tea
|
||||||
DEFAULT_APPLICATIONS =
|
DEFAULT_APPLICATIONS =
|
||||||
`)
|
`)
|
||||||
loadOAuth2From(cfg)
|
loadOAuth2From(cfg)
|
||||||
assert.Nil(t, nil, OAuth2.DefaultApplications)
|
assert.Nil(t, OAuth2.DefaultApplications)
|
||||||
}
|
}
|
||||||
|
|
|
@ -447,7 +447,7 @@ MINIO_USE_SSL = true
|
||||||
assert.NoError(t, loadRepoArchiveFrom(cfg))
|
assert.NoError(t, loadRepoArchiveFrom(cfg))
|
||||||
assert.EqualValues(t, "my_access_key", RepoArchive.Storage.MinioConfig.AccessKeyID)
|
assert.EqualValues(t, "my_access_key", RepoArchive.Storage.MinioConfig.AccessKeyID)
|
||||||
assert.EqualValues(t, "my_secret_key", RepoArchive.Storage.MinioConfig.SecretAccessKey)
|
assert.EqualValues(t, "my_secret_key", RepoArchive.Storage.MinioConfig.SecretAccessKey)
|
||||||
assert.EqualValues(t, true, RepoArchive.Storage.MinioConfig.UseSSL)
|
assert.True(t, RepoArchive.Storage.MinioConfig.UseSSL)
|
||||||
assert.EqualValues(t, "repo-archive/", RepoArchive.Storage.MinioConfig.BasePath)
|
assert.EqualValues(t, "repo-archive/", RepoArchive.Storage.MinioConfig.BasePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ MINIO_BASE_PATH = /prefix
|
||||||
assert.NoError(t, loadRepoArchiveFrom(cfg))
|
assert.NoError(t, loadRepoArchiveFrom(cfg))
|
||||||
assert.EqualValues(t, "my_access_key", RepoArchive.Storage.MinioConfig.AccessKeyID)
|
assert.EqualValues(t, "my_access_key", RepoArchive.Storage.MinioConfig.AccessKeyID)
|
||||||
assert.EqualValues(t, "my_secret_key", RepoArchive.Storage.MinioConfig.SecretAccessKey)
|
assert.EqualValues(t, "my_secret_key", RepoArchive.Storage.MinioConfig.SecretAccessKey)
|
||||||
assert.EqualValues(t, true, RepoArchive.Storage.MinioConfig.UseSSL)
|
assert.True(t, RepoArchive.Storage.MinioConfig.UseSSL)
|
||||||
assert.EqualValues(t, "/prefix/repo-archive/", RepoArchive.Storage.MinioConfig.BasePath)
|
assert.EqualValues(t, "/prefix/repo-archive/", RepoArchive.Storage.MinioConfig.BasePath)
|
||||||
|
|
||||||
cfg, err = NewConfigProviderFromData(`
|
cfg, err = NewConfigProviderFromData(`
|
||||||
|
@ -477,7 +477,7 @@ MINIO_BASE_PATH = /prefix
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NoError(t, loadRepoArchiveFrom(cfg))
|
assert.NoError(t, loadRepoArchiveFrom(cfg))
|
||||||
assert.EqualValues(t, "127.0.0.1", RepoArchive.Storage.MinioConfig.IamEndpoint)
|
assert.EqualValues(t, "127.0.0.1", RepoArchive.Storage.MinioConfig.IamEndpoint)
|
||||||
assert.EqualValues(t, true, RepoArchive.Storage.MinioConfig.UseSSL)
|
assert.True(t, RepoArchive.Storage.MinioConfig.UseSSL)
|
||||||
assert.EqualValues(t, "/prefix/repo-archive/", RepoArchive.Storage.MinioConfig.BasePath)
|
assert.EqualValues(t, "/prefix/repo-archive/", RepoArchive.Storage.MinioConfig.BasePath)
|
||||||
|
|
||||||
cfg, err = NewConfigProviderFromData(`
|
cfg, err = NewConfigProviderFromData(`
|
||||||
|
@ -495,7 +495,7 @@ MINIO_BASE_PATH = /lfs
|
||||||
assert.NoError(t, loadLFSFrom(cfg))
|
assert.NoError(t, loadLFSFrom(cfg))
|
||||||
assert.EqualValues(t, "my_access_key", LFS.Storage.MinioConfig.AccessKeyID)
|
assert.EqualValues(t, "my_access_key", LFS.Storage.MinioConfig.AccessKeyID)
|
||||||
assert.EqualValues(t, "my_secret_key", LFS.Storage.MinioConfig.SecretAccessKey)
|
assert.EqualValues(t, "my_secret_key", LFS.Storage.MinioConfig.SecretAccessKey)
|
||||||
assert.EqualValues(t, true, LFS.Storage.MinioConfig.UseSSL)
|
assert.True(t, LFS.Storage.MinioConfig.UseSSL)
|
||||||
assert.EqualValues(t, "/lfs", LFS.Storage.MinioConfig.BasePath)
|
assert.EqualValues(t, "/lfs", LFS.Storage.MinioConfig.BasePath)
|
||||||
|
|
||||||
cfg, err = NewConfigProviderFromData(`
|
cfg, err = NewConfigProviderFromData(`
|
||||||
|
@ -513,7 +513,7 @@ MINIO_BASE_PATH = /lfs
|
||||||
assert.NoError(t, loadLFSFrom(cfg))
|
assert.NoError(t, loadLFSFrom(cfg))
|
||||||
assert.EqualValues(t, "my_access_key", LFS.Storage.MinioConfig.AccessKeyID)
|
assert.EqualValues(t, "my_access_key", LFS.Storage.MinioConfig.AccessKeyID)
|
||||||
assert.EqualValues(t, "my_secret_key", LFS.Storage.MinioConfig.SecretAccessKey)
|
assert.EqualValues(t, "my_secret_key", LFS.Storage.MinioConfig.SecretAccessKey)
|
||||||
assert.EqualValues(t, true, LFS.Storage.MinioConfig.UseSSL)
|
assert.True(t, LFS.Storage.MinioConfig.UseSSL)
|
||||||
assert.EqualValues(t, "/lfs", LFS.Storage.MinioConfig.BasePath)
|
assert.EqualValues(t, "/lfs", LFS.Storage.MinioConfig.BasePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -36,7 +35,7 @@ func TestCurrentUsername(t *testing.T) {
|
||||||
if user != whoami {
|
if user != whoami {
|
||||||
t.Errorf("expected %s as user, got: %s", whoami, user)
|
t.Errorf("expected %s as user, got: %s", whoami, user)
|
||||||
}
|
}
|
||||||
os.Setenv("USER", "spoofed")
|
t.Setenv("USER", "spoofed")
|
||||||
user = CurrentUsername()
|
user = CurrentUsername()
|
||||||
if user != whoami {
|
if user != whoami {
|
||||||
t.Errorf("expected %s as user, got: %s", whoami, user)
|
t.Errorf("expected %s as user, got: %s", whoami, user)
|
||||||
|
|
|
@ -27,9 +27,9 @@ func Test_HexToRBGColor(t *testing.T) {
|
||||||
}
|
}
|
||||||
for n, c := range cases {
|
for n, c := range cases {
|
||||||
r, g, b := HexToRBGColor(c.colorString)
|
r, g, b := HexToRBGColor(c.colorString)
|
||||||
assert.Equal(t, c.expectedR, r, "case %d: error R should match: expected %f, but get %f", n, c.expectedR, r)
|
assert.InDelta(t, c.expectedR, r, 0, "case %d: error R should match: expected %f, but get %f", n, c.expectedR, r)
|
||||||
assert.Equal(t, c.expectedG, g, "case %d: error G should match: expected %f, but get %f", n, c.expectedG, g)
|
assert.InDelta(t, c.expectedG, g, 0, "case %d: error G should match: expected %f, but get %f", n, c.expectedG, g)
|
||||||
assert.Equal(t, c.expectedB, b, "case %d: error B should match: expected %f, but get %f", n, c.expectedB, b)
|
assert.InDelta(t, c.expectedB, b, 0, "case %d: error B should match: expected %f, but get %f", n, c.expectedB, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"regexp"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -23,8 +22,8 @@ func TestKeygen(t *testing.T) {
|
||||||
assert.NotEmpty(t, priv)
|
assert.NotEmpty(t, priv)
|
||||||
assert.NotEmpty(t, pub)
|
assert.NotEmpty(t, pub)
|
||||||
|
|
||||||
assert.Regexp(t, regexp.MustCompile("^-----BEGIN RSA PRIVATE KEY-----.*"), priv)
|
assert.Regexp(t, "^-----BEGIN RSA PRIVATE KEY-----.*", priv)
|
||||||
assert.Regexp(t, regexp.MustCompile("^-----BEGIN PUBLIC KEY-----.*"), pub)
|
assert.Regexp(t, "^-----BEGIN PUBLIC KEY-----.*", pub)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSignUsingKeys(t *testing.T) {
|
func TestSignUsingKeys(t *testing.T) {
|
||||||
|
|
|
@ -27,9 +27,9 @@ func TestTimeStr(t *testing.T) {
|
||||||
t.Run(test.input, func(t *testing.T) {
|
t.Run(test.input, func(t *testing.T) {
|
||||||
output, err := TimeEstimateParse(test.input)
|
output, err := TimeEstimateParse(test.input)
|
||||||
if test.err {
|
if test.err {
|
||||||
assert.NotNil(t, err)
|
assert.Error(t, err)
|
||||||
} else {
|
} else {
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
assert.Equal(t, test.output, output)
|
assert.Equal(t, test.output, output)
|
||||||
})
|
})
|
||||||
|
|
|
@ -122,8 +122,8 @@ func Test_NormalizeEOL(t *testing.T) {
|
||||||
|
|
||||||
func Test_RandomInt(t *testing.T) {
|
func Test_RandomInt(t *testing.T) {
|
||||||
randInt, err := CryptoRandomInt(255)
|
randInt, err := CryptoRandomInt(255)
|
||||||
assert.True(t, randInt >= 0)
|
assert.GreaterOrEqual(t, randInt, int64(0))
|
||||||
assert.True(t, randInt <= 255)
|
assert.LessOrEqual(t, randInt, int64(255))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,22 +223,22 @@ func BenchmarkToUpper(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestToTitleCase(t *testing.T) {
|
func TestToTitleCase(t *testing.T) {
|
||||||
assert.Equal(t, ToTitleCase(`foo bar baz`), `Foo Bar Baz`)
|
assert.Equal(t, `Foo Bar Baz`, ToTitleCase(`foo bar baz`))
|
||||||
assert.Equal(t, ToTitleCase(`FOO BAR BAZ`), `Foo Bar Baz`)
|
assert.Equal(t, `Foo Bar Baz`, ToTitleCase(`FOO BAR BAZ`))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestToPointer(t *testing.T) {
|
func TestToPointer(t *testing.T) {
|
||||||
assert.Equal(t, "abc", *ToPointer("abc"))
|
assert.Equal(t, "abc", *ToPointer("abc"))
|
||||||
assert.Equal(t, 123, *ToPointer(123))
|
assert.Equal(t, 123, *ToPointer(123))
|
||||||
abc := "abc"
|
abc := "abc"
|
||||||
assert.False(t, &abc == ToPointer(abc))
|
assert.NotSame(t, &abc, ToPointer(abc))
|
||||||
val123 := 123
|
val123 := 123
|
||||||
assert.False(t, &val123 == ToPointer(val123))
|
assert.NotSame(t, &val123, ToPointer(val123))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReserveLineBreakForTextarea(t *testing.T) {
|
func TestReserveLineBreakForTextarea(t *testing.T) {
|
||||||
assert.Equal(t, ReserveLineBreakForTextarea("test\r\ndata"), "test\ndata")
|
assert.Equal(t, "test\ndata", ReserveLineBreakForTextarea("test\r\ndata"))
|
||||||
assert.Equal(t, ReserveLineBreakForTextarea("test\r\ndata\r\n"), "test\ndata\n")
|
assert.Equal(t, "test\ndata\n", ReserveLineBreakForTextarea("test\r\ndata\r\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOptionalArg(t *testing.T) {
|
func TestOptionalArg(t *testing.T) {
|
||||||
|
|
|
@ -39,7 +39,7 @@ func TestHandlePullRequestMerging(t *testing.T) {
|
||||||
}, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, []*repo_module.PushUpdateOptions{
|
}, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, []*repo_module.PushUpdateOptions{
|
||||||
{NewCommitID: "01234567"},
|
{NewCommitID: "01234567"},
|
||||||
})
|
})
|
||||||
assert.Equal(t, 0, len(resp.Body.String()))
|
assert.Empty(t, resp.Body.String())
|
||||||
pr, err = issues_model.GetPullRequestByID(db.DefaultContext, pr.ID)
|
pr, err = issues_model.GetPullRequestByID(db.DefaultContext, pr.ID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, pr.HasMerged)
|
assert.True(t, pr.HasMerged)
|
||||||
|
|
|
@ -135,7 +135,7 @@ func TestNewWikiPost(t *testing.T) {
|
||||||
NewWikiPost(ctx)
|
NewWikiPost(ctx)
|
||||||
assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
|
assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
|
||||||
assertWikiExists(t, ctx.Repo.Repository, wiki_service.UserTitleToWebPath("", title))
|
assertWikiExists(t, ctx.Repo.Repository, wiki_service.UserTitleToWebPath("", title))
|
||||||
assert.Equal(t, wikiContent(t, ctx.Repo.Repository, wiki_service.UserTitleToWebPath("", title)), content)
|
assert.Equal(t, content, wikiContent(t, ctx.Repo.Repository, wiki_service.UserTitleToWebPath("", title)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ func TestEditWikiPost(t *testing.T) {
|
||||||
EditWikiPost(ctx)
|
EditWikiPost(ctx)
|
||||||
assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
|
assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
|
||||||
assertWikiExists(t, ctx.Repo.Repository, wiki_service.UserTitleToWebPath("", title))
|
assertWikiExists(t, ctx.Repo.Repository, wiki_service.UserTitleToWebPath("", title))
|
||||||
assert.Equal(t, wikiContent(t, ctx.Repo.Repository, wiki_service.UserTitleToWebPath("", title)), content)
|
assert.Equal(t, content, wikiContent(t, ctx.Repo.Repository, wiki_service.UserTitleToWebPath("", title)))
|
||||||
if title != "Home" {
|
if title != "Home" {
|
||||||
assertWikiNotExists(t, ctx.Repo.Repository, "Home")
|
assertWikiNotExists(t, ctx.Repo.Repository, "Home")
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,19 +17,19 @@ import (
|
||||||
func TestCreateAuthorizationToken(t *testing.T) {
|
func TestCreateAuthorizationToken(t *testing.T) {
|
||||||
var taskID int64 = 23
|
var taskID int64 = 23
|
||||||
token, err := CreateAuthorizationToken(taskID, 1, 2)
|
token, err := CreateAuthorizationToken(taskID, 1, 2)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotEqual(t, "", token)
|
assert.NotEqual(t, "", token)
|
||||||
claims := jwt.MapClaims{}
|
claims := jwt.MapClaims{}
|
||||||
_, err = jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (any, error) {
|
_, err = jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (any, error) {
|
||||||
return setting.GetGeneralTokenSigningSecret(), nil
|
return setting.GetGeneralTokenSigningSecret(), nil
|
||||||
})
|
})
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
scp, ok := claims["scp"]
|
scp, ok := claims["scp"]
|
||||||
assert.True(t, ok, "Has scp claim in jwt token")
|
assert.True(t, ok, "Has scp claim in jwt token")
|
||||||
assert.Contains(t, scp, "Actions.Results:1:2")
|
assert.Contains(t, scp, "Actions.Results:1:2")
|
||||||
taskIDClaim, ok := claims["TaskID"]
|
taskIDClaim, ok := claims["TaskID"]
|
||||||
assert.True(t, ok, "Has TaskID claim in jwt token")
|
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"]
|
acClaim, ok := claims["ac"]
|
||||||
assert.True(t, ok, "Has ac claim in jwt token")
|
assert.True(t, ok, "Has ac claim in jwt token")
|
||||||
ac, ok := acClaim.(string)
|
ac, ok := acClaim.(string)
|
||||||
|
@ -43,14 +43,14 @@ func TestCreateAuthorizationToken(t *testing.T) {
|
||||||
func TestParseAuthorizationToken(t *testing.T) {
|
func TestParseAuthorizationToken(t *testing.T) {
|
||||||
var taskID int64 = 23
|
var taskID int64 = 23
|
||||||
token, err := CreateAuthorizationToken(taskID, 1, 2)
|
token, err := CreateAuthorizationToken(taskID, 1, 2)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotEqual(t, "", token)
|
assert.NotEqual(t, "", token)
|
||||||
headers := http.Header{}
|
headers := http.Header{}
|
||||||
headers.Set("Authorization", "Bearer "+token)
|
headers.Set("Authorization", "Bearer "+token)
|
||||||
rTaskID, err := ParseAuthorizationToken(&http.Request{
|
rTaskID, err := ParseAuthorizationToken(&http.Request{
|
||||||
Header: headers,
|
Header: headers,
|
||||||
})
|
})
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, taskID, rTaskID)
|
assert.Equal(t, taskID, rTaskID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,6 @@ func TestParseAuthorizationTokenNoAuthHeader(t *testing.T) {
|
||||||
rTaskID, err := ParseAuthorizationToken(&http.Request{
|
rTaskID, err := ParseAuthorizationToken(&http.Request{
|
||||||
Header: headers,
|
Header: headers,
|
||||||
})
|
})
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, int64(0), rTaskID)
|
assert.Equal(t, int64(0), rTaskID)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ func TestUserIDFromToken(t *testing.T) {
|
||||||
o := OAuth2{}
|
o := OAuth2{}
|
||||||
uid := o.userIDFromToken(context.Background(), token, ds)
|
uid := o.userIDFromToken(context.Background(), token, ds)
|
||||||
assert.Equal(t, int64(user_model.ActionsUserID), uid)
|
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))
|
assert.Equal(t, ds["ActionsTaskID"], int64(RunningTaskID))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,8 @@ func TestSource(t *testing.T) {
|
||||||
ok, err := user_model.GetExternalLogin(context.Background(), e)
|
ok, err := user_model.GetExternalLogin(context.Background(), e)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
assert.Equal(t, e.RefreshToken, "refresh")
|
assert.Equal(t, "refresh", e.RefreshToken)
|
||||||
assert.Equal(t, e.AccessToken, "token")
|
assert.Equal(t, "token", e.AccessToken)
|
||||||
|
|
||||||
u, err := user_model.GetUserByID(context.Background(), user.ID)
|
u, err := user_model.GetUserByID(context.Background(), user.ID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@ -89,8 +89,8 @@ func TestSource(t *testing.T) {
|
||||||
ok, err := user_model.GetExternalLogin(context.Background(), e)
|
ok, err := user_model.GetExternalLogin(context.Background(), e)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, ok)
|
assert.True(t, ok)
|
||||||
assert.Equal(t, e.RefreshToken, "")
|
assert.Equal(t, "", e.RefreshToken)
|
||||||
assert.Equal(t, e.AccessToken, "")
|
assert.Equal(t, "", e.AccessToken)
|
||||||
|
|
||||||
u, err := user_model.GetUserByID(context.Background(), user.ID)
|
u, err := user_model.GetUserByID(context.Background(), user.ID)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -40,7 +40,7 @@ func Test_ToPullReview(t *testing.T) {
|
||||||
user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
|
user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
|
||||||
prList, err := ToPullReviewList(db.DefaultContext, reviewList, user4)
|
prList, err := ToPullReviewList(db.DefaultContext, reviewList, user4)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, prList, 0)
|
assert.Empty(t, prList)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Admin User", func(t *testing.T) {
|
t.Run("Admin User", func(t *testing.T) {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAddTaskToScheduler(t *testing.T) {
|
func TestAddTaskToScheduler(t *testing.T) {
|
||||||
assert.Len(t, scheduler.Jobs(), 0)
|
assert.Empty(t, scheduler.Jobs())
|
||||||
defer scheduler.Clear()
|
defer scheduler.Clear()
|
||||||
|
|
||||||
// no seconds
|
// no seconds
|
||||||
|
|
|
@ -41,7 +41,7 @@ func TestGetFeeds(t *testing.T) {
|
||||||
OnlyPerformedBy: false,
|
OnlyPerformedBy: false,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, actions, 0)
|
assert.Empty(t, actions)
|
||||||
assert.Equal(t, int64(0), count)
|
assert.Equal(t, int64(0), count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ func TestGetFeedsForRepos(t *testing.T) {
|
||||||
IncludePrivate: true,
|
IncludePrivate: true,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, actions, 0)
|
assert.Empty(t, actions)
|
||||||
assert.Equal(t, int64(0), count)
|
assert.Equal(t, int64(0), count)
|
||||||
|
|
||||||
// public repo & no login
|
// public repo & no login
|
||||||
|
@ -119,7 +119,7 @@ func TestGetFeeds2(t *testing.T) {
|
||||||
IncludeDeleted: true,
|
IncludeDeleted: true,
|
||||||
})
|
})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, actions, 0)
|
assert.Empty(t, actions)
|
||||||
assert.Equal(t, int64(0), count)
|
assert.Equal(t, int64(0), count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
package gitdiff
|
package gitdiff
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -643,9 +642,9 @@ func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) {
|
||||||
MaxFiles: setting.Git.MaxGitDiffFiles,
|
MaxFiles: setting.Git.MaxGitDiffFiles,
|
||||||
WhitespaceBehavior: behavior,
|
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 {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ func TestGitlabDownloadRepo(t *testing.T) {
|
||||||
|
|
||||||
topics, err := downloader.GetTopics()
|
topics, err := downloader.GetTopics()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, len(topics) == 2)
|
assert.Len(t, topics, 2)
|
||||||
assert.EqualValues(t, []string{"migration", "test"}, topics)
|
assert.EqualValues(t, []string{"migration", "test"}, topics)
|
||||||
|
|
||||||
milestones, err := downloader.GetMilestones()
|
milestones, err := downloader.GetMilestones()
|
||||||
|
|
|
@ -121,7 +121,7 @@ func TestDeleteTeam(t *testing.T) {
|
||||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
||||||
accessMode, err := access_model.AccessLevel(db.DefaultContext, user, repo)
|
accessMode, err := access_model.AccessLevel(db.DefaultContext, user, repo)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.True(t, accessMode < perm.AccessModeWrite)
|
assert.Less(t, accessMode, perm.AccessModeWrite)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddTeamMember(t *testing.T) {
|
func TestAddTeamMember(t *testing.T) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ func TestRepoGetReviewers(t *testing.T) {
|
||||||
// should not include doer and remove the poster
|
// should not include doer and remove the poster
|
||||||
reviewers, err = pull_service.GetReviewers(ctx, repo1, 11, 2)
|
reviewers, err = pull_service.GetReviewers(ctx, repo1, 11, 2)
|
||||||
assert.NoError(t, err)
|
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
|
// should not include PR poster, if PR poster would be otherwise eligible
|
||||||
reviewers, err = pull_service.GetReviewers(ctx, repo1, 11, 4)
|
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)
|
reviewers, err = pull_service.GetReviewers(ctx, repo2, 2, 4)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, reviewers, 1)
|
assert.Len(t, reviewers, 1)
|
||||||
assert.EqualValues(t, reviewers[0].ID, 2)
|
assert.EqualValues(t, 2, reviewers[0].ID)
|
||||||
|
|
||||||
// test private org repo
|
// test private org repo
|
||||||
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
repo3 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
||||||
|
|
|
@ -228,7 +228,7 @@ func TestRelease_Update(t *testing.T) {
|
||||||
IsTag: false,
|
IsTag: false,
|
||||||
}
|
}
|
||||||
assert.NoError(t, CreateRelease(gitRepo, release, nil, ""))
|
assert.NoError(t, CreateRelease(gitRepo, release, nil, ""))
|
||||||
assert.Greater(t, release.ID, int64(0))
|
assert.Positive(t, release.ID)
|
||||||
|
|
||||||
release.IsDraft = false
|
release.IsDraft = false
|
||||||
tagName := release.TagName
|
tagName := release.TagName
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
package archiver
|
package archiver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -121,7 +120,7 @@ func TestArchive_Basic(t *testing.T) {
|
||||||
// It's fine to go ahead and set it to nil now.
|
// It's fine to go ahead and set it to nil now.
|
||||||
|
|
||||||
assert.Equal(t, zipReq, zipReq2)
|
assert.Equal(t, zipReq, zipReq2)
|
||||||
assert.False(t, zipReq == zipReq2)
|
assert.NotSame(t, zipReq, zipReq2)
|
||||||
|
|
||||||
// Same commit, different compression formats should have different names.
|
// Same commit, different compression formats should have different names.
|
||||||
// Ideally, the extension would match what we originally requested.
|
// Ideally, the extension would match what we originally requested.
|
||||||
|
@ -131,5 +130,5 @@ func TestArchive_Basic(t *testing.T) {
|
||||||
|
|
||||||
func TestErrUnknownArchiveFormat(t *testing.T) {
|
func TestErrUnknownArchiveFormat(t *testing.T) {
|
||||||
err := ErrUnknownArchiveFormat{RequestFormat: "master"}
|
err := ErrUnknownArchiveFormat{RequestFormat: "master"}
|
||||||
assert.True(t, errors.Is(err, ErrUnknownArchiveFormat{}))
|
assert.ErrorIs(t, err, ErrUnknownArchiveFormat{})
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ func Test_detectLicense(t *testing.T) {
|
||||||
result, err := detectLicense(strings.NewReader(tests[2].arg + tests[3].arg + tests[4].arg))
|
result, err := detectLicense(strings.NewReader(tests[2].arg + tests[3].arg + tests[4].arg))
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
t.Run("multiple licenses test", func(t *testing.T) {
|
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[2].want[0])
|
||||||
assert.Contains(t, result, tests[3].want[0])
|
assert.Contains(t, result, tests[3].want[0])
|
||||||
assert.Contains(t, result, tests[4].want[0])
|
assert.Contains(t, result, tests[4].want[0])
|
||||||
|
|
|
@ -103,7 +103,7 @@ func TestRepositoryTransfer(t *testing.T) {
|
||||||
assert.NoError(t, models.CreatePendingRepositoryTransfer(db.DefaultContext, doer, user2, repo.ID, nil))
|
assert.NoError(t, models.CreatePendingRepositoryTransfer(db.DefaultContext, doer, user2, repo.ID, nil))
|
||||||
|
|
||||||
transfer, err = models.GetPendingRepositoryTransfer(db.DefaultContext, repo)
|
transfer, err = models.GetPendingRepositoryTransfer(db.DefaultContext, repo)
|
||||||
assert.Nil(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NoError(t, transfer.LoadAttributes(db.DefaultContext))
|
assert.NoError(t, transfer.LoadAttributes(db.DefaultContext))
|
||||||
assert.Equal(t, "user2", transfer.Recipient.Name)
|
assert.Equal(t, "user2", transfer.Recipient.Name)
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ func TestPackagistPayload(t *testing.T) {
|
||||||
|
|
||||||
pl, err := pc.Create(p)
|
pl, err := pc.Create(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Delete", func(t *testing.T) {
|
t.Run("Delete", func(t *testing.T) {
|
||||||
|
@ -33,7 +33,7 @@ func TestPackagistPayload(t *testing.T) {
|
||||||
|
|
||||||
pl, err := pc.Delete(p)
|
pl, err := pc.Delete(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Fork", func(t *testing.T) {
|
t.Run("Fork", func(t *testing.T) {
|
||||||
|
@ -41,7 +41,7 @@ func TestPackagistPayload(t *testing.T) {
|
||||||
|
|
||||||
pl, err := pc.Fork(p)
|
pl, err := pc.Fork(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Push", func(t *testing.T) {
|
t.Run("Push", func(t *testing.T) {
|
||||||
|
@ -59,12 +59,12 @@ func TestPackagistPayload(t *testing.T) {
|
||||||
p.Action = api.HookIssueOpened
|
p.Action = api.HookIssueOpened
|
||||||
pl, err := pc.Issue(p)
|
pl, err := pc.Issue(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
|
|
||||||
p.Action = api.HookIssueClosed
|
p.Action = api.HookIssueClosed
|
||||||
pl, err = pc.Issue(p)
|
pl, err = pc.Issue(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("IssueComment", func(t *testing.T) {
|
t.Run("IssueComment", func(t *testing.T) {
|
||||||
|
@ -72,7 +72,7 @@ func TestPackagistPayload(t *testing.T) {
|
||||||
|
|
||||||
pl, err := pc.IssueComment(p)
|
pl, err := pc.IssueComment(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("PullRequest", func(t *testing.T) {
|
t.Run("PullRequest", func(t *testing.T) {
|
||||||
|
@ -80,7 +80,7 @@ func TestPackagistPayload(t *testing.T) {
|
||||||
|
|
||||||
pl, err := pc.PullRequest(p)
|
pl, err := pc.PullRequest(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("PullRequestComment", func(t *testing.T) {
|
t.Run("PullRequestComment", func(t *testing.T) {
|
||||||
|
@ -88,7 +88,7 @@ func TestPackagistPayload(t *testing.T) {
|
||||||
|
|
||||||
pl, err := pc.IssueComment(p)
|
pl, err := pc.IssueComment(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Review", func(t *testing.T) {
|
t.Run("Review", func(t *testing.T) {
|
||||||
|
@ -97,7 +97,7 @@ func TestPackagistPayload(t *testing.T) {
|
||||||
|
|
||||||
pl, err := pc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
pl, err := pc.Review(p, webhook_module.HookEventPullRequestReviewApproved)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Repository", func(t *testing.T) {
|
t.Run("Repository", func(t *testing.T) {
|
||||||
|
@ -105,7 +105,7 @@ func TestPackagistPayload(t *testing.T) {
|
||||||
|
|
||||||
pl, err := pc.Repository(p)
|
pl, err := pc.Repository(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Package", func(t *testing.T) {
|
t.Run("Package", func(t *testing.T) {
|
||||||
|
@ -113,7 +113,7 @@ func TestPackagistPayload(t *testing.T) {
|
||||||
|
|
||||||
pl, err := pc.Package(p)
|
pl, err := pc.Package(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Wiki", func(t *testing.T) {
|
t.Run("Wiki", func(t *testing.T) {
|
||||||
|
@ -122,17 +122,17 @@ func TestPackagistPayload(t *testing.T) {
|
||||||
p.Action = api.HookWikiCreated
|
p.Action = api.HookWikiCreated
|
||||||
pl, err := pc.Wiki(p)
|
pl, err := pc.Wiki(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
|
|
||||||
p.Action = api.HookWikiEdited
|
p.Action = api.HookWikiEdited
|
||||||
pl, err = pc.Wiki(p)
|
pl, err = pc.Wiki(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
|
|
||||||
p.Action = api.HookWikiDeleted
|
p.Action = api.HookWikiDeleted
|
||||||
pl, err = pc.Wiki(p)
|
pl, err = pc.Wiki(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Release", func(t *testing.T) {
|
t.Run("Release", func(t *testing.T) {
|
||||||
|
@ -140,7 +140,7 @@ func TestPackagistPayload(t *testing.T) {
|
||||||
|
|
||||||
pl, err := pc.Release(p)
|
pl, err := pc.Release(p)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, pl, PackagistPayload{})
|
require.Equal(t, PackagistPayload{}, pl)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,11 @@ func TestWebhook_GetSlackHook(t *testing.T) {
|
||||||
Meta: `{"channel": "foo", "username": "username", "color": "blue"}`,
|
Meta: `{"channel": "foo", "username": "username", "color": "blue"}`,
|
||||||
}
|
}
|
||||||
slackHook := GetSlackHook(w)
|
slackHook := GetSlackHook(w)
|
||||||
assert.Equal(t, *slackHook, SlackMeta{
|
assert.Equal(t, SlackMeta{
|
||||||
Channel: "foo",
|
Channel: "foo",
|
||||||
Username: "username",
|
Username: "username",
|
||||||
Color: "blue",
|
Color: "blue",
|
||||||
})
|
}, *slackHook)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrepareWebhooks(t *testing.T) {
|
func TestPrepareWebhooks(t *testing.T) {
|
||||||
|
|
|
@ -133,7 +133,7 @@ func TestActionsArtifactDownload(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert.NotNil(t, artifactIdx)
|
assert.NotNil(t, artifactIdx)
|
||||||
assert.Equal(t, listResp.Value[artifactIdx].Name, "artifact-download")
|
assert.Equal(t, "artifact-download", listResp.Value[artifactIdx].Name)
|
||||||
assert.Contains(t, listResp.Value[artifactIdx].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
assert.Contains(t, listResp.Value[artifactIdx].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
||||||
|
|
||||||
idx := strings.Index(listResp.Value[artifactIdx].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
idx := strings.Index(listResp.Value[artifactIdx].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
||||||
|
@ -374,7 +374,7 @@ func TestActionsArtifactOverwrite(t *testing.T) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert.Equal(t, uploadedItem.Name, "artifact-download")
|
assert.Equal(t, "artifact-download", uploadedItem.Name)
|
||||||
|
|
||||||
idx := strings.Index(uploadedItem.FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
idx := strings.Index(uploadedItem.FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
||||||
url := uploadedItem.FileContainerResourceURL[idx+1:] + "?itemPath=artifact-download"
|
url := uploadedItem.FileContainerResourceURL[idx+1:] + "?itemPath=artifact-download"
|
||||||
|
|
|
@ -244,7 +244,7 @@ func TestAPIBranchProtection(t *testing.T) {
|
||||||
StatusCheckContexts: []string{"test1"},
|
StatusCheckContexts: []string{"test1"},
|
||||||
}, http.StatusOK)
|
}, http.StatusOK)
|
||||||
bp := testAPIGetBranchProtection(t, "master", http.StatusOK)
|
bp := testAPIGetBranchProtection(t, "master", http.StatusOK)
|
||||||
assert.Equal(t, true, bp.EnableStatusCheck)
|
assert.True(t, bp.EnableStatusCheck)
|
||||||
assert.Equal(t, []string{"test1"}, bp.StatusCheckContexts)
|
assert.Equal(t, []string{"test1"}, bp.StatusCheckContexts)
|
||||||
|
|
||||||
// disable status checks, clear the list of required checks
|
// disable status checks, clear the list of required checks
|
||||||
|
@ -253,7 +253,7 @@ func TestAPIBranchProtection(t *testing.T) {
|
||||||
StatusCheckContexts: []string{},
|
StatusCheckContexts: []string{},
|
||||||
}, http.StatusOK)
|
}, http.StatusOK)
|
||||||
bp = testAPIGetBranchProtection(t, "master", http.StatusOK)
|
bp = testAPIGetBranchProtection(t, "master", http.StatusOK)
|
||||||
assert.Equal(t, false, bp.EnableStatusCheck)
|
assert.False(t, bp.EnableStatusCheck)
|
||||||
assert.Equal(t, []string{}, bp.StatusCheckContexts)
|
assert.Equal(t, []string{}, bp.StatusCheckContexts)
|
||||||
|
|
||||||
testAPIDeleteBranchProtection(t, "master", http.StatusNoContent)
|
testAPIDeleteBranchProtection(t, "master", http.StatusNoContent)
|
||||||
|
|
|
@ -47,7 +47,7 @@ func TestAPIRepoGetIssueConfig(t *testing.T) {
|
||||||
issueConfig := getIssueConfig(t, owner.Name, repo.Name)
|
issueConfig := getIssueConfig(t, owner.Name, repo.Name)
|
||||||
|
|
||||||
assert.True(t, issueConfig.BlankIssuesEnabled)
|
assert.True(t, issueConfig.BlankIssuesEnabled)
|
||||||
assert.Len(t, issueConfig.ContactLinks, 0)
|
assert.Empty(t, issueConfig.ContactLinks)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("DisableBlankIssues", func(t *testing.T) {
|
t.Run("DisableBlankIssues", func(t *testing.T) {
|
||||||
|
@ -59,7 +59,7 @@ func TestAPIRepoGetIssueConfig(t *testing.T) {
|
||||||
issueConfig := getIssueConfig(t, owner.Name, repo.Name)
|
issueConfig := getIssueConfig(t, owner.Name, repo.Name)
|
||||||
|
|
||||||
assert.False(t, issueConfig.BlankIssuesEnabled)
|
assert.False(t, issueConfig.BlankIssuesEnabled)
|
||||||
assert.Len(t, issueConfig.ContactLinks, 0)
|
assert.Empty(t, issueConfig.ContactLinks)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("ContactLinks", func(t *testing.T) {
|
t.Run("ContactLinks", func(t *testing.T) {
|
||||||
|
@ -135,7 +135,7 @@ func TestAPIRepoIssueConfigPaths(t *testing.T) {
|
||||||
issueConfig := getIssueConfig(t, owner.Name, repo.Name)
|
issueConfig := getIssueConfig(t, owner.Name, repo.Name)
|
||||||
|
|
||||||
assert.False(t, issueConfig.BlankIssuesEnabled)
|
assert.False(t, issueConfig.BlankIssuesEnabled)
|
||||||
assert.Len(t, issueConfig.ContactLinks, 0)
|
assert.Empty(t, issueConfig.ContactLinks)
|
||||||
|
|
||||||
_, err = deleteFileInBranch(owner, repo, fullPath, repo.DefaultBranch)
|
_, err = deleteFileInBranch(owner, repo, fullPath, repo.DefaultBranch)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
@ -153,7 +153,7 @@ func TestAPIListPinnedIssues(t *testing.T) {
|
||||||
var issueList []api.Issue
|
var issueList []api.Issue
|
||||||
DecodeJSON(t, resp, &issueList)
|
DecodeJSON(t, resp, &issueList)
|
||||||
|
|
||||||
assert.Equal(t, 1, len(issueList))
|
assert.Len(t, issueList, 1)
|
||||||
assert.Equal(t, issue.ID, issueList[0].ID)
|
assert.Equal(t, issue.ID, issueList[0].ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ func TestAPIListPinnedPullrequests(t *testing.T) {
|
||||||
var prList []api.PullRequest
|
var prList []api.PullRequest
|
||||||
DecodeJSON(t, resp, &prList)
|
DecodeJSON(t, resp, &prList)
|
||||||
|
|
||||||
assert.Equal(t, 0, len(prList))
|
assert.Empty(t, prList)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAPINewPinAllowed(t *testing.T) {
|
func TestAPINewPinAllowed(t *testing.T) {
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -252,7 +252,7 @@ func TestAPIEditIssue(t *testing.T) {
|
||||||
assert.Equal(t, api.StateClosed, apiIssue.State)
|
assert.Equal(t, api.StateClosed, apiIssue.State)
|
||||||
assert.Equal(t, milestone, apiIssue.Milestone.ID)
|
assert.Equal(t, milestone, apiIssue.Milestone.ID)
|
||||||
assert.Equal(t, body, apiIssue.Body)
|
assert.Equal(t, body, apiIssue.Body)
|
||||||
assert.True(t, apiIssue.Deadline == nil)
|
assert.Nil(t, apiIssue.Deadline)
|
||||||
assert.Equal(t, title, apiIssue.Title)
|
assert.Equal(t, title, apiIssue.Title)
|
||||||
|
|
||||||
// in database
|
// in database
|
||||||
|
|
|
@ -168,7 +168,7 @@ func TestCreateUserKey(t *testing.T) {
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
DecodeJSON(t, resp, &fingerprintPublicKeys)
|
DecodeJSON(t, resp, &fingerprintPublicKeys)
|
||||||
assert.Len(t, fingerprintPublicKeys, 0)
|
assert.Empty(t, fingerprintPublicKeys)
|
||||||
|
|
||||||
// Fail searching for wrong users key
|
// Fail searching for wrong users key
|
||||||
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/users/%s/keys?fingerprint=%s", "user2", newPublicKey.Fingerprint)).
|
req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/users/%s/keys?fingerprint=%s", "user2", newPublicKey.Fingerprint)).
|
||||||
|
@ -176,7 +176,7 @@ func TestCreateUserKey(t *testing.T) {
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
DecodeJSON(t, resp, &fingerprintPublicKeys)
|
DecodeJSON(t, resp, &fingerprintPublicKeys)
|
||||||
assert.Len(t, fingerprintPublicKeys, 0)
|
assert.Empty(t, fingerprintPublicKeys)
|
||||||
|
|
||||||
// Now login as user 2
|
// Now login as user 2
|
||||||
session2 := loginUser(t, "user2")
|
session2 := loginUser(t, "user2")
|
||||||
|
@ -208,5 +208,5 @@ func TestCreateUserKey(t *testing.T) {
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
DecodeJSON(t, resp, &fingerprintPublicKeys)
|
DecodeJSON(t, resp, &fingerprintPublicKeys)
|
||||||
assert.Len(t, fingerprintPublicKeys, 0)
|
assert.Empty(t, fingerprintPublicKeys)
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ func TestAPINotification(t *testing.T) {
|
||||||
AddTokenAuth(token)
|
AddTokenAuth(token)
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
DecodeJSON(t, resp, &newStruct)
|
DecodeJSON(t, resp, &newStruct)
|
||||||
assert.True(t, newStruct.New > 0)
|
assert.Positive(t, newStruct.New)
|
||||||
|
|
||||||
// -- mark notifications as read --
|
// -- mark notifications as read --
|
||||||
req = NewRequest(t, "GET", "/api/v1/notifications?status-types=unread").
|
req = NewRequest(t, "GET", "/api/v1/notifications?status-types=unread").
|
||||||
|
@ -154,7 +154,7 @@ func TestAPINotification(t *testing.T) {
|
||||||
AddTokenAuth(token)
|
AddTokenAuth(token)
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
DecodeJSON(t, resp, &newStruct)
|
DecodeJSON(t, resp, &newStruct)
|
||||||
assert.True(t, newStruct.New == 0)
|
assert.Zero(t, newStruct.New)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAPINotificationPUT(t *testing.T) {
|
func TestAPINotificationPUT(t *testing.T) {
|
||||||
|
|
|
@ -74,9 +74,9 @@ func testAPIListOAuth2Applications(t *testing.T) {
|
||||||
DecodeJSON(t, resp, &appList)
|
DecodeJSON(t, resp, &appList)
|
||||||
expectedApp := appList[0]
|
expectedApp := appList[0]
|
||||||
|
|
||||||
assert.EqualValues(t, existApp.Name, expectedApp.Name)
|
assert.EqualValues(t, expectedApp.Name, existApp.Name)
|
||||||
assert.EqualValues(t, existApp.ClientID, expectedApp.ClientID)
|
assert.EqualValues(t, expectedApp.ClientID, existApp.ClientID)
|
||||||
assert.Equal(t, existApp.ConfidentialClient, expectedApp.ConfidentialClient)
|
assert.Equal(t, expectedApp.ConfidentialClient, existApp.ConfidentialClient)
|
||||||
assert.Len(t, expectedApp.ClientID, 36)
|
assert.Len(t, expectedApp.ClientID, 36)
|
||||||
assert.Empty(t, expectedApp.ClientSecret)
|
assert.Empty(t, expectedApp.ClientSecret)
|
||||||
assert.EqualValues(t, existApp.RedirectURIs[0], expectedApp.RedirectURIs[0])
|
assert.EqualValues(t, existApp.RedirectURIs[0], expectedApp.RedirectURIs[0])
|
||||||
|
@ -128,13 +128,13 @@ func testAPIGetOAuth2Application(t *testing.T) {
|
||||||
DecodeJSON(t, resp, &app)
|
DecodeJSON(t, resp, &app)
|
||||||
expectedApp := app
|
expectedApp := app
|
||||||
|
|
||||||
assert.EqualValues(t, existApp.Name, expectedApp.Name)
|
assert.EqualValues(t, expectedApp.Name, existApp.Name)
|
||||||
assert.EqualValues(t, existApp.ClientID, expectedApp.ClientID)
|
assert.EqualValues(t, expectedApp.ClientID, existApp.ClientID)
|
||||||
assert.Equal(t, existApp.ConfidentialClient, expectedApp.ConfidentialClient)
|
assert.Equal(t, expectedApp.ConfidentialClient, existApp.ConfidentialClient)
|
||||||
assert.Len(t, expectedApp.ClientID, 36)
|
assert.Len(t, expectedApp.ClientID, 36)
|
||||||
assert.Empty(t, expectedApp.ClientSecret)
|
assert.Empty(t, expectedApp.ClientSecret)
|
||||||
assert.Len(t, expectedApp.RedirectURIs, 1)
|
assert.Len(t, expectedApp.RedirectURIs, 1)
|
||||||
assert.EqualValues(t, existApp.RedirectURIs[0], expectedApp.RedirectURIs[0])
|
assert.EqualValues(t, expectedApp.RedirectURIs[0], existApp.RedirectURIs[0])
|
||||||
unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: expectedApp.ID, Name: expectedApp.Name})
|
unittest.AssertExistsAndLoadBean(t, &auth_model.OAuth2Application{ID: expectedApp.ID, Name: expectedApp.Name})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -325,7 +325,7 @@ func TestPackageNpm(t *testing.T) {
|
||||||
|
|
||||||
pvs, err = packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNpm)
|
pvs, err = packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeNpm)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, pvs, 0)
|
assert.Empty(t, pvs)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ func TestAPIViewPulls(t *testing.T) {
|
||||||
pull := pulls[0]
|
pull := pulls[0]
|
||||||
assert.EqualValues(t, 1, pull.Poster.ID)
|
assert.EqualValues(t, 1, pull.Poster.ID)
|
||||||
assert.Len(t, pull.RequestedReviewers, 2)
|
assert.Len(t, pull.RequestedReviewers, 2)
|
||||||
assert.Len(t, pull.RequestedReviewersTeams, 0)
|
assert.Empty(t, pull.RequestedReviewersTeams)
|
||||||
assert.EqualValues(t, 5, pull.RequestedReviewers[0].ID)
|
assert.EqualValues(t, 5, pull.RequestedReviewers[0].ID)
|
||||||
assert.EqualValues(t, 6, pull.RequestedReviewers[1].ID)
|
assert.EqualValues(t, 6, pull.RequestedReviewers[1].ID)
|
||||||
assert.EqualValues(t, 1, pull.ChangedFiles)
|
assert.EqualValues(t, 1, pull.ChangedFiles)
|
||||||
|
@ -83,7 +83,7 @@ func TestAPIViewPulls(t *testing.T) {
|
||||||
pull = pulls[1]
|
pull = pulls[1]
|
||||||
assert.EqualValues(t, 1, pull.Poster.ID)
|
assert.EqualValues(t, 1, pull.Poster.ID)
|
||||||
assert.Len(t, pull.RequestedReviewers, 4)
|
assert.Len(t, pull.RequestedReviewers, 4)
|
||||||
assert.Len(t, pull.RequestedReviewersTeams, 0)
|
assert.Empty(t, pull.RequestedReviewersTeams)
|
||||||
assert.EqualValues(t, 3, pull.RequestedReviewers[0].ID)
|
assert.EqualValues(t, 3, pull.RequestedReviewers[0].ID)
|
||||||
assert.EqualValues(t, 4, pull.RequestedReviewers[1].ID)
|
assert.EqualValues(t, 4, pull.RequestedReviewers[1].ID)
|
||||||
assert.EqualValues(t, 2, pull.RequestedReviewers[2].ID)
|
assert.EqualValues(t, 2, pull.RequestedReviewers[2].ID)
|
||||||
|
@ -120,7 +120,7 @@ func TestAPIViewPulls(t *testing.T) {
|
||||||
pull = pulls[2]
|
pull = pulls[2]
|
||||||
assert.EqualValues(t, 1, pull.Poster.ID)
|
assert.EqualValues(t, 1, pull.Poster.ID)
|
||||||
assert.Len(t, pull.RequestedReviewers, 1)
|
assert.Len(t, pull.RequestedReviewers, 1)
|
||||||
assert.Len(t, pull.RequestedReviewersTeams, 0)
|
assert.Empty(t, pull.RequestedReviewersTeams)
|
||||||
assert.EqualValues(t, 1, pull.RequestedReviewers[0].ID)
|
assert.EqualValues(t, 1, pull.RequestedReviewers[0].ID)
|
||||||
assert.EqualValues(t, 0, pull.ChangedFiles)
|
assert.EqualValues(t, 0, pull.ChangedFiles)
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ func TestAPIReposGitCommitList(t *testing.T) {
|
||||||
assert.EqualValues(t, "c8e31bc7688741a5287fcde4fbb8fc129ca07027", apiData[1].CommitMeta.SHA)
|
assert.EqualValues(t, "c8e31bc7688741a5287fcde4fbb8fc129ca07027", apiData[1].CommitMeta.SHA)
|
||||||
compareCommitFiles(t, []string{"test.csv"}, apiData[1].Files)
|
compareCommitFiles(t, []string{"test.csv"}, apiData[1].Files)
|
||||||
|
|
||||||
assert.EqualValues(t, resp.Header().Get("X-Total"), "2")
|
assert.EqualValues(t, "2", resp.Header().Get("X-Total"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAPIReposGitCommitListNotMaster(t *testing.T) {
|
func TestAPIReposGitCommitListNotMaster(t *testing.T) {
|
||||||
|
@ -103,7 +103,7 @@ func TestAPIReposGitCommitListNotMaster(t *testing.T) {
|
||||||
assert.EqualValues(t, "5099b81332712fe655e34e8dd63574f503f61811", apiData[2].CommitMeta.SHA)
|
assert.EqualValues(t, "5099b81332712fe655e34e8dd63574f503f61811", apiData[2].CommitMeta.SHA)
|
||||||
compareCommitFiles(t, []string{"readme.md"}, apiData[2].Files)
|
compareCommitFiles(t, []string{"readme.md"}, apiData[2].Files)
|
||||||
|
|
||||||
assert.EqualValues(t, resp.Header().Get("X-Total"), "3")
|
assert.EqualValues(t, "3", resp.Header().Get("X-Total"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
|
func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
|
||||||
|
@ -121,7 +121,7 @@ func TestAPIReposGitCommitListPage2Empty(t *testing.T) {
|
||||||
var apiData []api.Commit
|
var apiData []api.Commit
|
||||||
DecodeJSON(t, resp, &apiData)
|
DecodeJSON(t, resp, &apiData)
|
||||||
|
|
||||||
assert.Len(t, apiData, 0)
|
assert.Empty(t, apiData)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAPIReposGitCommitListDifferentBranch(t *testing.T) {
|
func TestAPIReposGitCommitListDifferentBranch(t *testing.T) {
|
||||||
|
@ -208,7 +208,7 @@ func TestGetFileHistory(t *testing.T) {
|
||||||
assert.Equal(t, "f27c2b2b03dcab38beaf89b0ab4ff61f6de63441", apiData[0].CommitMeta.SHA)
|
assert.Equal(t, "f27c2b2b03dcab38beaf89b0ab4ff61f6de63441", apiData[0].CommitMeta.SHA)
|
||||||
compareCommitFiles(t, []string{"readme.md"}, apiData[0].Files)
|
compareCommitFiles(t, []string{"readme.md"}, apiData[0].Files)
|
||||||
|
|
||||||
assert.EqualValues(t, resp.Header().Get("X-Total"), "1")
|
assert.EqualValues(t, "1", resp.Header().Get("X-Total"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetFileHistoryNotOnMaster(t *testing.T) {
|
func TestGetFileHistoryNotOnMaster(t *testing.T) {
|
||||||
|
@ -229,5 +229,5 @@ func TestGetFileHistoryNotOnMaster(t *testing.T) {
|
||||||
assert.Equal(t, "c8e31bc7688741a5287fcde4fbb8fc129ca07027", apiData[0].CommitMeta.SHA)
|
assert.Equal(t, "c8e31bc7688741a5287fcde4fbb8fc129ca07027", apiData[0].CommitMeta.SHA)
|
||||||
compareCommitFiles(t, []string{"test.csv"}, apiData[0].Files)
|
compareCommitFiles(t, []string{"test.csv"}, apiData[0].Files)
|
||||||
|
|
||||||
assert.EqualValues(t, resp.Header().Get("X-Total"), "1")
|
assert.EqualValues(t, "1", resp.Header().Get("X-Total"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,6 +176,6 @@ func TestAPILFSLocksLogged(t *testing.T) {
|
||||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
var lfsLocks api.LFSLockList
|
var lfsLocks api.LFSLockList
|
||||||
DecodeJSON(t, resp, &lfsLocks)
|
DecodeJSON(t, resp, &lfsLocks)
|
||||||
assert.Len(t, lfsLocks.Locks, 0)
|
assert.Empty(t, lfsLocks.Locks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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), "%v == %v", 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)
|
||||||
|
|
|
@ -76,7 +76,7 @@ func TestUserOrgs(t *testing.T) {
|
||||||
|
|
||||||
// unrelated user should not get private org membership of privateMemberUsername
|
// unrelated user should not get private org membership of privateMemberUsername
|
||||||
orgs = getUserOrgs(t, unrelatedUsername, privateMemberUsername)
|
orgs = getUserOrgs(t, unrelatedUsername, privateMemberUsername)
|
||||||
assert.Len(t, orgs, 0)
|
assert.Empty(t, orgs)
|
||||||
|
|
||||||
// not authenticated call should not be allowed
|
// not authenticated call should not be allowed
|
||||||
testUserOrgsUnauthenticated(t, privateMemberUsername)
|
testUserOrgsUnauthenticated(t, privateMemberUsername)
|
||||||
|
|
|
@ -49,7 +49,7 @@ func TestAPIUserSearchLoggedIn(t *testing.T) {
|
||||||
for _, user := range results.Data {
|
for _, user := range results.Data {
|
||||||
assert.Contains(t, user.UserName, query)
|
assert.Contains(t, user.UserName, query)
|
||||||
assert.NotEmpty(t, user.Email)
|
assert.NotEmpty(t, user.Email)
|
||||||
assert.True(t, user.Visibility == "public")
|
assert.Equal(t, "public", user.Visibility)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ func TestAPIUserSearchSystemUsers(t *testing.T) {
|
||||||
var results SearchResults
|
var results SearchResults
|
||||||
DecodeJSON(t, resp, &results)
|
DecodeJSON(t, resp, &results)
|
||||||
assert.NotEmpty(t, results.Data)
|
assert.NotEmpty(t, results.Data)
|
||||||
if assert.EqualValues(t, 1, len(results.Data)) {
|
if assert.Len(t, results.Data, 1) {
|
||||||
user := results.Data[0]
|
user := results.Data[0]
|
||||||
assert.EqualValues(t, user.UserName, systemUser.Name)
|
assert.EqualValues(t, user.UserName, systemUser.Name)
|
||||||
assert.EqualValues(t, user.ID, systemUser.ID)
|
assert.EqualValues(t, user.ID, systemUser.ID)
|
||||||
|
@ -137,7 +137,7 @@ func TestAPIUserSearchByEmail(t *testing.T) {
|
||||||
|
|
||||||
var results SearchResults
|
var results SearchResults
|
||||||
DecodeJSON(t, resp, &results)
|
DecodeJSON(t, resp, &results)
|
||||||
assert.Equal(t, 1, len(results.Data))
|
assert.Len(t, results.Data, 1)
|
||||||
assert.Equal(t, query, results.Data[0].Email)
|
assert.Equal(t, query, results.Data[0].Email)
|
||||||
|
|
||||||
// no login user can not search user with private email
|
// no login user can not search user with private email
|
||||||
|
@ -155,6 +155,6 @@ func TestAPIUserSearchByEmail(t *testing.T) {
|
||||||
resp = MakeRequest(t, req, http.StatusOK)
|
resp = MakeRequest(t, req, http.StatusOK)
|
||||||
|
|
||||||
DecodeJSON(t, resp, &results)
|
DecodeJSON(t, resp, &results)
|
||||||
assert.Equal(t, 1, len(results.Data))
|
assert.Len(t, results.Data, 1)
|
||||||
assert.Equal(t, query, results.Data[0].Email)
|
assert.Equal(t, query, results.Data[0].Email)
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,7 +265,7 @@ func TestLDAPUserSyncWithEmptyUsernameAttribute(t *testing.T) {
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
|
|
||||||
tr := htmlDoc.doc.Find("table.table tbody tr")
|
tr := htmlDoc.doc.Find("table.table tbody tr")
|
||||||
assert.True(t, tr.Length() == 0)
|
assert.Equal(t, 0, tr.Length())
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, u := range gitLDAPUsers {
|
for _, u := range gitLDAPUsers {
|
||||||
|
|
|
@ -40,10 +40,10 @@ func withKeyFile(t *testing.T, keyname string, callback func(string)) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Setup ssh wrapper
|
// Setup ssh wrapper
|
||||||
os.Setenv("GIT_SSH", path.Join(tmpDir, "ssh"))
|
t.Setenv("GIT_SSH", path.Join(tmpDir, "ssh"))
|
||||||
os.Setenv("GIT_SSH_COMMAND",
|
t.Setenv("GIT_SSH_COMMAND",
|
||||||
"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i \""+keyFile+"\"")
|
"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -i \""+keyFile+"\"")
|
||||||
os.Setenv("GIT_SSH_VARIANT", "ssh")
|
t.Setenv("GIT_SSH_VARIANT", "ssh")
|
||||||
|
|
||||||
callback(keyFile)
|
callback(keyFile)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ package integration
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
auth_model "code.gitea.io/gitea/models/auth"
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
|
@ -211,6 +210,6 @@ func TestPushPullRefs(t *testing.T) {
|
||||||
})
|
})
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Empty(t, stdout)
|
assert.Empty(t, stdout)
|
||||||
assert.False(t, strings.Contains(stderr, "[deleted]"), "stderr: %s", stderr)
|
assert.NotContains(t, stderr, "[deleted]", "stderr: %s", stderr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,7 @@ func TestGPGGit(t *testing.T) {
|
||||||
err := os.Chmod(tmpDir, 0o700)
|
err := os.Chmod(tmpDir, 0o700)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
oldGNUPGHome := os.Getenv("GNUPGHOME")
|
t.Setenv("GNUPGHOME", tmpDir)
|
||||||
err = os.Setenv("GNUPGHOME", tmpDir)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
defer os.Setenv("GNUPGHOME", oldGNUPGHome)
|
|
||||||
|
|
||||||
// Need to create a root key
|
// Need to create a root key
|
||||||
rootKeyPair, err := importTestingKey()
|
rootKeyPair, err := importTestingKey()
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue