Skip to content

Commit

Permalink
chore: add test header for /test
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Gelloz committed Dec 1, 2022
1 parent 6ef7b4f commit 96032f4
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pkg/attempt.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Attempt struct {
NextRetryAfter time.Time `json:"nextRetryAfter,omitempty" bson:"nextRetryAfter,omitempty"`
}

func MakeAttempt(ctx context.Context, httpClient *http.Client, schedule []time.Duration, id string, attemptNb int, cfg Config, payload []byte) (Attempt, error) {
func MakeAttempt(ctx context.Context, httpClient *http.Client, schedule []time.Duration, id string, attemptNb int, cfg Config, payload []byte, isTest bool) (Attempt, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodPost, cfg.Endpoint, bytes.NewBuffer(payload))
if err != nil {
return Attempt{}, errors.Wrap(err, "http.NewRequestWithContext")
Expand All @@ -52,6 +52,7 @@ func MakeAttempt(ctx context.Context, httpClient *http.Client, schedule []time.D
req.Header.Set("formance-webhook-id", id)
req.Header.Set("formance-webhook-timestamp", fmt.Sprintf("%d", timestamp))
req.Header.Set("formance-webhook-signature", signature)
req.Header.Set("formance-webhook-test", fmt.Sprintf("%v", isTest))

resp, err := httpClient.Do(req)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (h *serverHandler) testOneConfigHandle(w http.ResponseWriter, r *http.Reque
}
sharedlogging.GetLogger(r.Context()).Infof("GET %s/%s%s", PathConfigs, id, PathTest)
attempt, err := webhooks.MakeAttempt(r.Context(), h.httpClient, nil,
uuid.NewString(), 0, cfgs[0], []byte(`{"data":"test"}`))
uuid.NewString(), 0, cfgs[0], []byte(`{"data":"test"}`), true)
if err != nil {
sharedlogging.GetLogger(r.Context()).Errorf("GET %s/%s%s: %s", PathConfigs, id, PathTest, err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
Expand Down
2 changes: 1 addition & 1 deletion pkg/worker/messages/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (w *WorkerMessages) processMessage(ctx context.Context, msgValue []byte) er
}

attempt, err := webhooks.MakeAttempt(ctx, w.httpClient, w.retriesSchedule,
uuid.NewString(), 0, cfg, data)
uuid.NewString(), 0, cfg, data, false)
if err != nil {
return errors.Wrap(err, "sending webhook")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/worker/retries/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (w *WorkerRetries) attemptRetries(ctx context.Context, errChan chan error)

newAttemptNb := atts[0].RetryAttempt + 1
attempt, err := webhooks.MakeAttempt(ctx, w.httpClient, w.retriesSchedule,
id, newAttemptNb, atts[0].Config, []byte(atts[0].Payload))
id, newAttemptNb, atts[0].Config, []byte(atts[0].Payload), false)
if err != nil {
errChan <- errors.Wrap(err, "webhooks.MakeAttempt")
continue
Expand Down
1 change: 1 addition & 0 deletions test/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func TestServer(t *testing.T) {
attempt, ok := decodeSingleResponse[webhooks.Attempt](t, resBody)
assert.Equal(t, true, ok)
assert.Equal(t, webhooks.StatusAttemptSuccess, attempt.Status)
assert.Equal(t, `{"data":"test"}`, attempt.Payload)

requestServer(t, http.MethodDelete, server.PathConfigs+"/"+c.ID, http.StatusOK)
})
Expand Down

0 comments on commit 96032f4

Please sign in to comment.