mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
Merge pull request #1241 from xucong053/bugfix-failed-to-assert
fix: failed to assert when int is compared with int64 #1232
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -198,6 +199,39 @@ func Interface2Float64(i interface{}) (float64, error) {
|
||||
return 0, errors.New("failed to convert interface to float64")
|
||||
}
|
||||
|
||||
func TypeNormalization(raw interface{}) interface{} {
|
||||
rawValue := reflect.ValueOf(raw)
|
||||
switch rawValue.Kind() {
|
||||
case reflect.Int:
|
||||
return rawValue.Int()
|
||||
case reflect.Int8:
|
||||
return rawValue.Int()
|
||||
case reflect.Int16:
|
||||
return rawValue.Int()
|
||||
case reflect.Int32:
|
||||
return rawValue.Int()
|
||||
case reflect.Float32:
|
||||
return rawValue.Float()
|
||||
case reflect.Uint:
|
||||
return rawValue.Uint()
|
||||
case reflect.Uint8:
|
||||
return rawValue.Uint()
|
||||
case reflect.Uint16:
|
||||
return rawValue.Uint()
|
||||
case reflect.Uint32:
|
||||
return rawValue.Uint()
|
||||
default:
|
||||
return raw
|
||||
}
|
||||
}
|
||||
|
||||
func InterfaceType(raw interface{}) string {
|
||||
if raw == nil {
|
||||
return ""
|
||||
}
|
||||
return reflect.TypeOf(raw).String()
|
||||
}
|
||||
|
||||
var ErrUnsupportedFileExt = fmt.Errorf("unsupported file extension")
|
||||
|
||||
// LoadFile loads file content with file extension and assigns to structObj
|
||||
|
||||
@@ -117,7 +117,7 @@ func (p *Parser) Parse(raw interface{}, variablesMapping map[string]interface{})
|
||||
return parsedMap, nil
|
||||
default:
|
||||
// other types, e.g. nil, int, float, bool
|
||||
return raw, nil
|
||||
return builtin.TypeNormalization(raw), nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -632,7 +632,7 @@ func TestParseVariables(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
map[string]interface{}{"varA": "$varB", "varB": "$varC", "varC": "123", "a": 1, "b": 2},
|
||||
map[string]interface{}{"varA": "123", "varB": "123", "varC": "123", "a": 1, "b": 2},
|
||||
map[string]interface{}{"varA": "123", "varB": "123", "varC": "123", "a": int64(1), "b": int64(2)},
|
||||
},
|
||||
{
|
||||
map[string]interface{}{"n": 34.5, "a": 12.3, "b": "$n", "varFoo2": "${max($a, $b)}"},
|
||||
|
||||
@@ -170,7 +170,9 @@ func (v *responseObject) Validate(iValidators []interface{}, variablesMapping ma
|
||||
Str("checkExpr", validator.Check).
|
||||
Str("assertMethod", assertMethod).
|
||||
Interface("expectValue", expectValue).
|
||||
Str("expectValueType", builtin.InterfaceType(expectValue)).
|
||||
Interface("checkValue", checkValue).
|
||||
Str("checkValueType", builtin.InterfaceType(checkValue)).
|
||||
Bool("result", result).
|
||||
Msgf("validate %s", checkItem)
|
||||
if !result {
|
||||
@@ -179,7 +181,9 @@ func (v *responseObject) Validate(iValidators []interface{}, variablesMapping ma
|
||||
Str("checkExpr", validator.Check).
|
||||
Str("assertMethod", assertMethod).
|
||||
Interface("checkValue", checkValue).
|
||||
Str("checkValueType", builtin.InterfaceType(checkValue)).
|
||||
Interface("expectValue", expectValue).
|
||||
Str("expectValueType", builtin.InterfaceType(expectValue)).
|
||||
Msg("assert failed")
|
||||
return errors.New("step validation failed")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user