Add injection function to webhook

This commit is contained in:
Fabian Reinartz 2015-10-12 07:28:25 +02:00
parent ee6ca25db0
commit aca2089216
1 changed files with 10 additions and 0 deletions

View File

@ -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()