mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-23 22:46:53 +00:00
[Backport release-1.5] Feat: add http status and code from http cmd run (#4528)
* Feat: add http status and code from http cmd run Signed-off-by: suxiang <704427617@qq.com> (cherry picked from commit0b96b2e60a) * Feat: fix unit test error Signed-off-by: suxiang <704427617@qq.com> (cherry picked from commit25f2291503) * Feat: status is not necessary Signed-off-by: suxiang <704427617@qq.com> (cherry picked from commitef3b8ac82b) * Feat: make reviewable Signed-off-by: suxiang <704427617@qq.com> (cherry picked from commit684f5e9ae2) * Feat: add unit test Signed-off-by: suxiang <704427617@qq.com> (cherry picked from commit6c39f602ea) * Feat: make reviewable Signed-off-by: suxiang <704427617@qq.com> (cherry picked from commit20ae7f2e15) Co-authored-by: suxiang <704427617@qq.com>
This commit is contained in:
co-authored by
suxiang
parent
37dd176dd3
commit
66dfcec0ad
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user