mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +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"
|
||||
|
||||
var FunctionsMap = map[string]interface{}{
|
||||
var Functions = map[string]interface{}{
|
||||
"sleep": Sleep,
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
17
response.go
17
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)
|
||||
|
||||
Reference in New Issue
Block a user