github.com/argoproj/argo-events@v1.9.1/eventsources/common/webhook/fake.go (about) 1 /* 2 Copyright 2018 BlackRock, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package webhook 18 19 import ( 20 "net/http" 21 22 "github.com/argoproj/argo-events/common/logging" 23 metrics "github.com/argoproj/argo-events/metrics" 24 "github.com/argoproj/argo-events/pkg/apis/eventsource/v1alpha1" 25 ) 26 27 var Hook = &v1alpha1.WebhookContext{ 28 Endpoint: "/fake", 29 Port: "12000", 30 URL: "test-url", 31 } 32 33 type FakeHttpWriter struct { 34 HeaderStatus int 35 Payload []byte 36 } 37 38 func (f *FakeHttpWriter) Header() http.Header { 39 return http.Header{} 40 } 41 42 func (f *FakeHttpWriter) Write(body []byte) (int, error) { 43 f.Payload = body 44 return len(body), nil 45 } 46 47 func (f *FakeHttpWriter) WriteHeader(status int) { 48 f.HeaderStatus = status 49 } 50 51 type FakeRouter struct { 52 route *Route 53 } 54 55 func (f *FakeRouter) GetRoute() *Route { 56 return f.route 57 } 58 59 func (f *FakeRouter) HandleRoute(writer http.ResponseWriter, request *http.Request) { 60 } 61 62 func (f *FakeRouter) PostActivate() error { 63 return nil 64 } 65 66 func (f *FakeRouter) PostInactivate() error { 67 return nil 68 } 69 70 func GetFakeRoute() *Route { 71 logger := logging.NewArgoEventsLogger() 72 return NewRoute(Hook, logger, "fake-event-source", "fake-event", metrics.NewMetrics("fake-ns")) 73 }