You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

webhook_test.go 2.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package webhook
  5. import (
  6. "testing"
  7. "code.gitea.io/gitea/models"
  8. api "code.gitea.io/gitea/modules/structs"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestPrepareWebhooks(t *testing.T) {
  12. assert.NoError(t, models.PrepareTestDatabase())
  13. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
  14. hookTasks := []*models.HookTask{
  15. {RepoID: repo.ID, HookID: 1, EventType: models.HookEventPush},
  16. }
  17. for _, hookTask := range hookTasks {
  18. models.AssertNotExistsBean(t, hookTask)
  19. }
  20. assert.NoError(t, PrepareWebhooks(repo, models.HookEventPush, &api.PushPayload{}))
  21. for _, hookTask := range hookTasks {
  22. models.AssertExistsAndLoadBean(t, hookTask)
  23. }
  24. }
  25. func TestPrepareWebhooksBranchFilterMatch(t *testing.T) {
  26. assert.NoError(t, models.PrepareTestDatabase())
  27. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
  28. hookTasks := []*models.HookTask{
  29. {RepoID: repo.ID, HookID: 4, EventType: models.HookEventPush},
  30. }
  31. for _, hookTask := range hookTasks {
  32. models.AssertNotExistsBean(t, hookTask)
  33. }
  34. // this test also ensures that * doesn't handle / in any special way (like shell would)
  35. assert.NoError(t, PrepareWebhooks(repo, models.HookEventPush, &api.PushPayload{Ref: "refs/heads/feature/7791"}))
  36. for _, hookTask := range hookTasks {
  37. models.AssertExistsAndLoadBean(t, hookTask)
  38. }
  39. }
  40. func TestPrepareWebhooksBranchFilterNoMatch(t *testing.T) {
  41. assert.NoError(t, models.PrepareTestDatabase())
  42. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
  43. hookTasks := []*models.HookTask{
  44. {RepoID: repo.ID, HookID: 4, EventType: models.HookEventPush},
  45. }
  46. for _, hookTask := range hookTasks {
  47. models.AssertNotExistsBean(t, hookTask)
  48. }
  49. assert.NoError(t, PrepareWebhooks(repo, models.HookEventPush, &api.PushPayload{Ref: "refs/heads/fix_weird_bug"}))
  50. for _, hookTask := range hookTasks {
  51. models.AssertNotExistsBean(t, hookTask)
  52. }
  53. }
  54. // TODO TestHookTask_deliver
  55. // TODO TestDeliverHooks