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