mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
change: move assertions to builtin
This commit is contained in:
15
builtin/assertion.go
Normal file
15
builtin/assertion.go
Normal file
@@ -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,
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ package builtin
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
var FunctionsMap = map[string]interface{}{
|
var Functions = map[string]interface{}{
|
||||||
"sleep": Sleep,
|
"sleep": Sleep,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ func mergeVariables(variables, overriddenVariables map[string]interface{}) map[s
|
|||||||
}
|
}
|
||||||
|
|
||||||
func callFunction(funcName string, params []interface{}) (interface{}, error) {
|
func callFunction(funcName string, params []interface{}) (interface{}, error) {
|
||||||
function, ok := builtin.FunctionsMap[funcName]
|
function, ok := builtin.Functions[funcName]
|
||||||
if !ok {
|
if !ok {
|
||||||
// function not found
|
// function not found
|
||||||
return nil, fmt.Errorf("function %s is not found", funcName)
|
return nil, fmt.Errorf("function %s is not found", funcName)
|
||||||
|
|||||||
17
response.go
17
response.go
@@ -8,20 +8,9 @@ import (
|
|||||||
|
|
||||||
"github.com/imroc/req"
|
"github.com/imroc/req"
|
||||||
"github.com/jmespath/go-jmespath"
|
"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{
|
"github.com/httprunner/httpboomer/builtin"
|
||||||
"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,
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewResponseObject(t *testing.T, resp *req.Resp) *ResponseObject {
|
func NewResponseObject(t *testing.T, resp *req.Resp) *ResponseObject {
|
||||||
// prepare response headers
|
// prepare response headers
|
||||||
@@ -111,7 +100,7 @@ func (v *ResponseObject) Validate(validators []TValidator, variablesMapping map[
|
|||||||
|
|
||||||
// get assert method
|
// get assert method
|
||||||
assertMethod := validator.Assert
|
assertMethod := validator.Assert
|
||||||
assertFunc := assertFunctionsMap[assertMethod]
|
assertFunc := builtin.Assertions[assertMethod]
|
||||||
|
|
||||||
// parse expected value
|
// parse expected value
|
||||||
expectValue := parseData(validator.Expect, variablesMapping)
|
expectValue := parseData(validator.Expect, variablesMapping)
|
||||||
|
|||||||
Reference in New Issue
Block a user