Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit355e9a9

Browse files
authored
Add a webhook push test for dev branch (#34421)
1 parent0902d42 commit355e9a9

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

‎tests/integration/repo_webhook_test.go‎

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,21 @@ func TestNewWebHookLink(t *testing.T) {
5656
}
5757
}
5858

59-
functestAPICreateWebhookForRepo(t*testing.T,session*TestSession,userName,repoName,url,eventstring) {
59+
functestAPICreateWebhookForRepo(t*testing.T,session*TestSession,userName,repoName,url,eventstring,branchFilter...string) {
6060
token:=getTokenForLoggedInUser(t,session,auth_model.AccessTokenScopeAll)
61+
varbranchFilterStringstring
62+
iflen(branchFilter)>0 {
63+
branchFilterString=branchFilter[0]
64+
}
6165
req:=NewRequestWithJSON(t,"POST","/api/v1/repos/"+userName+"/"+repoName+"/hooks", api.CreateHookOption{
6266
Type:"gitea",
6367
Config: api.CreateHookOptionConfig{
6468
"content_type":"json",
6569
"url":url,
6670
},
67-
Events: []string{event},
68-
Active:true,
71+
Events: []string{event},
72+
Active:true,
73+
BranchFilter:branchFilterString,
6974
}).AddTokenAuth(token)
7075
MakeRequest(t,req,http.StatusCreated)
7176
}
@@ -371,6 +376,45 @@ func Test_WebhookPush(t *testing.T) {
371376
})
372377
}
373378

379+
funcTest_WebhookPushDevBranch(t*testing.T) {
380+
varpayloads []api.PushPayload
381+
vartriggeredEventstring
382+
provider:=newMockWebhookProvider(func(r*http.Request) {
383+
content,_:=io.ReadAll(r.Body)
384+
varpayload api.PushPayload
385+
err:=json.Unmarshal(content,&payload)
386+
assert.NoError(t,err)
387+
payloads=append(payloads,payload)
388+
triggeredEvent="push"
389+
},http.StatusOK)
390+
deferprovider.Close()
391+
392+
onGiteaRun(t,func(t*testing.T,giteaURL*url.URL) {
393+
// 1. create a new webhook with special webhook for repo1
394+
session:=loginUser(t,"user2")
395+
396+
// only for dev branch
397+
testAPICreateWebhookForRepo(t,session,"user2","repo1",provider.URL(),"push","develop")
398+
399+
// 2. this should not trigger the webhook
400+
testCreateFile(t,session,"user2","repo1","master","test_webhook_push.md","# a test file for webhook push")
401+
assert.Empty(t,triggeredEvent)
402+
assert.Empty(t,payloads)
403+
404+
// 3. trigger the webhook
405+
testCreateFile(t,session,"user2","repo1","develop","test_webhook_push.md","# a test file for webhook push")
406+
407+
// 4. validate the webhook is triggered
408+
assert.Equal(t,"push",triggeredEvent)
409+
assert.Len(t,payloads,1)
410+
assert.Equal(t,"repo1",payloads[0].Repo.Name)
411+
assert.Equal(t,"develop",payloads[0].Branch())
412+
assert.Equal(t,"user2/repo1",payloads[0].Repo.FullName)
413+
assert.Len(t,payloads[0].Commits,1)
414+
assert.Equal(t, []string{"test_webhook_push.md"},payloads[0].Commits[0].Added)
415+
})
416+
}
417+
374418
funcTest_WebhookIssue(t*testing.T) {
375419
varpayloads []api.IssuePayload
376420
vartriggeredEventstring

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp