-
Notifications
You must be signed in to change notification settings - Fork 0
fix(transform): return an error on non-2xx in send_http_post #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Steven Patterson (stevepatterson5)
merged 4 commits into
main
from
fix-send-http-post-silent-4xx-drop
Jul 27, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
78f7c8e
fix(transform): return an error on non-2xx in send_http_post
stevepatterson5 b965b30
chore: point CODEOWNERS at @LiveRamp/seceng
stevepatterson5 e63013d
fix(transform): omit interpolated URL from send_http_post errors
stevepatterson5 2a7602e
fix: add cyclop to the pubSubHandler nolint directive
stevepatterson5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| * @brexhq/substation | ||
| * @LiveRamp/seceng |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package transform | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/brexhq/substation/v2/config" | ||
| "github.com/brexhq/substation/v2/message" | ||
| ) | ||
|
|
||
| var _ Transformer = &sendHTTPPost{} | ||
|
|
||
| // Statuses that the HTTP client does not retry are returned with a nil error, | ||
| // so the transform must inspect the status code itself. Retried statuses (429 | ||
| // and 5xx) are deliberately excluded here because exercising them would incur | ||
| // the client's full backoff and exceed the test timeout. | ||
| var sendHTTPPostTests = []struct { | ||
| name string | ||
| statusCode int | ||
| body string | ||
| expectErr bool | ||
| }{ | ||
| {"200 succeeds", http.StatusOK, "", false}, | ||
| {"201 succeeds", http.StatusCreated, "", false}, | ||
| {"400 errors", http.StatusBadRequest, "invalid JSON at offset 12", true}, | ||
| {"401 errors", http.StatusUnauthorized, "invalid ingest token", true}, | ||
| {"404 errors", http.StatusNotFound, "no such endpoint", true}, | ||
| } | ||
|
|
||
| func TestSendHTTPPost(t *testing.T) { | ||
| ctx := context.TODO() | ||
|
|
||
| for _, test := range sendHTTPPostTests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| serv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
| w.WriteHeader(test.statusCode) | ||
| //nolint:errcheck // Test server write. | ||
| w.Write([]byte(test.body)) | ||
| })) | ||
| defer serv.Close() | ||
|
|
||
| tf, err := newSendHTTPPost(ctx, config.Config{ | ||
| Settings: map[string]interface{}{"url": serv.URL}, | ||
| }) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| if _, err := tf.Transform(ctx, message.New().SetData([]byte(`{"a":1}`))); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| // The batch is sent when the control message is received. | ||
| _, err = tf.Transform(ctx, message.New().AsControl()) | ||
|
|
||
| if !test.expectErr { | ||
| if err != nil { | ||
| t.Errorf("expected no error, got %v", err) | ||
| } | ||
|
|
||
| return | ||
| } | ||
|
|
||
| if err == nil { | ||
| t.Fatalf("expected an error for status %d, got nil", test.statusCode) | ||
| } | ||
|
|
||
| if !strings.Contains(err.Error(), test.body) { | ||
| t.Errorf("expected error to contain response body %q, got %q", test.body, err) | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.