mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
change: sort map keys to keep validators in stable order
This commit is contained in:
@@ -80,6 +80,12 @@
|
||||
"expect": "application/json; charset=utf-8",
|
||||
"msg": "assert response header Content-Type"
|
||||
},
|
||||
{
|
||||
"check": "body.data",
|
||||
"assert": "equals",
|
||||
"expect": "This is expected to be sent back as part of response body.",
|
||||
"msg": "assert response body data"
|
||||
},
|
||||
{
|
||||
"check": "body.json",
|
||||
"assert": "equals",
|
||||
@@ -90,12 +96,6 @@
|
||||
"assert": "equals",
|
||||
"expect": "https://postman-echo.com/post",
|
||||
"msg": "assert response body url"
|
||||
},
|
||||
{
|
||||
"check": "body.data",
|
||||
"assert": "equals",
|
||||
"expect": "This is expected to be sent back as part of response body.",
|
||||
"msg": "assert response body data"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -133,17 +133,17 @@
|
||||
"expect": "application/json; charset=utf-8",
|
||||
"msg": "assert response header Content-Type"
|
||||
},
|
||||
{
|
||||
"check": "body.url",
|
||||
"assert": "equals",
|
||||
"expect": "https://postman-echo.com/post",
|
||||
"msg": "assert response body url"
|
||||
},
|
||||
{
|
||||
"check": "body.data",
|
||||
"assert": "equals",
|
||||
"expect": "",
|
||||
"msg": "assert response body data"
|
||||
},
|
||||
{
|
||||
"check": "body.url",
|
||||
"assert": "equals",
|
||||
"expect": "https://postman-echo.com/post",
|
||||
"msg": "assert response body url"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -181,12 +181,6 @@
|
||||
"expect": "application/json; charset=utf-8",
|
||||
"msg": "assert response header Content-Type"
|
||||
},
|
||||
{
|
||||
"check": "body.url",
|
||||
"assert": "equals",
|
||||
"expect": "https://postman-echo.com/put",
|
||||
"msg": "assert response body url"
|
||||
},
|
||||
{
|
||||
"check": "body.data",
|
||||
"assert": "equals",
|
||||
@@ -197,6 +191,12 @@
|
||||
"check": "body.json",
|
||||
"assert": "equals",
|
||||
"msg": "assert response body json"
|
||||
},
|
||||
{
|
||||
"check": "body.url",
|
||||
"assert": "equals",
|
||||
"expect": "https://postman-echo.com/put",
|
||||
"msg": "assert response body url"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -234,6 +234,12 @@
|
||||
"expect": "application/json; charset=utf-8",
|
||||
"msg": "assert response header Content-Type"
|
||||
},
|
||||
{
|
||||
"check": "body.data",
|
||||
"assert": "equals",
|
||||
"expect": "This is expected to be sent back as part of response body.",
|
||||
"msg": "assert response body data"
|
||||
},
|
||||
{
|
||||
"check": "body.json",
|
||||
"assert": "equals",
|
||||
@@ -244,12 +250,6 @@
|
||||
"assert": "equals",
|
||||
"expect": "https://postman-echo.com/patch",
|
||||
"msg": "assert response body url"
|
||||
},
|
||||
{
|
||||
"check": "body.data",
|
||||
"assert": "equals",
|
||||
"expect": "This is expected to be sent back as part of response body.",
|
||||
"msg": "assert response body data"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -375,17 +375,17 @@
|
||||
"expect": "application/json; charset=utf-8",
|
||||
"msg": "assert response header Content-Type"
|
||||
},
|
||||
{
|
||||
"check": "body.foo2",
|
||||
"assert": "equals",
|
||||
"expect": "bar2",
|
||||
"msg": "assert response body foo2"
|
||||
},
|
||||
{
|
||||
"check": "body.foo1",
|
||||
"assert": "equals",
|
||||
"expect": "bar1",
|
||||
"msg": "assert response body foo1"
|
||||
},
|
||||
{
|
||||
"check": "body.foo2",
|
||||
"assert": "equals",
|
||||
"expect": "bar2",
|
||||
"msg": "assert response body foo2"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -1327,18 +1327,6 @@
|
||||
"expect": "application/json; charset=utf-8",
|
||||
"msg": "assert response header Content-Type"
|
||||
},
|
||||
{
|
||||
"check": "body.years",
|
||||
"assert": "equals",
|
||||
"expect": 2016,
|
||||
"msg": "assert response body years"
|
||||
},
|
||||
{
|
||||
"check": "body.months",
|
||||
"assert": "equals",
|
||||
"expect": 9,
|
||||
"msg": "assert response body months"
|
||||
},
|
||||
{
|
||||
"check": "body.date",
|
||||
"assert": "equals",
|
||||
@@ -1351,12 +1339,24 @@
|
||||
"expect": 0,
|
||||
"msg": "assert response body hours"
|
||||
},
|
||||
{
|
||||
"check": "body.milliseconds",
|
||||
"assert": "equals",
|
||||
"expect": 0,
|
||||
"msg": "assert response body milliseconds"
|
||||
},
|
||||
{
|
||||
"check": "body.minutes",
|
||||
"assert": "equals",
|
||||
"expect": 0,
|
||||
"msg": "assert response body minutes"
|
||||
},
|
||||
{
|
||||
"check": "body.months",
|
||||
"assert": "equals",
|
||||
"expect": 9,
|
||||
"msg": "assert response body months"
|
||||
},
|
||||
{
|
||||
"check": "body.seconds",
|
||||
"assert": "equals",
|
||||
@@ -1364,10 +1364,10 @@
|
||||
"msg": "assert response body seconds"
|
||||
},
|
||||
{
|
||||
"check": "body.milliseconds",
|
||||
"check": "body.years",
|
||||
"assert": "equals",
|
||||
"expect": 0,
|
||||
"msg": "assert response body milliseconds"
|
||||
"expect": 2016,
|
||||
"msg": "assert response body years"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -57,6 +57,10 @@ teststeps:
|
||||
assert: equals
|
||||
expect: application/json; charset=utf-8
|
||||
msg: assert response header Content-Type
|
||||
- check: body.data
|
||||
assert: equals
|
||||
expect: This is expected to be sent back as part of response body.
|
||||
msg: assert response body data
|
||||
- check: body.json
|
||||
assert: equals
|
||||
msg: assert response body json
|
||||
@@ -64,10 +68,6 @@ teststeps:
|
||||
assert: equals
|
||||
expect: https://postman-echo.com/post
|
||||
msg: assert response body url
|
||||
- check: body.data
|
||||
assert: equals
|
||||
expect: This is expected to be sent back as part of response body.
|
||||
msg: assert response body data
|
||||
- name: ""
|
||||
request:
|
||||
method: POST
|
||||
@@ -94,14 +94,14 @@ teststeps:
|
||||
assert: equals
|
||||
expect: application/json; charset=utf-8
|
||||
msg: assert response header Content-Type
|
||||
- check: body.url
|
||||
assert: equals
|
||||
expect: https://postman-echo.com/post
|
||||
msg: assert response body url
|
||||
- check: body.data
|
||||
assert: equals
|
||||
expect: ""
|
||||
msg: assert response body data
|
||||
- check: body.url
|
||||
assert: equals
|
||||
expect: https://postman-echo.com/post
|
||||
msg: assert response body url
|
||||
- name: ""
|
||||
request:
|
||||
method: PUT
|
||||
@@ -128,10 +128,6 @@ teststeps:
|
||||
assert: equals
|
||||
expect: application/json; charset=utf-8
|
||||
msg: assert response header Content-Type
|
||||
- check: body.url
|
||||
assert: equals
|
||||
expect: https://postman-echo.com/put
|
||||
msg: assert response body url
|
||||
- check: body.data
|
||||
assert: equals
|
||||
expect: This is expected to be sent back as part of response body.
|
||||
@@ -139,6 +135,10 @@ teststeps:
|
||||
- check: body.json
|
||||
assert: equals
|
||||
msg: assert response body json
|
||||
- check: body.url
|
||||
assert: equals
|
||||
expect: https://postman-echo.com/put
|
||||
msg: assert response body url
|
||||
- name: ""
|
||||
request:
|
||||
method: PATCH
|
||||
@@ -165,6 +165,10 @@ teststeps:
|
||||
assert: equals
|
||||
expect: application/json; charset=utf-8
|
||||
msg: assert response header Content-Type
|
||||
- check: body.data
|
||||
assert: equals
|
||||
expect: This is expected to be sent back as part of response body.
|
||||
msg: assert response body data
|
||||
- check: body.json
|
||||
assert: equals
|
||||
msg: assert response body json
|
||||
@@ -172,10 +176,6 @@ teststeps:
|
||||
assert: equals
|
||||
expect: https://postman-echo.com/patch
|
||||
msg: assert response body url
|
||||
- check: body.data
|
||||
assert: equals
|
||||
expect: This is expected to be sent back as part of response body.
|
||||
msg: assert response body data
|
||||
- name: ""
|
||||
request:
|
||||
method: DELETE
|
||||
@@ -202,6 +202,10 @@ teststeps:
|
||||
assert: equals
|
||||
expect: application/json; charset=utf-8
|
||||
msg: assert response header Content-Type
|
||||
- check: body.data
|
||||
assert: equals
|
||||
expect: This is expected to be sent back as part of response body.
|
||||
msg: assert response body data
|
||||
- check: body.json
|
||||
assert: equals
|
||||
msg: assert response body json
|
||||
@@ -209,10 +213,6 @@ teststeps:
|
||||
assert: equals
|
||||
expect: https://postman-echo.com/delete
|
||||
msg: assert response body url
|
||||
- check: body.data
|
||||
assert: equals
|
||||
expect: This is expected to be sent back as part of response body.
|
||||
msg: assert response body data
|
||||
- name: ""
|
||||
request:
|
||||
method: GET
|
||||
@@ -666,14 +666,14 @@ teststeps:
|
||||
assert: equals
|
||||
expect: application/json; charset=utf-8
|
||||
msg: assert response header Content-Type
|
||||
- check: body.method
|
||||
assert: equals
|
||||
expect: GET
|
||||
msg: assert response body method
|
||||
- check: body.deflated
|
||||
assert: equals
|
||||
expect: true
|
||||
msg: assert response body deflated
|
||||
- check: body.method
|
||||
assert: equals
|
||||
expect: GET
|
||||
msg: assert response body method
|
||||
- name: ""
|
||||
request:
|
||||
method: GET
|
||||
@@ -928,34 +928,34 @@ teststeps:
|
||||
assert: equals
|
||||
expect: application/json; charset=utf-8
|
||||
msg: assert response header Content-Type
|
||||
- check: body.hours
|
||||
assert: equals
|
||||
expect: 0
|
||||
msg: assert response body hours
|
||||
- check: body.minutes
|
||||
assert: equals
|
||||
expect: 0
|
||||
msg: assert response body minutes
|
||||
- check: body.seconds
|
||||
assert: equals
|
||||
expect: 0
|
||||
msg: assert response body seconds
|
||||
- check: body.milliseconds
|
||||
assert: equals
|
||||
expect: 0
|
||||
msg: assert response body milliseconds
|
||||
- check: body.years
|
||||
assert: equals
|
||||
expect: 2016
|
||||
msg: assert response body years
|
||||
- check: body.months
|
||||
assert: equals
|
||||
expect: 9
|
||||
msg: assert response body months
|
||||
- check: body.date
|
||||
assert: equals
|
||||
expect: 10
|
||||
msg: assert response body date
|
||||
- check: body.hours
|
||||
assert: equals
|
||||
expect: 0
|
||||
msg: assert response body hours
|
||||
- check: body.milliseconds
|
||||
assert: equals
|
||||
expect: 0
|
||||
msg: assert response body milliseconds
|
||||
- check: body.minutes
|
||||
assert: equals
|
||||
expect: 0
|
||||
msg: assert response body minutes
|
||||
- check: body.months
|
||||
assert: equals
|
||||
expect: 9
|
||||
msg: assert response body months
|
||||
- check: body.seconds
|
||||
assert: equals
|
||||
expect: 0
|
||||
msg: assert response body seconds
|
||||
- check: body.years
|
||||
assert: equals
|
||||
expect: 2016
|
||||
msg: assert response body years
|
||||
- name: ""
|
||||
request:
|
||||
method: GET
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -273,12 +274,20 @@ func (s *TStep) makeValidate(entry *Entry) error {
|
||||
if err = json.Unmarshal(data, &body); err != nil {
|
||||
return errors.Wrap(err, "json.Unmarshal body error")
|
||||
}
|
||||
if _, ok := body.(map[string]interface{}); !ok {
|
||||
jsonBody, ok := body.(map[string]interface{})
|
||||
if !ok {
|
||||
return fmt.Errorf("response body is not json, not matched with MimeType")
|
||||
}
|
||||
|
||||
// response body is json
|
||||
for key, value := range body.(map[string]interface{}) {
|
||||
keys := make([]string, 0, len(jsonBody))
|
||||
for k := range jsonBody {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
// sort map keys to keep validators in stable order
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
value := jsonBody[key]
|
||||
switch v := value.(type) {
|
||||
case map[string]interface{}:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user