@@ -468,6 +468,103 @@ func TestIncomingWebhookRule(t *testing.T) {
468468 }
469469}
470470
471+ func TestMatchRepo (t * testing.T ) {
472+ tests := []struct {
473+ name string
474+ eventURL string
475+ repoURL string
476+ wantMatch bool
477+ wantError bool
478+ errorCheck string
479+ }{
480+ // Exact matching
481+ {
482+ name : "exact match" ,
483+ eventURL : "https://github.com/tektoncd/pipelines-as-code" ,
484+ repoURL : "https://github.com/tektoncd/pipelines-as-code" ,
485+ wantMatch : true ,
486+ },
487+ {
488+ name : "no substring match" ,
489+ eventURL : "https://github.com/forked/pipelines-as-code" ,
490+ repoURL : "https://github.com/tektoncd/pipelines-as-code" ,
491+ wantMatch : false ,
492+ },
493+ // Wildcard * - matches zero or more characters
494+ {
495+ name : "glob * - prefix pattern" ,
496+ eventURL : "https://github.com/tektoncd/pipelines-as-code" ,
497+ repoURL : "https://github.com/tektoncd/*" ,
498+ wantMatch : true ,
499+ },
500+ {
501+ name : "glob * - must match from start" ,
502+ eventURL : "https://gitlab.com/tektoncd/pipelines-as-code" ,
503+ repoURL : "https://github.com/tektoncd/*" ,
504+ wantMatch : false ,
505+ },
506+ {
507+ name : "glob * - substring match with wildcards" ,
508+ eventURL : "https://github.com/tektoncd/pipelines-as-code" ,
509+ repoURL : "*/tektoncd/*" ,
510+ wantMatch : true ,
511+ },
512+ {
513+ name : "glob * - catch-all" ,
514+ eventURL : "https://github.com/tektoncd/pipelines-as-code" ,
515+ repoURL : "*" ,
516+ wantMatch : true ,
517+ },
518+ // Wildcard ? - matches exactly one character
519+ {
520+ name : "glob ? - single char match" ,
521+ eventURL : "https://github.com/tektoncd/pipelines-as-code-v2" ,
522+ repoURL : "https://github.com/tektoncd/pipelines-as-code-v?" ,
523+ wantMatch : true ,
524+ },
525+ // Character classes [...]
526+ {
527+ name : "glob [range] - character class" ,
528+ eventURL : "https://gitlab.com/tektoncd/pipelines-as-code" ,
529+ repoURL : "https://[a-z]*.com/tektoncd/pipelines-as-code" ,
530+ wantMatch : true ,
531+ },
532+ // Error handling
533+ {
534+ name : "invalid glob - unclosed bracket" ,
535+ eventURL : "https://github.com/tektoncd/pipelines-as-code" ,
536+ repoURL : "https://[github.com/tektoncd/pipelines-as-code" ,
537+ wantMatch : false ,
538+ wantError : true ,
539+ errorCheck : "unexpected end of input" ,
540+ },
541+ }
542+
543+ for _ , tt := range tests {
544+ t .Run (tt .name , func (t * testing.T ) {
545+ gotMatch , err := matchRepo (tt .eventURL , tt .repoURL )
546+
547+ if tt .wantError {
548+ if err == nil {
549+ t .Errorf ("matchRepo() expected error but got nil" )
550+ return
551+ }
552+ if tt .errorCheck != "" {
553+ assert .ErrorContains (t , err , tt .errorCheck )
554+ }
555+ } else {
556+ if err != nil {
557+ t .Errorf ("matchRepo() unexpected error = %v" , err )
558+ return
559+ }
560+ if gotMatch != tt .wantMatch {
561+ t .Errorf ("matchRepo() gotMatch = %v, want %v for eventURL=%q, repoURL=%q" , gotMatch , tt .wantMatch , tt .eventURL , tt .repoURL )
562+ }
563+ }
564+ })
565+ }
566+ }
567+
471568func TestMatchTarget (t * testing.T ) {
472569 tests := []struct {
473570 name string
0 commit comments