From aca2089216235df8ef8e89a0f716ee234e6600f3 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Mon, 12 Oct 2015 07:28:25 +0200 Subject: [PATCH] Add injection function to webhook --- test/mock.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/mock.go b/test/mock.go index b0c719d3..fe63d13c 100644 --- a/test/mock.go +++ b/test/mock.go @@ -216,8 +216,11 @@ func equalTime(a, b time.Time, opts *AcceptanceOpts) bool { } type MockWebhook struct { + opts *AcceptanceOpts collector *Collector listener net.Listener + + Func func(timestamp float64) bool } func NewWebhook(c *Collector) *MockWebhook { @@ -238,6 +241,13 @@ func NewWebhook(c *Collector) *MockWebhook { } func (ws *MockWebhook) ServeHTTP(w http.ResponseWriter, req *http.Request) { + // Inject Func if it exists. + if ws.Func != nil { + if ws.Func(ws.opts.relativeTime(time.Now())) { + return + } + } + dec := json.NewDecoder(req.Body) defer req.Body.Close()