-
Notifications
You must be signed in to change notification settings - Fork 11
feat: adds http put support to cel expressions #53
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -728,3 +728,127 @@ func Test_impl_post_request_with_400_bad_request(t *testing.T) { | |||||
| assert.Equal(t, body["code"], "INVALID_DATA") | ||||||
| assert.Equal(t, body["statusCode"], http.StatusBadRequest) | ||||||
| } | ||||||
|
|
||||||
| func Test_impl_put_request(t *testing.T) { | ||||||
| base, err := compiler.NewBaseEnv() | ||||||
| assert.NoError(t, err) | ||||||
| assert.NotNil(t, base) | ||||||
|
|
||||||
| ctx := Context{&contextImpl{ | ||||||
| client: testClient{ | ||||||
| doFunc: func(req *http.Request) (*http.Response, error) { | ||||||
| assert.Equal(t, req.URL.String(), "http://localhost:8080") | ||||||
| assert.Equal(t, req.Method, "PUT") | ||||||
|
|
||||||
| var data any | ||||||
| err := json.NewDecoder(req.Body).Decode(&data) | ||||||
| assert.NoError(t, err) | ||||||
| assert.Equal(t, data.(map[string]any)["key"], "value") | ||||||
| assert.Equal(t, data.(map[string]any)["foo"], float64(2)) | ||||||
|
|
||||||
| return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(strings.NewReader(`{"body": "updated"}`))}, nil | ||||||
| }, | ||||||
| }, | ||||||
| }} | ||||||
|
|
||||||
| env, err := base.Extend( | ||||||
| Lib(&ctx, version.MajorMinor(1, 18)), | ||||||
| ) | ||||||
| assert.NoError(t, err) | ||||||
| assert.NotNil(t, env) | ||||||
| ast, issues := env.Compile(`http.Put("http://localhost:8080", { "key": dyn("value"), "foo": dyn(2) })`) | ||||||
|
||||||
| ast, issues := env.Compile(`http.Put("http://localhost:8080", { "key": dyn("value"), "foo": dyn(2) })`) | |
| ast, issues := env.Compile(`http.put("http://localhost:8080", { "key": dyn("value"), "foo": dyn(2) })`) |
Copilot
AI
Apr 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test also only covers the PascalCase overload (http.Put). To keep consistency with the rest of the suite and verify the version-gated camelCase overload, add a corresponding compile/eval test for http.put.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ var ContextType = types.NewOpaqueType("http.Context") | |
| type ContextInterface interface { | ||
| Get(url string, headers map[string]string) (any, error) | ||
| Post(url string, data any, headers map[string]string) (any, error) | ||
| Put(url string, data any, headers map[string]string) (any, error) | ||
| Client(caBundle string) (ContextInterface, error) | ||
|
Comment on lines
9
to
13
|
||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put() now uses buildRequestData(), but buildRequestData’s internal error text still says "failed to encode HTTP POST data ...". If encoding fails on a PUT request, the returned error chain will misleadingly mention POST; consider making buildRequestData’s error message method-agnostic (or pass the HTTP method into it).