aboutsummaryrefslogtreecommitdiffstats
path: root/models/webhook_test.go
diff options
context:
space:
mode:
authorWGH <wgh@torlan.ru>2019-09-09 08:48:21 +0300
committerLauris BH <lauris.buksis@zzdats.lv>2019-09-09 08:48:21 +0300
commit6ddd3b0b470d16dfe62caf5fff21011cfff44a76 (patch)
tree05d4c7fedf8af21b489003890be000f839f69a51 /models/webhook_test.go
parent0118b6aaf8ada3edd67cb975c776f6f124178ad2 (diff)
downloadgitea-6ddd3b0b470d16dfe62caf5fff21011cfff44a76.tar.gz
gitea-6ddd3b0b470d16dfe62caf5fff21011cfff44a76.zip
Implement webhook branch filter (#7791)
* Fix validate() function to handle errors in embedded anon structs * Implement webhook branch filter See #2025, #3998.
Diffstat (limited to 'models/webhook_test.go')
-rw-r--r--models/webhook_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/models/webhook_test.go b/models/webhook_test.go
index d2fb3ea6ed..343000f5b5 100644
--- a/models/webhook_test.go
+++ b/models/webhook_test.go
@@ -270,6 +270,40 @@ func TestPrepareWebhooks(t *testing.T) {
}
}
+func TestPrepareWebhooksBranchFilterMatch(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+
+ repo := AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository)
+ hookTasks := []*HookTask{
+ {RepoID: repo.ID, HookID: 4, EventType: HookEventPush},
+ }
+ for _, hookTask := range hookTasks {
+ AssertNotExistsBean(t, hookTask)
+ }
+ // this test also ensures that * doesn't handle / in any special way (like shell would)
+ assert.NoError(t, PrepareWebhooks(repo, HookEventPush, &api.PushPayload{Ref: "refs/heads/feature/7791"}))
+ for _, hookTask := range hookTasks {
+ AssertExistsAndLoadBean(t, hookTask)
+ }
+}
+
+func TestPrepareWebhooksBranchFilterNoMatch(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+
+ repo := AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository)
+ hookTasks := []*HookTask{
+ {RepoID: repo.ID, HookID: 4, EventType: HookEventPush},
+ }
+ for _, hookTask := range hookTasks {
+ AssertNotExistsBean(t, hookTask)
+ }
+ assert.NoError(t, PrepareWebhooks(repo, HookEventPush, &api.PushPayload{Ref: "refs/heads/fix_weird_bug"}))
+
+ for _, hookTask := range hookTasks {
+ AssertNotExistsBean(t, hookTask)
+ }
+}
+
// TODO TestHookTask_deliver
// TODO TestDeliverHooks