Skip to content

Commit

Permalink
chore(backport release-1.2): fix: short term fix for deep copy failin…
Browse files Browse the repository at this point in the history
…g on http status code (#3467)

Co-authored-by: Kent Rancourt <kent.rancourt@gmail.com>
  • Loading branch information
akuitybot and krancour authored Feb 8, 2025
1 parent 001d342 commit c5f858c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion internal/directives/http_requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ func (h *httpRequester) buildExprEnv(resp *http.Response) (map[string]any, error
}
env := map[string]any{
"response": map[string]any{
"status": resp.StatusCode,
// TODO(krancour): Casting as an int64 is a short-term fix here because
// deep copy of the output map will panic if any value is an int. This is
// a near-term fix and a better solution will be PR'ed soon.
"status": int64(resp.StatusCode),
"header": resp.Header.Get,
"headers": resp.Header,
"body": map[string]any{},
Expand Down
10 changes: 5 additions & 5 deletions internal/directives/http_requester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func Test_httpRequester_runPromotionStep(t *testing.T) {
require.Equal(
t,
map[string]any{
"status": http.StatusOK,
"status": int64(http.StatusOK),
"theMeaningOfLife": nil,
},
res.Output,
Expand Down Expand Up @@ -284,7 +284,7 @@ func Test_httpRequester_runPromotionStep(t *testing.T) {
require.Equal(
t,
map[string]any{
"status": http.StatusOK,
"status": int64(http.StatusOK),
"theMeaningOfLife": nil,
},
res.Output,
Expand Down Expand Up @@ -317,7 +317,7 @@ func Test_httpRequester_runPromotionStep(t *testing.T) {
require.Equal(
t,
map[string]any{
"status": http.StatusOK,
"status": int64(http.StatusOK),
"theMeaningOfLife": float64(42),
},
res.Output,
Expand Down Expand Up @@ -465,9 +465,9 @@ func Test_httpRequester_buildExprEnv(t *testing.T) {
require.NoError(t, err)
statusAny, ok := env["response"].(map[string]any)["status"]
require.True(t, ok)
status, ok := statusAny.(int)
status, ok := statusAny.(int64)
require.True(t, ok)
require.Equal(t, http.StatusOK, status)
require.Equal(t, int64(http.StatusOK), status)
headerFnAny, ok := env["response"].(map[string]any)["header"]
require.True(t, ok)
headerFn, ok := headerFnAny.(func(string) string)
Expand Down

0 comments on commit c5f858c

Please # to comment.