diff --git a/builtin/assertion.go b/builtin/assertion.go new file mode 100644 index 00000000..6634207f --- /dev/null +++ b/builtin/assertion.go @@ -0,0 +1,15 @@ +package builtin + +import "github.com/stretchr/testify/assert" + +var Assertions = map[string]func(t assert.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool{ + "equals": assert.EqualValues, + "equal": assert.EqualValues, // alias for equals + "greater_than": assert.Greater, + "less_than": assert.Less, + "greater_or_equals": assert.GreaterOrEqual, + "less_or_equals": assert.LessOrEqual, + "not_equal": assert.NotEqual, + "contains": assert.Contains, + "regex_match": assert.Regexp, +} diff --git a/builtin/function.go b/builtin/function.go index 8ea6792d..e240fa16 100644 --- a/builtin/function.go +++ b/builtin/function.go @@ -2,7 +2,7 @@ package builtin import "time" -var FunctionsMap = map[string]interface{}{ +var Functions = map[string]interface{}{ "sleep": Sleep, } diff --git a/parser.go b/parser.go index 7b8ee46d..b9023a9c 100644 --- a/parser.go +++ b/parser.go @@ -170,7 +170,7 @@ func mergeVariables(variables, overriddenVariables map[string]interface{}) map[s } func callFunction(funcName string, params []interface{}) (interface{}, error) { - function, ok := builtin.FunctionsMap[funcName] + function, ok := builtin.Functions[funcName] if !ok { // function not found return nil, fmt.Errorf("function %s is not found", funcName) diff --git a/response.go b/response.go index 816246ad..60c01b6b 100644 --- a/response.go +++ b/response.go @@ -8,20 +8,9 @@ import ( "github.com/imroc/req" "github.com/jmespath/go-jmespath" - "github.com/stretchr/testify/assert" -) -var assertFunctionsMap = map[string]func(t assert.TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool{ - "equals": assert.EqualValues, - "equal": assert.EqualValues, // alias for equals - "greater_than": assert.Greater, - "less_than": assert.Less, - "greater_or_equals": assert.GreaterOrEqual, - "less_or_equals": assert.LessOrEqual, - "not_equal": assert.NotEqual, - "contains": assert.Contains, - "regex_match": assert.Regexp, -} + "github.com/httprunner/httpboomer/builtin" +) func NewResponseObject(t *testing.T, resp *req.Resp) *ResponseObject { // prepare response headers @@ -111,7 +100,7 @@ func (v *ResponseObject) Validate(validators []TValidator, variablesMapping map[ // get assert method assertMethod := validator.Assert - assertFunc := assertFunctionsMap[assertMethod] + assertFunc := builtin.Assertions[assertMethod] // parse expected value expectValue := parseData(validator.Expect, variablesMapping)