aboutsummaryrefslogtreecommitdiffstats
path: root/tests/integration
diff options
context:
space:
mode:
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/api_actions_run_test.go (renamed from tests/integration/api_actions_delete_run_test.go)38
-rw-r--r--tests/integration/api_repo_edit_test.go3
-rw-r--r--tests/integration/api_repo_git_trees_test.go26
-rw-r--r--tests/integration/editor_test.go17
-rw-r--r--tests/integration/empty_repo_test.go5
-rw-r--r--tests/integration/pull_diff_test.go4
-rw-r--r--tests/integration/repo_webhook_test.go79
7 files changed, 149 insertions, 23 deletions
diff --git a/tests/integration/api_actions_delete_run_test.go b/tests/integration/api_actions_run_test.go
index 5b41702c57..a0292f8f8b 100644
--- a/tests/integration/api_actions_delete_run_test.go
+++ b/tests/integration/api_actions_run_test.go
@@ -18,6 +18,44 @@ import (
"github.com/stretchr/testify/assert"
)
+func TestAPIActionsGetWorkflowRun(t *testing.T) {
+ defer prepareTestEnvActionsArtifacts(t)()
+
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
+ user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
+ session := loginUser(t, user.Name)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
+
+ req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/runs/802802", repo.FullName())).
+ AddTokenAuth(token)
+ MakeRequest(t, req, http.StatusNotFound)
+ req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/runs/802", repo.FullName())).
+ AddTokenAuth(token)
+ MakeRequest(t, req, http.StatusNotFound)
+ req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/runs/803", repo.FullName())).
+ AddTokenAuth(token)
+ MakeRequest(t, req, http.StatusOK)
+}
+
+func TestAPIActionsGetWorkflowJob(t *testing.T) {
+ defer prepareTestEnvActionsArtifacts(t)()
+
+ repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
+ user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
+ session := loginUser(t, user.Name)
+ token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
+
+ req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/jobs/198198", repo.FullName())).
+ AddTokenAuth(token)
+ MakeRequest(t, req, http.StatusNotFound)
+ req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/jobs/198", repo.FullName())).
+ AddTokenAuth(token)
+ MakeRequest(t, req, http.StatusOK)
+ req = NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/actions/jobs/196", repo.FullName())).
+ AddTokenAuth(token)
+ MakeRequest(t, req, http.StatusNotFound)
+}
+
func TestAPIActionsDeleteRunCheckPermission(t *testing.T) {
defer prepareTestEnvActionsArtifacts(t)()
diff --git a/tests/integration/api_repo_edit_test.go b/tests/integration/api_repo_edit_test.go
index 7de8910ee0..e228da26e9 100644
--- a/tests/integration/api_repo_edit_test.go
+++ b/tests/integration/api_repo_edit_test.go
@@ -53,9 +53,8 @@ func getRepoEditOptionFromRepo(repo *repo_model.Repository) *api.EditRepoOption
hasWiki = true
} else if unit, err := repo.GetUnit(db.DefaultContext, unit_model.TypeExternalWiki); err == nil {
hasWiki = true
- config := unit.ExternalWikiConfig()
externalWiki = &api.ExternalWiki{
- ExternalWikiURL: config.ExternalWikiURL,
+ ExternalWikiURL: unit.ExternalWikiConfig().ExternalWikiURL,
}
}
defaultBranch := repo.DefaultBranch
diff --git a/tests/integration/api_repo_git_trees_test.go b/tests/integration/api_repo_git_trees_test.go
index 47063d9091..ea7630f414 100644
--- a/tests/integration/api_repo_git_trees_test.go
+++ b/tests/integration/api_repo_git_trees_test.go
@@ -11,7 +11,11 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
+ api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/tests"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAPIReposGitTrees(t *testing.T) {
@@ -32,13 +36,21 @@ func TestAPIReposGitTrees(t *testing.T) {
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
// Test a public repo that anyone can GET the tree of
- for _, ref := range [...]string{
- "master", // Branch
- repo1TreeSHA, // Tree SHA
- } {
- req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/git/trees/%s", user2.Name, repo1.Name, ref)
- MakeRequest(t, req, http.StatusOK)
- }
+ _ = MakeRequest(t, NewRequest(t, "GET", "/api/v1/repos/user2/repo1/git/trees/master"), http.StatusOK)
+
+ resp := MakeRequest(t, NewRequest(t, "GET", "/api/v1/repos/user2/repo1/git/trees/62fb502a7172d4453f0322a2cc85bddffa57f07a?per_page=1"), http.StatusOK)
+ var respGitTree api.GitTreeResponse
+ DecodeJSON(t, resp, &respGitTree)
+ assert.True(t, respGitTree.Truncated)
+ require.Len(t, respGitTree.Entries, 1)
+ assert.Equal(t, "File-WoW", respGitTree.Entries[0].Path)
+
+ resp = MakeRequest(t, NewRequest(t, "GET", "/api/v1/repos/user2/repo1/git/trees/62fb502a7172d4453f0322a2cc85bddffa57f07a?page=2&per_page=1"), http.StatusOK)
+ respGitTree = api.GitTreeResponse{}
+ DecodeJSON(t, resp, &respGitTree)
+ assert.False(t, respGitTree.Truncated)
+ require.Len(t, respGitTree.Entries, 1)
+ assert.Equal(t, "README.md", respGitTree.Entries[0].Path)
// Tests a private repo with no token so will fail
for _, ref := range [...]string{
diff --git a/tests/integration/editor_test.go b/tests/integration/editor_test.go
index ac1fb2abff..8c45d8881c 100644
--- a/tests/integration/editor_test.go
+++ b/tests/integration/editor_test.go
@@ -56,7 +56,7 @@ func TestEditor(t *testing.T) {
func testEditorCreateFile(t *testing.T) {
session := loginUser(t, "user2")
- testCreateFile(t, session, "user2", "repo1", "master", "test.txt", "Content")
+ testCreateFile(t, session, "user2", "repo1", "master", "", "test.txt", "Content")
testEditorActionPostRequestError(t, session, "/user2/repo1/_new/master/", map[string]string{
"tree_path": "test.txt",
"commit_choice": "direct",
@@ -69,11 +69,16 @@ func testEditorCreateFile(t *testing.T) {
}, `Branch "master" already exists in this repository.`)
}
-func testCreateFile(t *testing.T, session *TestSession, user, repo, branch, filePath, content string) {
- testEditorActionEdit(t, session, user, repo, "_new", branch, "", map[string]string{
- "tree_path": filePath,
- "content": content,
- "commit_choice": "direct",
+func testCreateFile(t *testing.T, session *TestSession, user, repo, baseBranchName, newBranchName, filePath, content string) {
+ commitChoice := "direct"
+ if newBranchName != "" && newBranchName != baseBranchName {
+ commitChoice = "commit-to-new-branch"
+ }
+ testEditorActionEdit(t, session, user, repo, "_new", baseBranchName, "", map[string]string{
+ "tree_path": filePath,
+ "content": content,
+ "commit_choice": commitChoice,
+ "new_branch_name": newBranchName,
})
}
diff --git a/tests/integration/empty_repo_test.go b/tests/integration/empty_repo_test.go
index 6a8c70f12f..127df5919d 100644
--- a/tests/integration/empty_repo_test.go
+++ b/tests/integration/empty_repo_test.go
@@ -75,6 +75,11 @@ func TestEmptyRepoAddFile(t *testing.T) {
req = NewRequest(t, "GET", "/api/v1/repos/user30/empty/raw/main/README.md").AddTokenAuth(token)
session.MakeRequest(t, req, http.StatusNotFound)
+ // test feed
+ req = NewRequest(t, "GET", "/user30/empty/rss/branch/main/README.md").AddTokenAuth(token).SetHeader("Accept", "application/rss+xml")
+ resp = session.MakeRequest(t, req, http.StatusOK)
+ assert.Contains(t, resp.Body.String(), "</rss>")
+
// create a new file
req = NewRequest(t, "GET", "/user30/empty/_new/"+setting.Repository.DefaultBranch)
resp = session.MakeRequest(t, req, http.StatusOK)
diff --git a/tests/integration/pull_diff_test.go b/tests/integration/pull_diff_test.go
index 5411250935..0b286fd2b2 100644
--- a/tests/integration/pull_diff_test.go
+++ b/tests/integration/pull_diff_test.go
@@ -25,10 +25,6 @@ func TestPullDiff_CommitRangePRDiff(t *testing.T) {
doTestPRDiff(t, "/user2/commitsonpr/pulls/1/files/4ca8bcaf27e28504df7bf996819665986b01c847..23576dd018294e476c06e569b6b0f170d0558705", true, []string{"test2.txt", "test3.txt", "test4.txt"})
}
-func TestPullDiff_StartingFromBaseToCommitPRDiff(t *testing.T) {
- doTestPRDiff(t, "/user2/commitsonpr/pulls/1/files/c5626fc9eff57eb1bb7b796b01d4d0f2f3f792a2", true, []string{"test1.txt", "test2.txt", "test3.txt"})
-}
-
func doTestPRDiff(t *testing.T, prDiffURL string, reviewBtnDisabled bool, expectedFilenames []string) {
defer tests.PrepareTestEnv(t)()
diff --git a/tests/integration/repo_webhook_test.go b/tests/integration/repo_webhook_test.go
index 1da7bc9d3c..f1abac8cfa 100644
--- a/tests/integration/repo_webhook_test.go
+++ b/tests/integration/repo_webhook_test.go
@@ -19,8 +19,10 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/commitstatus"
+ "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/json"
+ "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
webhook_module "code.gitea.io/gitea/modules/webhook"
"code.gitea.io/gitea/tests"
@@ -365,7 +367,7 @@ func Test_WebhookPush(t *testing.T) {
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "push")
// 2. trigger the webhook
- testCreateFile(t, session, "user2", "repo1", "master", "test_webhook_push.md", "# a test file for webhook push")
+ testCreateFile(t, session, "user2", "repo1", "master", "", "test_webhook_push.md", "# a test file for webhook push")
// 3. validate the webhook is triggered
assert.Equal(t, "push", triggeredEvent)
@@ -398,21 +400,90 @@ func Test_WebhookPushDevBranch(t *testing.T) {
testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "push", "develop")
// 2. this should not trigger the webhook
- testCreateFile(t, session, "user2", "repo1", "master", "test_webhook_push.md", "# a test file for webhook push")
+ testCreateFile(t, session, "user2", "repo1", "master", "", "test_webhook_push.md", "# a test file for webhook push")
assert.Empty(t, triggeredEvent)
assert.Empty(t, payloads)
+ repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
+ gitRepo, err := gitrepo.OpenRepository(t.Context(), repo1)
+ assert.NoError(t, err)
+ defer gitRepo.Close()
+
+ beforeCommitID, err := gitRepo.GetBranchCommitID("develop")
+ assert.NoError(t, err)
+
// 3. trigger the webhook
- testCreateFile(t, session, "user2", "repo1", "develop", "test_webhook_push.md", "# a test file for webhook push")
+ testCreateFile(t, session, "user2", "repo1", "develop", "", "test_webhook_push.md", "# a test file for webhook push")
+
+ afterCommitID, err := gitRepo.GetBranchCommitID("develop")
+ assert.NoError(t, err)
// 4. validate the webhook is triggered
assert.Equal(t, "push", triggeredEvent)
assert.Len(t, payloads, 1)
+ assert.Equal(t, "refs/heads/develop", payloads[0].Ref)
+ assert.Equal(t, beforeCommitID, payloads[0].Before)
+ assert.Equal(t, afterCommitID, payloads[0].After)
assert.Equal(t, "repo1", payloads[0].Repo.Name)
assert.Equal(t, "develop", payloads[0].Branch())
assert.Equal(t, "user2/repo1", payloads[0].Repo.FullName)
assert.Len(t, payloads[0].Commits, 1)
+ assert.Equal(t, afterCommitID, payloads[0].Commits[0].ID)
+ assert.Equal(t, setting.AppURL+"user2/repo1/compare/"+beforeCommitID+"..."+afterCommitID, payloads[0].CompareURL)
+ assert.Equal(t, []string{"test_webhook_push.md"}, payloads[0].Commits[0].Added)
+ assert.Empty(t, payloads[0].Commits[0].Removed)
+ })
+}
+
+func Test_WebhookPushToNewBranch(t *testing.T) {
+ var payloads []api.PushPayload
+ var triggeredEvent string
+ provider := newMockWebhookProvider(func(r *http.Request) {
+ content, _ := io.ReadAll(r.Body)
+ var payload api.PushPayload
+ err := json.Unmarshal(content, &payload)
+ assert.NoError(t, err)
+ payloads = append(payloads, payload)
+ triggeredEvent = "push"
+ }, http.StatusOK)
+ defer provider.Close()
+
+ onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
+ // 1. create a new webhook with special webhook for repo1
+ session := loginUser(t, "user2")
+
+ // only for dev branch
+ testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "push", "new_branch")
+
+ repo1 := unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
+ gitRepo, err := gitrepo.OpenRepository(t.Context(), repo1)
+ assert.NoError(t, err)
+ defer gitRepo.Close()
+
+ beforeCommitID, err := gitRepo.GetBranchCommitID("master")
+ assert.NoError(t, err)
+
+ // 2. trigger the webhook
+ testCreateFile(t, session, "user2", "repo1", "master", "new_branch", "test_webhook_push.md", "# a new push from new branch")
+
+ afterCommitID, err := gitRepo.GetBranchCommitID("new_branch")
+ assert.NoError(t, err)
+ emptyCommitID := git.Sha1ObjectFormat.EmptyObjectID().String()
+
+ // 4. validate the webhook is triggered
+ assert.Equal(t, "push", triggeredEvent)
+ assert.Len(t, payloads, 1)
+ assert.Equal(t, "refs/heads/new_branch", payloads[0].Ref)
+ assert.Equal(t, emptyCommitID, payloads[0].Before)
+ assert.Equal(t, afterCommitID, payloads[0].After)
+ assert.Equal(t, "repo1", payloads[0].Repo.Name)
+ assert.Equal(t, "new_branch", payloads[0].Branch())
+ assert.Equal(t, "user2/repo1", payloads[0].Repo.FullName)
+ assert.Len(t, payloads[0].Commits, 1)
+ assert.Equal(t, afterCommitID, payloads[0].Commits[0].ID)
+ assert.Equal(t, setting.AppURL+"user2/repo1/compare/"+beforeCommitID+"..."+afterCommitID, payloads[0].CompareURL)
assert.Equal(t, []string{"test_webhook_push.md"}, payloads[0].Commits[0].Added)
+ assert.Empty(t, payloads[0].Commits[0].Removed)
})
}
@@ -878,7 +949,7 @@ func Test_WebhookStatus_NoWrongTrigger(t *testing.T) {
testCreateWebhookForRepo(t, session, "gitea", "user2", "repo1", provider.URL(), "push_only")
// 2. trigger the webhook with a push action
- testCreateFile(t, session, "user2", "repo1", "master", "test_webhook_push.md", "# a test file for webhook push")
+ testCreateFile(t, session, "user2", "repo1", "master", "", "test_webhook_push.md", "# a test file for webhook push")
// 3. validate the webhook is triggered with right event
assert.Equal(t, "push", trigger)