mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-17 03:57:36 +08:00
fix #1331: use str_eq to assert string and digit equality
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
# Release History
|
||||
|
||||
## v4.1.2 (2022-06-03)
|
||||
|
||||
- fix #1331: use `str_eq` to assert string and digit equality
|
||||
|
||||
## v4.1.1 (2022-05-31)
|
||||
|
||||
- fix: failed to build debugtalk.go without go.mod
|
||||
- fix: avoid to escape from html special characters like '&' in converted JSON testcase
|
||||
- fix: display the full step name when referencing testcase in html report
|
||||
|
||||
@@ -45,6 +45,7 @@ var Assertions = map[string]func(t assert.TestingT, actual interface{}, expected
|
||||
"contained_by": ContainedBy,
|
||||
"str_eq": StringEqual,
|
||||
"string_equals": StringEqual,
|
||||
"equal_fold": EqualFold,
|
||||
"regex_match": RegexMatch,
|
||||
}
|
||||
|
||||
@@ -157,6 +158,12 @@ func ContainedBy(t assert.TestingT, actual, expected interface{}, msgAndArgs ...
|
||||
}
|
||||
|
||||
func StringEqual(t assert.TestingT, actual, expected interface{}, msgAndArgs ...interface{}) bool {
|
||||
a := fmt.Sprintf("%v", actual)
|
||||
e := fmt.Sprintf("%v", expected)
|
||||
return assert.True(t, a == e, msgAndArgs)
|
||||
}
|
||||
|
||||
func EqualFold(t assert.TestingT, actual, expected interface{}, msgAndArgs ...interface{}) bool {
|
||||
if !assert.IsType(t, "string", actual, msgAndArgs) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -158,6 +158,27 @@ func TestContainedBy(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStringEqual(t *testing.T) {
|
||||
testData := []struct {
|
||||
raw interface{}
|
||||
expected interface{}
|
||||
}{
|
||||
{"abcd", "abcd"},
|
||||
{"0", 0},
|
||||
{"123", 123},
|
||||
// {"123.0", 123.0}, // FIXME
|
||||
{"12.3", 12.3},
|
||||
{"-12.3", -12.3},
|
||||
{"-123", -123},
|
||||
}
|
||||
|
||||
for _, data := range testData {
|
||||
if !assert.True(t, StringEqual(t, data.raw, data.expected)) {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqualFold(t *testing.T) {
|
||||
testData := []struct {
|
||||
raw interface{}
|
||||
expected interface{}
|
||||
@@ -168,7 +189,7 @@ func TestStringEqual(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, data := range testData {
|
||||
if !assert.True(t, StringEqual(t, data.raw, data.expected)) {
|
||||
if !assert.True(t, EqualFold(t, data.raw, data.expected)) {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1065,6 +1065,17 @@ func (s *StepRequestValidation) AssertStringEqual(jmesPath string, expected inte
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *StepRequestValidation) AssertEqualFold(jmesPath string, expected interface{}, msg string) *StepRequestValidation {
|
||||
v := Validator{
|
||||
Check: jmesPath,
|
||||
Assert: "equal_fold",
|
||||
Expect: expected,
|
||||
Message: msg,
|
||||
}
|
||||
s.step.Validators = append(s.step.Validators, v)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *StepRequestValidation) AssertLengthLessOrEquals(jmesPath string, expected interface{}, msg string) *StepRequestValidation {
|
||||
v := Validator{
|
||||
Check: jmesPath,
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestCaseCallFunction(t *testing.T) {
|
||||
AssertLengthEqual("body.args.foo1", 5, "check args foo1").
|
||||
AssertEqual("body.args.foo2", "12.3", "check args foo2").
|
||||
AssertTypeMatch("body.args.foo3", "str", "check args foo3 is type string").
|
||||
AssertStringEqual("body.args.foo3", "foo3", "check args foo3 case-insensitivity").
|
||||
AssertEqualFold("body.args.foo3", "foo3", "check args foo3 case-insensitivity").
|
||||
AssertContains("body.args.foo3", "Foo", "check contains ").
|
||||
AssertContainedBy("body.args.foo3", "this is Foo3 test", "check contained by"), // notice: request params value will be converted to string
|
||||
hrp.NewStep("post json data with functions").
|
||||
|
||||
Reference in New Issue
Block a user