From 8171db0c3680382f5b1e1b97a0d10c75328be4ce Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 11 May 2025 12:32:38 -0700 Subject: [PATCH] Fix test --- tests/integration/repo_webhook_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/integration/repo_webhook_test.go b/tests/integration/repo_webhook_test.go index 476dd8a63b..eab58922e6 100644 --- a/tests/integration/repo_webhook_test.go +++ b/tests/integration/repo_webhook_test.go @@ -21,6 +21,7 @@ import ( "code.gitea.io/gitea/modules/gitrepo" "code.gitea.io/gitea/modules/json" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/util" webhook_module "code.gitea.io/gitea/modules/webhook" "code.gitea.io/gitea/tests" @@ -64,8 +65,9 @@ func testAPICreateWebhookForRepo(t *testing.T, session *TestSession, userName, r "content_type": "json", "url": url, }, - Events: []string{event}, - Active: true, + Events: []string{event}, + Active: true, + BranchFilter: util.Iif(len(branchFilter) > 0, branchFilter[0], ""), }).AddTokenAuth(token) MakeRequest(t, req, http.StatusCreated) } @@ -342,10 +344,15 @@ func Test_WebhookPushDevBranch(t *testing.T) { // only for dev branch testAPICreateWebhookForRepo(t, session, "user2", "repo1", provider.URL(), "push", "develop") - // 2. trigger the webhook + // 2. this should not trigger the webhook + testCreateFile(t, session, "user2", "repo1", "master", "test_webhook_push.md", "# a test file for webhook push") + assert.Equal(t, "", triggeredEvent) + assert.Len(t, payloads, 0) + + // 3. trigger the webhook testCreateFile(t, session, "user2", "repo1", "develop", "test_webhook_push.md", "# a test file for webhook push") - // 3. validate the webhook is triggered + // 4. validate the webhook is triggered assert.Equal(t, "push", triggeredEvent) assert.Len(t, payloads, 1) assert.Equal(t, "repo1", payloads[0].Repo.Name)