mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-02 13:00:10 +02:00
Merge remote-tracking branch 'upstream/main' into limit-repo-size
This commit is contained in:
commit
f583b8f967
487 files changed
+7089
-3293
No files matched your search
@@ -174,7 +174,7 @@ func TestAPISearchIssues(t *testing.T) {
|
||||
token := getUserToken(t, "user2")
|
||||
|
||||
// as this API was used in the frontend, it uses UI page size
|
||||
expectedIssueCount := 15 // from the fixtures
|
||||
expectedIssueCount := 16 // from the fixtures
|
||||
if expectedIssueCount > setting.UI.IssuePagingNum {
|
||||
expectedIssueCount = setting.UI.IssuePagingNum
|
||||
}
|
||||
@@ -198,7 +198,7 @@ func TestAPISearchIssues(t *testing.T) {
|
||||
req = NewRequest(t, "GET", link.String())
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.Len(t, apiIssues, 8)
|
||||
assert.Len(t, apiIssues, 9)
|
||||
query.Del("since")
|
||||
query.Del("before")
|
||||
|
||||
@@ -214,15 +214,15 @@ func TestAPISearchIssues(t *testing.T) {
|
||||
req = NewRequest(t, "GET", link.String())
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.EqualValues(t, "17", resp.Header().Get("X-Total-Count"))
|
||||
assert.Len(t, apiIssues, 17)
|
||||
assert.EqualValues(t, "18", resp.Header().Get("X-Total-Count"))
|
||||
assert.Len(t, apiIssues, 18)
|
||||
|
||||
query.Add("limit", "10")
|
||||
link.RawQuery = query.Encode()
|
||||
req = NewRequest(t, "GET", link.String())
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.EqualValues(t, "17", resp.Header().Get("X-Total-Count"))
|
||||
assert.EqualValues(t, "18", resp.Header().Get("X-Total-Count"))
|
||||
assert.Len(t, apiIssues, 10)
|
||||
|
||||
query = url.Values{"assigned": {"true"}, "state": {"all"}, "token": {token}}
|
||||
@@ -251,7 +251,7 @@ func TestAPISearchIssues(t *testing.T) {
|
||||
req = NewRequest(t, "GET", link.String())
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.Len(t, apiIssues, 6)
|
||||
assert.Len(t, apiIssues, 7)
|
||||
|
||||
query = url.Values{"owner": {"user3"}, "token": {token}} // organization
|
||||
link.RawQuery = query.Encode()
|
||||
@@ -272,7 +272,7 @@ func TestAPISearchIssuesWithLabels(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
// as this API was used in the frontend, it uses UI page size
|
||||
expectedIssueCount := 15 // from the fixtures
|
||||
expectedIssueCount := 16 // from the fixtures
|
||||
if expectedIssueCount > setting.UI.IssuePagingNum {
|
||||
expectedIssueCount = setting.UI.IssuePagingNum
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func TestNodeinfo(t *testing.T) {
|
||||
assert.True(t, nodeinfo.OpenRegistrations)
|
||||
assert.Equal(t, "gitea", nodeinfo.Software.Name)
|
||||
assert.Equal(t, 24, nodeinfo.Usage.Users.Total)
|
||||
assert.Equal(t, 17, nodeinfo.Usage.LocalPosts)
|
||||
assert.Equal(t, 18, nodeinfo.Usage.LocalPosts)
|
||||
assert.Equal(t, 2, nodeinfo.Usage.LocalComments)
|
||||
})
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"encoding/pem"
|
||||
@@ -34,6 +33,7 @@ import (
|
||||
chef_router "code.gitea.io/gitea/routers/api/packages/chef"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/minio/sha256-simd"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
|
||||
func TestPackageComposer(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
vendorName := "gitea"
|
||||
|
||||
@@ -205,6 +205,7 @@ func uploadConanPackageV2(t *testing.T, baseURL, token, name, version, user, cha
|
||||
|
||||
func TestPackageConan(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
name := "ConanPackage"
|
||||
|
||||
@@ -5,7 +5,6 @@ package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -24,6 +23,7 @@ import (
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/minio/sha256-simd"
|
||||
oci "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -640,7 +640,7 @@ func TestPackageContainer(t *testing.T) {
|
||||
|
||||
checkCatalog := func(owner string) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", fmt.Sprintf("%sv2/_catalog", setting.AppURL))
|
||||
addTokenAuthHeader(req, userToken)
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
func TestPackageGeneric(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
packageName := "te-st_pac.kage"
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
|
||||
func TestPackageHelm(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
packageName := "test-chart"
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
|
||||
func TestPackageMaven(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
groupID := "com.gitea"
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
|
||||
func TestPackageNpm(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
token := fmt.Sprintf("Bearer %s", getTokenForLoggedInUser(t, loginUser(t, user.Name)))
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
|
||||
func TestPackagePub(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
token := "Bearer " + getUserToken(t, user.Name)
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
|
||||
func TestPackagePyPI(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
packageName := "test-package"
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
func TestPackageRubyGems(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
packageName := "gitea"
|
||||
|
||||
@@ -5,7 +5,6 @@ package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -20,10 +19,12 @@ import (
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
packages_service "code.gitea.io/gitea/services/packages"
|
||||
packages_cleanup_service "code.gitea.io/gitea/services/packages/cleanup"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/minio/sha256-simd"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -235,16 +236,35 @@ func TestPackageQuota(t *testing.T) {
|
||||
func TestPackageCleanup(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
duration, _ := time.ParseDuration("-1h")
|
||||
|
||||
t.Run("Common", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
// Upload and delete a generic package and upload a container blob
|
||||
data, _ := util.CryptoRandomBytes(5)
|
||||
url := fmt.Sprintf("/api/packages/%s/generic/cleanup-test/1.1.1/file.bin", user.Name)
|
||||
req := NewRequestWithBody(t, "PUT", url, bytes.NewReader(data))
|
||||
AddBasicAuthHeader(req, user.Name)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
req = NewRequest(t, "DELETE", url)
|
||||
AddBasicAuthHeader(req, user.Name)
|
||||
MakeRequest(t, req, http.StatusNoContent)
|
||||
|
||||
data, _ = util.CryptoRandomBytes(5)
|
||||
url = fmt.Sprintf("/v2/%s/cleanup-test/blobs/uploads?digest=sha256:%x", user.Name, sha256.Sum256(data))
|
||||
req = NewRequestWithBody(t, "POST", url, bytes.NewReader(data))
|
||||
AddBasicAuthHeader(req, user.Name)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
pbs, err := packages_model.FindExpiredUnreferencedBlobs(db.DefaultContext, duration)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, pbs)
|
||||
|
||||
_, err = packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, 2, packages_model.TypeContainer, "test", container_model.UploadVersion)
|
||||
_, err = packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, "cleanup-test", container_model.UploadVersion)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = packages_cleanup_service.Cleanup(db.DefaultContext, duration)
|
||||
@@ -254,15 +274,13 @@ func TestPackageCleanup(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, pbs)
|
||||
|
||||
_, err = packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, 2, packages_model.TypeContainer, "test", container_model.UploadVersion)
|
||||
_, err = packages_model.GetInternalVersionByNameAndVersion(db.DefaultContext, user.ID, packages_model.TypeContainer, "cleanup-test", container_model.UploadVersion)
|
||||
assert.ErrorIs(t, err, packages_model.ErrPackageNotExist)
|
||||
})
|
||||
|
||||
t.Run("CleanupRules", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
type version struct {
|
||||
Version string
|
||||
ShouldExist bool
|
||||
|
||||
@@ -111,7 +111,7 @@ func TestAPITeam(t *testing.T) {
|
||||
|
||||
// Read team.
|
||||
teamRead := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
|
||||
assert.NoError(t, teamRead.GetUnits())
|
||||
assert.NoError(t, teamRead.LoadUnits(db.DefaultContext))
|
||||
req = NewRequestf(t, "GET", "/api/v1/teams/%d?token="+token, teamID)
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
apiTeam = api.Team{}
|
||||
@@ -181,7 +181,7 @@ func TestAPITeam(t *testing.T) {
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
apiTeam = api.Team{}
|
||||
DecodeJSON(t, resp, &apiTeam)
|
||||
assert.NoError(t, teamRead.GetUnits())
|
||||
assert.NoError(t, teamRead.LoadUnits(db.DefaultContext))
|
||||
checkTeamResponse(t, "ReadTeam2", &apiTeam, teamRead.Name, *teamToEditDesc.Description, teamRead.IncludesAllRepositories,
|
||||
teamRead.AccessMode.String(), teamRead.GetUnitNames(), teamRead.GetUnitsMap())
|
||||
|
||||
@@ -210,7 +210,7 @@ func checkTeamResponse(t *testing.T, testName string, apiTeam *api.Team, name, d
|
||||
|
||||
func checkTeamBean(t *testing.T, id int64, name, description string, includesAllRepositories bool, permission string, units []string, unitsMap map[string]string) {
|
||||
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: id})
|
||||
assert.NoError(t, team.GetUnits(), "GetUnits")
|
||||
assert.NoError(t, team.LoadUnits(db.DefaultContext), "LoadUnits")
|
||||
apiTeam, err := convert.ToTeam(db.DefaultContext, team)
|
||||
assert.NoError(t, err)
|
||||
checkTeamResponse(t, fmt.Sprintf("checkTeamBean/%s_%s", name, description), apiTeam, name, description, includesAllRepositories, permission, units, unitsMap)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -40,3 +41,80 @@ func TestCompareDefault(t *testing.T) {
|
||||
selection := htmlDoc.doc.Find(".choose.branch .filter.dropdown")
|
||||
assert.Lenf(t, selection.Nodes, 2, "The template has changed")
|
||||
}
|
||||
|
||||
// Ensure the comparison matches what we expect
|
||||
func inspectCompare(t *testing.T, htmlDoc *HTMLDoc, diffCount int, diffChanges []string) {
|
||||
selection := htmlDoc.doc.Find("#diff-file-boxes").Children()
|
||||
|
||||
assert.Lenf(t, selection.Nodes, diffCount, "Expected %v diffed files, found: %v", diffCount, len(selection.Nodes))
|
||||
|
||||
for _, diffChange := range diffChanges {
|
||||
selection = htmlDoc.doc.Find(fmt.Sprintf("[data-new-filename=\"%s\"]", diffChange))
|
||||
assert.Lenf(t, selection.Nodes, 1, "Expected 1 match for [data-new-filename=\"%s\"], found: %v", diffChange, len(selection.Nodes))
|
||||
}
|
||||
}
|
||||
|
||||
// Git commit graph for repo20
|
||||
// * 8babce9 (origin/remove-files-b) Add a dummy file
|
||||
// * b67e43a Delete test.csv and link_hi
|
||||
// | * cfe3b3c (origin/remove-files-a) Delete test.csv and link_hi
|
||||
// |/
|
||||
// * c8e31bc (origin/add-csv) Add test csv file
|
||||
// * 808038d (HEAD -> master, origin/master, origin/HEAD) Added test links
|
||||
|
||||
func TestCompareBranches(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
// Inderect compare remove-files-b (head) with add-csv (base) branch
|
||||
//
|
||||
// 'link_hi' and 'test.csv' are deleted, 'test.txt' is added
|
||||
req := NewRequest(t, "GET", "/user2/repo20/compare/add-csv...remove-files-b")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
diffCount := 3
|
||||
diffChanges := []string{"link_hi", "test.csv", "test.txt"}
|
||||
|
||||
inspectCompare(t, htmlDoc, diffCount, diffChanges)
|
||||
|
||||
// Inderect compare remove-files-b (head) with remove-files-a (base) branch
|
||||
//
|
||||
// 'link_hi' and 'test.csv' are deleted, 'test.txt' is added
|
||||
|
||||
req = NewRequest(t, "GET", "/user2/repo20/compare/remove-files-a...remove-files-b")
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc = NewHTMLParser(t, resp.Body)
|
||||
|
||||
diffCount = 3
|
||||
diffChanges = []string{"link_hi", "test.csv", "test.txt"}
|
||||
|
||||
inspectCompare(t, htmlDoc, diffCount, diffChanges)
|
||||
|
||||
// Inderect compare remove-files-a (head) with remove-files-b (base) branch
|
||||
//
|
||||
// 'link_hi' and 'test.csv' are deleted
|
||||
|
||||
req = NewRequest(t, "GET", "/user2/repo20/compare/remove-files-b...remove-files-a")
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc = NewHTMLParser(t, resp.Body)
|
||||
|
||||
diffCount = 2
|
||||
diffChanges = []string{"link_hi", "test.csv"}
|
||||
|
||||
inspectCompare(t, htmlDoc, diffCount, diffChanges)
|
||||
|
||||
// Direct compare remove-files-b (head) with remove-files-a (base) branch
|
||||
//
|
||||
// 'test.txt' is deleted
|
||||
|
||||
req = NewRequest(t, "GET", "/user2/repo20/compare/remove-files-b..remove-files-a")
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc = NewHTMLParser(t, resp.Body)
|
||||
|
||||
diffCount = 1
|
||||
diffChanges = []string{"test.txt"}
|
||||
|
||||
inspectCompare(t, htmlDoc, diffCount, diffChanges)
|
||||
}
|
||||
@@ -674,8 +674,17 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
|
||||
|
||||
commitID := path.Base(commitURL)
|
||||
|
||||
addCommitStatus := func(status api.CommitStatusState) func(*testing.T) {
|
||||
return doAPICreateCommitStatus(ctx, commitID, api.CreateStatusOption{
|
||||
State: status,
|
||||
TargetURL: "http://test.ci/",
|
||||
Description: "",
|
||||
Context: "testci",
|
||||
})
|
||||
}
|
||||
|
||||
// Call API to add Pending status for commit
|
||||
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusPending))
|
||||
t.Run("CreateStatus", addCommitStatus(api.CommitStatusPending))
|
||||
|
||||
// Cancel not existing auto merge
|
||||
ctx.ExpectedCode = http.StatusNotFound
|
||||
@@ -704,7 +713,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
|
||||
assert.False(t, pr.HasMerged)
|
||||
|
||||
// Call API to add Failure status for commit
|
||||
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusFailure))
|
||||
t.Run("CreateStatus", addCommitStatus(api.CommitStatusFailure))
|
||||
|
||||
// Check pr status
|
||||
pr, err = doAPIGetPullRequest(ctx, baseCtx.Username, baseCtx.Reponame, pr.Index)(t)
|
||||
@@ -712,7 +721,7 @@ func doAutoPRMerge(baseCtx *APITestContext, dstPath string) func(t *testing.T) {
|
||||
assert.False(t, pr.HasMerged)
|
||||
|
||||
// Call API to add Success status for commit
|
||||
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, commitID, api.CommitStatusSuccess))
|
||||
t.Run("CreateStatus", addCommitStatus(api.CommitStatusSuccess))
|
||||
|
||||
// wait to let gitea merge stuff
|
||||
time.Sleep(time.Second)
|
||||
|
||||
@@ -87,8 +87,8 @@ func TestMain(m *testing.M) {
|
||||
c = routers.NormalRoutes(context.TODO())
|
||||
|
||||
// integration test settings...
|
||||
if setting.Cfg != nil {
|
||||
testingCfg := setting.Cfg.Section("integration-tests")
|
||||
if setting.CfgProvider != nil {
|
||||
testingCfg := setting.CfgProvider.Section("integration-tests")
|
||||
tests.SlowTest = testingCfg.Key("SLOW_TEST").MustDuration(tests.SlowTest)
|
||||
tests.SlowFlush = testingCfg.Key("SLOW_FLUSH").MustDuration(tests.SlowFlush)
|
||||
}
|
||||
|
||||
@@ -356,7 +356,7 @@ func TestSearchIssues(t *testing.T) {
|
||||
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
expectedIssueCount := 15 // from the fixtures
|
||||
expectedIssueCount := 16 // from the fixtures
|
||||
if expectedIssueCount > setting.UI.IssuePagingNum {
|
||||
expectedIssueCount = setting.UI.IssuePagingNum
|
||||
}
|
||||
@@ -377,7 +377,7 @@ func TestSearchIssues(t *testing.T) {
|
||||
req = NewRequest(t, "GET", link.String())
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.Len(t, apiIssues, 8)
|
||||
assert.Len(t, apiIssues, 9)
|
||||
query.Del("since")
|
||||
query.Del("before")
|
||||
|
||||
@@ -393,15 +393,15 @@ func TestSearchIssues(t *testing.T) {
|
||||
req = NewRequest(t, "GET", link.String())
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.EqualValues(t, "17", resp.Header().Get("X-Total-Count"))
|
||||
assert.Len(t, apiIssues, 17)
|
||||
assert.EqualValues(t, "18", resp.Header().Get("X-Total-Count"))
|
||||
assert.Len(t, apiIssues, 18)
|
||||
|
||||
query.Add("limit", "5")
|
||||
link.RawQuery = query.Encode()
|
||||
req = NewRequest(t, "GET", link.String())
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.EqualValues(t, "17", resp.Header().Get("X-Total-Count"))
|
||||
assert.EqualValues(t, "18", resp.Header().Get("X-Total-Count"))
|
||||
assert.Len(t, apiIssues, 5)
|
||||
|
||||
query = url.Values{"assigned": {"true"}, "state": {"all"}}
|
||||
@@ -430,7 +430,7 @@ func TestSearchIssues(t *testing.T) {
|
||||
req = NewRequest(t, "GET", link.String())
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
DecodeJSON(t, resp, &apiIssues)
|
||||
assert.Len(t, apiIssues, 6)
|
||||
assert.Len(t, apiIssues, 7)
|
||||
|
||||
query = url.Values{"owner": {"user3"}} // organization
|
||||
link.RawQuery = query.Encode()
|
||||
@@ -450,7 +450,7 @@ func TestSearchIssues(t *testing.T) {
|
||||
func TestSearchIssuesWithLabels(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
expectedIssueCount := 15 // from the fixtures
|
||||
expectedIssueCount := 16 // from the fixtures
|
||||
if expectedIssueCount > setting.UI.IssuePagingNum {
|
||||
expectedIssueCount = setting.UI.IssuePagingNum
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func initMigrationTest(t *testing.T) func() {
|
||||
setting.CustomConf = giteaConf
|
||||
}
|
||||
|
||||
setting.LoadForTest()
|
||||
setting.InitProviderAndLoadCommonSettingsForTest()
|
||||
|
||||
assert.True(t, len(setting.RepoRootPath) != 0)
|
||||
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
|
||||
@@ -83,8 +83,8 @@ func initMigrationTest(t *testing.T) func() {
|
||||
}
|
||||
|
||||
assert.NoError(t, git.InitFull(context.Background()))
|
||||
setting.InitDBConfig()
|
||||
setting.NewLogServices(true)
|
||||
setting.LoadDBSetting()
|
||||
setting.InitLogs(true)
|
||||
return deferFn
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ func doMigrationTest(t *testing.T, version string) {
|
||||
return
|
||||
}
|
||||
|
||||
setting.NewXORMLogService(false)
|
||||
setting.InitSQLLog(false)
|
||||
|
||||
err := db.InitEngineWithMigration(context.Background(), wrappedMigrate)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -70,7 +70,12 @@ func TestPullCreate_CommitStatus(t *testing.T) {
|
||||
for _, status := range statusList {
|
||||
|
||||
// Call API to add status for commit
|
||||
t.Run("CreateStatus", doAPICreateCommitStatus(testCtx, commitID, status))
|
||||
t.Run("CreateStatus", doAPICreateCommitStatus(testCtx, commitID, api.CreateStatusOption{
|
||||
State: status,
|
||||
TargetURL: "http://test.ci/",
|
||||
Description: "",
|
||||
Context: "testci",
|
||||
}))
|
||||
|
||||
req = NewRequestf(t, "GET", "/user1/repo1/pulls/1/commits")
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
@@ -88,15 +93,13 @@ func TestPullCreate_CommitStatus(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func doAPICreateCommitStatus(ctx APITestContext, commitID string, status api.CommitStatusState) func(*testing.T) {
|
||||
func doAPICreateCommitStatus(ctx APITestContext, commitID string, data api.CreateStatusOption) func(*testing.T) {
|
||||
return func(t *testing.T) {
|
||||
req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/statuses/%s?token=%s", ctx.Username, ctx.Reponame, commitID, ctx.Token),
|
||||
api.CreateStatusOption{
|
||||
State: status,
|
||||
TargetURL: "http://test.ci/",
|
||||
Description: "",
|
||||
Context: "testci",
|
||||
},
|
||||
req := NewRequestWithJSON(
|
||||
t,
|
||||
http.MethodPost,
|
||||
fmt.Sprintf("/api/v1/repos/%s/%s/statuses/%s?token=%s", ctx.Username, ctx.Reponame, commitID, ctx.Token),
|
||||
data,
|
||||
)
|
||||
if ctx.ExpectedCode != 0 {
|
||||
ctx.Session.MakeRequest(t, req, ctx.ExpectedCode)
|
||||
|
||||
@@ -52,14 +52,19 @@ func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
|
||||
|
||||
// Call API to add status for commit
|
||||
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeRepo)
|
||||
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CommitStatusState(state)))
|
||||
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{
|
||||
State: api.CommitStatusState(state),
|
||||
TargetURL: "http://test.ci/",
|
||||
Description: "",
|
||||
Context: "testci",
|
||||
}))
|
||||
|
||||
req = NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
doc = NewHTMLParser(t, resp.Body)
|
||||
// Check if commit status is displayed in message column
|
||||
sel := doc.doc.Find("#commits-table tbody tr td.message a.commit-statuses-trigger .commit-status")
|
||||
// Check if commit status is displayed in message column (.tippy-target to ignore the tippy trigger)
|
||||
sel := doc.doc.Find("#commits-table tbody tr td.message .tippy-target .commit-status")
|
||||
assert.Equal(t, 1, sel.Length())
|
||||
for _, class := range classes {
|
||||
assert.True(t, sel.HasClass(class))
|
||||
@@ -145,7 +150,12 @@ func TestRepoCommitsStatusParallel(t *testing.T) {
|
||||
go func(parentT *testing.T, i int) {
|
||||
parentT.Run(fmt.Sprintf("ParallelCreateStatus_%d", i), func(t *testing.T) {
|
||||
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeRepoStatus)
|
||||
runBody := doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CommitStatusState("pending"))
|
||||
runBody := doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{
|
||||
State: api.CommitStatusPending,
|
||||
TargetURL: "http://test.ci/",
|
||||
Description: "",
|
||||
Context: "testci",
|
||||
})
|
||||
runBody(t)
|
||||
wg.Done()
|
||||
})
|
||||
@@ -153,3 +163,43 @@ func TestRepoCommitsStatusParallel(t *testing.T) {
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestRepoCommitsStatusMultiple(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
// Request repository commits page
|
||||
req := NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
doc := NewHTMLParser(t, resp.Body)
|
||||
// Get first commit URL
|
||||
commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href")
|
||||
assert.True(t, exists)
|
||||
assert.NotEmpty(t, commitURL)
|
||||
|
||||
// Call API to add status for commit
|
||||
ctx := NewAPITestContext(t, "user2", "repo1", auth_model.AccessTokenScopeRepo)
|
||||
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{
|
||||
State: api.CommitStatusSuccess,
|
||||
TargetURL: "http://test.ci/",
|
||||
Description: "",
|
||||
Context: "testci",
|
||||
}))
|
||||
|
||||
t.Run("CreateStatus", doAPICreateCommitStatus(ctx, path.Base(commitURL), api.CreateStatusOption{
|
||||
State: api.CommitStatusSuccess,
|
||||
TargetURL: "http://test.ci/",
|
||||
Description: "",
|
||||
Context: "other_context",
|
||||
}))
|
||||
|
||||
req = NewRequest(t, "GET", "/user2/repo1/commits/branch/master")
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
doc = NewHTMLParser(t, resp.Body)
|
||||
// Check that the data-tippy="commit-statuses" (for trigger) and commit-status (svg) are present
|
||||
sel := doc.doc.Find("#commits-table tbody tr td.message [data-tippy=\"commit-statuses\"] .commit-status")
|
||||
assert.Equal(t, 1, sel.Length())
|
||||
}
|
||||
Reference in new issue
Block a user