2023-03-23 07:04:15 +03:00
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package actions
import (
"testing"
webhook_module "code.gitea.io/gitea/modules/webhook"
"github.com/stretchr/testify/assert"
)
func TestCanGithubEventMatch ( t * testing . T ) {
testCases := [ ] struct {
desc string
eventName string
triggeredEvent webhook_module . HookEventType
expected bool
} {
// registry_package event
{
"registry_package matches" ,
2023-06-26 09:33:18 +03:00
GithubEventRegistryPackage ,
2023-03-23 07:04:15 +03:00
webhook_module . HookEventPackage ,
true ,
} ,
{
"registry_package cannot match" ,
2023-06-26 09:33:18 +03:00
GithubEventRegistryPackage ,
2023-03-23 07:04:15 +03:00
webhook_module . HookEventPush ,
false ,
} ,
// issues event
{
"issue matches" ,
2023-06-26 09:33:18 +03:00
GithubEventIssues ,
2023-03-23 07:04:15 +03:00
webhook_module . HookEventIssueLabel ,
true ,
} ,
{
"issue cannot match" ,
2023-06-26 09:33:18 +03:00
GithubEventIssues ,
2023-03-23 07:04:15 +03:00
webhook_module . HookEventIssueComment ,
false ,
} ,
// issue_comment event
{
"issue_comment matches" ,
2023-06-26 09:33:18 +03:00
GithubEventIssueComment ,
2023-03-23 07:04:15 +03:00
webhook_module . HookEventIssueComment ,
true ,
} ,
{
"issue_comment cannot match" ,
2023-06-26 09:33:18 +03:00
GithubEventIssueComment ,
2023-03-23 07:04:15 +03:00
webhook_module . HookEventIssues ,
false ,
} ,
// pull_request event
{
"pull_request matches" ,
2023-06-26 09:33:18 +03:00
GithubEventPullRequest ,
2023-03-23 07:04:15 +03:00
webhook_module . HookEventPullRequestSync ,
true ,
} ,
{
"pull_request cannot match" ,
2023-06-26 09:33:18 +03:00
GithubEventPullRequest ,
2023-03-23 07:04:15 +03:00
webhook_module . HookEventPullRequestComment ,
false ,
} ,
// pull_request_target event
{
"pull_request_target matches" ,
2023-06-26 09:33:18 +03:00
GithubEventPullRequest ,
2023-03-23 07:04:15 +03:00
webhook_module . HookEventPullRequest ,
true ,
} ,
{
"pull_request_target cannot match" ,
2023-06-26 09:33:18 +03:00
GithubEventPullRequest ,
2023-03-23 07:04:15 +03:00
webhook_module . HookEventPullRequestComment ,
false ,
} ,
// pull_request_review event
{
"pull_request_review matches" ,
2023-06-26 09:33:18 +03:00
GithubEventPullRequestReview ,
2023-03-23 07:04:15 +03:00
webhook_module . HookEventPullRequestReviewComment ,
true ,
} ,
{
"pull_request_review cannot match" ,
2023-06-26 09:33:18 +03:00
GithubEventPullRequestReview ,
2023-03-23 07:04:15 +03:00
webhook_module . HookEventPullRequestComment ,
false ,
} ,
// other events
{
"create event" ,
2023-06-26 09:33:18 +03:00
GithubEventCreate ,
2023-03-23 07:04:15 +03:00
webhook_module . HookEventCreate ,
true ,
} ,
2024-02-22 17:47:35 +03:00
{
"create pull request comment" ,
GithubEventIssueComment ,
webhook_module . HookEventPullRequestComment ,
true ,
} ,
2023-03-23 07:04:15 +03:00
}
for _ , tc := range testCases {
t . Run ( tc . desc , func ( t * testing . T ) {
assert . Equalf ( t , tc . expected , canGithubEventMatch ( tc . eventName , tc . triggeredEvent ) , "canGithubEventMatch(%v, %v)" , tc . eventName , tc . triggeredEvent )
} )
}
}