mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-10 02:09:51 +08:00
refactor: group parser functions
This commit is contained in:
14
response.go
14
response.go
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/httprunner/hrp/internal/builtin"
|
||||
)
|
||||
|
||||
func newResponseObject(t *testing.T, pluginLoader *pluginLoader, resp *http.Response) (*responseObject, error) {
|
||||
func newResponseObject(t *testing.T, parser *parser, resp *http.Response) (*responseObject, error) {
|
||||
// prepare response headers
|
||||
headers := make(map[string]string)
|
||||
for k, v := range resp.Header {
|
||||
@@ -60,9 +60,9 @@ func newResponseObject(t *testing.T, pluginLoader *pluginLoader, resp *http.Resp
|
||||
}
|
||||
|
||||
return &responseObject{
|
||||
t: t,
|
||||
pluginLoader: pluginLoader,
|
||||
respObjMeta: data,
|
||||
t: t,
|
||||
parser: parser,
|
||||
respObjMeta: data,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ type respObjMeta struct {
|
||||
|
||||
type responseObject struct {
|
||||
t *testing.T
|
||||
pluginLoader *pluginLoader
|
||||
parser *parser
|
||||
respObjMeta interface{}
|
||||
validationResults map[string]interface{}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ func (v *responseObject) Validate(validators []Validator, variablesMapping map[s
|
||||
var checkValue interface{}
|
||||
if strings.Contains(checkItem, "$") {
|
||||
// reference variable
|
||||
checkValue, err = parseData(checkItem, variablesMapping, v.pluginLoader)
|
||||
checkValue, err = v.parser.parseData(checkItem, variablesMapping)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -116,7 +116,7 @@ func (v *responseObject) Validate(validators []Validator, variablesMapping map[s
|
||||
assertFunc := builtin.Assertions[assertMethod]
|
||||
|
||||
// parse expected value
|
||||
expectValue, err := parseData(validator.Expect, variablesMapping, v.pluginLoader)
|
||||
expectValue, err := v.parser.parseData(validator.Expect, variablesMapping)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user