missing repo on webhook

pull/5/head
Karolis Rusenas 2017-06-12 23:11:27 +01:00
parent 6b8df0e4fd
commit 525cb8fe3c
1 changed files with 31 additions and 2 deletions

View File

@ -33,7 +33,7 @@ func TestNativeWebhookHandler(t *testing.T) {
srv := NewTriggerServer(&Opts{Providers: providers})
srv.registerRoutes(srv.router)
req, err := http.NewRequest("POST", "/v1/native", bytes.NewBuffer([]byte(`{"client":"test_client", "mountpoint": "xx"}`)))
req, err := http.NewRequest("POST", "/v1/native", bytes.NewBuffer([]byte(`{"repository": {"name": "gcr.io/v2-namespace/hello-world", "tag": "1.1.1"}}`)))
if err != nil {
t.Fatalf("failed to create req: %s", err)
}
@ -47,6 +47,35 @@ func TestNativeWebhookHandler(t *testing.T) {
}
if len(fp.submitted) != 1 {
t.Errorf("unexpected number of events submitted: %d", len(fp.submitted))
t.Fatalf("unexpected number of events submitted: %d", len(fp.submitted))
}
}
func TestNativeWebhookHandlerNoRepoName(t *testing.T) {
fp := &fakeProvider{}
providers := map[string]provider.Provider{
fp.GetName(): fp,
}
srv := NewTriggerServer(&Opts{Providers: providers})
srv.registerRoutes(srv.router)
req, err := http.NewRequest("POST", "/v1/native", bytes.NewBuffer([]byte(`{"repository": { "tag": "1.1.1"}}`)))
if err != nil {
t.Fatalf("failed to create req: %s", err)
}
//The response recorder used to record HTTP responses
rec := httptest.NewRecorder()
srv.router.ServeHTTP(rec, req)
if rec.Code != 400 {
t.Errorf("unexpected status code: %d", rec.Code)
}
if len(fp.submitted) != 0 {
t.Fatalf("unexpected number of events submitted: %d", len(fp.submitted))
}
}