diff --git a/middleware/job/webhook.go b/middleware/job/webhook.go index c57197b7..b036e6d9 100644 --- a/middleware/job/webhook.go +++ b/middleware/job/webhook.go @@ -23,6 +23,9 @@ func Webhook(next HandlerFunc) HandlerFunc { if err := next(ctx, et, j); err != nil { return err } + if et != StateChange { + return nil + } if len(j.Webhooks) == 0 { return nil } diff --git a/middleware/job/webhook_test.go b/middleware/job/webhook_test.go index 9f22e2d2..de093293 100644 --- a/middleware/job/webhook_test.go +++ b/middleware/job/webhook_test.go @@ -41,7 +41,7 @@ func TestWebhookOK(t *testing.T) { }}, } - assert.NoError(t, hm(context.Background(), Read, j)) + assert.NoError(t, hm(context.Background(), StateChange, j)) <-received } @@ -80,7 +80,7 @@ func TestWebhookRetry(t *testing.T) { }}, } - assert.NoError(t, hm(context.Background(), Read, j)) + assert.NoError(t, hm(context.Background(), StateChange, j)) <-received } @@ -118,6 +118,11 @@ func TestWebhookOKWithHeaders(t *testing.T) { }}, } - assert.NoError(t, hm(context.Background(), Read, j)) + assert.NoError(t, hm(context.Background(), StateChange, j)) <-received } + +func TestWebhookIgnored(t *testing.T) { + hm := ApplyMiddleware(NoOpHandlerFunc, []MiddlewareFunc{Webhook}) + assert.NoError(t, hm(context.Background(), Read, nil)) +}