@@ -127,6 +127,34 @@ func TestHandlePushEventNoPipeline(t *testing.T) {
127127 }
128128}
129129
130+ func TestHandlePushEventNoMatchingRules (t * testing.T ) {
131+ as := test .MakeAPIServer (t , "/api/v3/repos/Codertocat/Hello-World/contents/.tekton_ci.yaml" , "6113728f27ae82c7b1a177c8d03f9e96e0adf246" , "testdata/content_match_only_master.json" )
132+ defer as .Close ()
133+ scmClient , err := factory .NewClient ("github" , as .URL , "" , factory .Client (as .Client ()))
134+ if err != nil {
135+ t .Fatal (err )
136+ }
137+ gitClient := git .New (scmClient , secrets .NewMock (), metrics .NewMock ())
138+ fakeTektonClient := fakeclientset .NewSimpleClientset ()
139+ fakeClient := fake .NewSimpleClientset ()
140+ vc := volumes .New (fakeClient )
141+ logger := zaptest .NewLogger (t , zaptest .Level (zap .WarnLevel ))
142+ h := New (gitClient , fakeTektonClient , vc , metrics .NewMock (), testConfiguration (), testNS , logger .Sugar ())
143+ req := test .MakeHookRequest (t , "../testdata/github_push.json" , "push" )
144+ rec := httptest .NewRecorder ()
145+
146+ h .ServeHTTP (rec , req )
147+
148+ w := rec .Result ()
149+ if w .StatusCode != http .StatusOK {
150+ t .Fatalf ("got %d, want %d: %s" , w .StatusCode , http .StatusOK , mustReadBody (t , w ))
151+ }
152+ _ , err = fakeTektonClient .TektonV1beta1 ().PipelineRuns (testNS ).Get ("" , metav1.GetOptions {})
153+ if ! errors .IsNotFound (err ) {
154+ t .Fatalf ("pipelinerun was created with no matching rules" )
155+ }
156+ }
157+
130158func mustReadBody (t * testing.T , req * http.Response ) []byte {
131159 t .Helper ()
132160 b , err := ioutil .ReadAll (req .Body )
0 commit comments