mirror of
https://github.com/taigrr/github-to-signal.git
synced 2026-04-02 11:19:15 -07:00
Configure which events to forward via comma-separated 'events' config.
Supports event-level ('push', 'pull_request') or event:action-level
('pull_request:opened', 'issues:closed') filtering.
Empty/omitted = forward everything (backwards compatible).
33 lines
1.2 KiB
Go
33 lines
1.2 KiB
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestEventFilter(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
filters []string
|
|
event string
|
|
action string
|
|
want bool
|
|
}{
|
|
{"empty allows all", nil, "push", "", true},
|
|
{"event only", []string{"push"}, "push", "", true},
|
|
{"event only blocks other", []string{"push"}, "issues", "opened", false},
|
|
{"event:action match", []string{"pull_request:opened"}, "pull_request", "opened", true},
|
|
{"event:action no match", []string{"pull_request:opened"}, "pull_request", "closed", false},
|
|
{"multiple actions", []string{"pull_request:opened", "pull_request:closed"}, "pull_request", "closed", true},
|
|
{"mixed event and action", []string{"push", "pull_request:opened"}, "push", "", true},
|
|
{"mixed blocks filtered", []string{"push", "pull_request:opened"}, "pull_request", "closed", false},
|
|
{"case insensitive", []string{"Pull_Request:Opened"}, "pull_request", "opened", true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
ef := ParseEventFilter(tt.filters)
|
|
if got := ef.Allowed(tt.event, tt.action); got != tt.want {
|
|
t.Errorf("Allowed(%q, %q) = %v, want %v", tt.event, tt.action, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|