diff --git a/pkg/builtin/http/http.go b/pkg/builtin/http/http.go index 01f8c7b3d..bc60fceef 100644 --- a/pkg/builtin/http/http.go +++ b/pkg/builtin/http/http.go @@ -128,9 +128,10 @@ func (c *HTTPCmd) Run(meta *registry.Meta) (res interface{}, err error) { b, err := io.ReadAll(resp.Body) // parse response body and headers return map[string]interface{}{ - "body": string(b), - "header": resp.Header, - "trailer": resp.Trailer, + "body": string(b), + "header": resp.Header, + "trailer": resp.Trailer, + "statusCode": resp.StatusCode, }, err } diff --git a/pkg/workflow/providers/http/do_test.go b/pkg/workflow/providers/http/do_test.go index 0a0f6fa6f..6f42c51f4 100644 --- a/pkg/workflow/providers/http/do_test.go +++ b/pkg/workflow/providers/http/do_test.go @@ -57,17 +57,20 @@ func TestHttpDo(t *testing.T) { body: string header?: [string]: [...string] trailer?: [string]: [...string] + statusCode: number }) ` testCases := map[string]struct { request string expectedBody string + statusCode int64 }{ "hello": { request: baseTemplate + ` method: "GET" url: "http://127.0.0.1:1229/hello"`, expectedBody: `hello`, + statusCode: 200, }, "echo": { @@ -79,6 +82,7 @@ request:{ header: "Content-Type": "text/plain; charset=utf-8" }`, expectedBody: `I am vela`, + statusCode: 200, }, "json": { request: ` @@ -95,6 +99,7 @@ request:{ header: "Content-Type": "application/json; charset=utf-8" }` + baseTemplate, expectedBody: `{"name":"foo","score":100}`, + statusCode: 200, }, } @@ -109,6 +114,11 @@ request:{ ret, err := body.CueValue().String() assert.NilError(t, err, tName) assert.Equal(t, ret, tCase.expectedBody, tName) + statusCode, err := v.LookupValue("response", "statusCode") + assert.NilError(t, err, tName) + code, err := statusCode.CueValue().Int64() + assert.NilError(t, err, tName) + assert.Equal(t, code, tCase.statusCode, tName) } }