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

github_test.go 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Copyright 2023 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package actions
  4. import (
  5. "testing"
  6. webhook_module "code.gitea.io/gitea/modules/webhook"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestCanGithubEventMatch(t *testing.T) {
  10. testCases := []struct {
  11. desc string
  12. eventName string
  13. triggeredEvent webhook_module.HookEventType
  14. expected bool
  15. }{
  16. // registry_package event
  17. {
  18. "registry_package matches",
  19. GithubEventRegistryPackage,
  20. webhook_module.HookEventPackage,
  21. true,
  22. },
  23. {
  24. "registry_package cannot match",
  25. GithubEventRegistryPackage,
  26. webhook_module.HookEventPush,
  27. false,
  28. },
  29. // issues event
  30. {
  31. "issue matches",
  32. GithubEventIssues,
  33. webhook_module.HookEventIssueLabel,
  34. true,
  35. },
  36. {
  37. "issue cannot match",
  38. GithubEventIssues,
  39. webhook_module.HookEventIssueComment,
  40. false,
  41. },
  42. // issue_comment event
  43. {
  44. "issue_comment matches",
  45. GithubEventIssueComment,
  46. webhook_module.HookEventIssueComment,
  47. true,
  48. },
  49. {
  50. "issue_comment cannot match",
  51. GithubEventIssueComment,
  52. webhook_module.HookEventIssues,
  53. false,
  54. },
  55. // pull_request event
  56. {
  57. "pull_request matches",
  58. GithubEventPullRequest,
  59. webhook_module.HookEventPullRequestSync,
  60. true,
  61. },
  62. {
  63. "pull_request cannot match",
  64. GithubEventPullRequest,
  65. webhook_module.HookEventPullRequestComment,
  66. false,
  67. },
  68. // pull_request_target event
  69. {
  70. "pull_request_target matches",
  71. GithubEventPullRequest,
  72. webhook_module.HookEventPullRequest,
  73. true,
  74. },
  75. {
  76. "pull_request_target cannot match",
  77. GithubEventPullRequest,
  78. webhook_module.HookEventPullRequestComment,
  79. false,
  80. },
  81. // pull_request_review event
  82. {
  83. "pull_request_review matches",
  84. GithubEventPullRequestReview,
  85. webhook_module.HookEventPullRequestReviewComment,
  86. true,
  87. },
  88. {
  89. "pull_request_review cannot match",
  90. GithubEventPullRequestReview,
  91. webhook_module.HookEventPullRequestComment,
  92. false,
  93. },
  94. // other events
  95. {
  96. "create event",
  97. GithubEventCreate,
  98. webhook_module.HookEventCreate,
  99. true,
  100. },
  101. }
  102. for _, tc := range testCases {
  103. t.Run(tc.desc, func(t *testing.T) {
  104. assert.Equalf(t, tc.expected, canGithubEventMatch(tc.eventName, tc.triggeredEvent), "canGithubEventMatch(%v, %v)", tc.eventName, tc.triggeredEvent)
  105. })
  106. }
  107. }