diff --git a/assertions/helper.go b/assertions/helper.go index f0688a3d..7fdad649 100644 --- a/assertions/helper.go +++ b/assertions/helper.go @@ -1,6 +1,7 @@ package assertions import ( + "encoding/json" "fmt" "reflect" ) @@ -49,8 +50,39 @@ func isNil(i interface{}) bool { } func areSameTypes(i, j interface{}) bool { + var err error + i, j, err = handleJSONNumber(i, j) + if err != nil { + return false + } return reflect.DeepEqual( reflect.Zero(reflect.TypeOf(i)).Interface(), reflect.Zero(reflect.TypeOf(j)).Interface(), ) } + +func handleJSONNumber(actual interface{}, expected interface{}) (interface{}, interface{}, error) { + jsNumber, is := actual.(json.Number) + if !is { + return actual, expected, nil + } + + switch expected.(type) { + case string: + return jsNumber.String(), expected, nil + case int64: + i, err := jsNumber.Int64() + if err != nil { + return actual, expected, err + } + return i, expected, nil + case float64: + f, err := jsNumber.Float64() + if err != nil { + return actual, expected, err + } + return f, expected, nil + } + + return jsNumber, expected, nil +} diff --git a/tests/assertions/ShouldBeLessThan.yml b/tests/assertions/ShouldBeLessThan.yml index 5ff06241..0afbc481 100644 --- a/tests/assertions/ShouldBeLessThan.yml +++ b/tests/assertions/ShouldBeLessThan.yml @@ -4,4 +4,14 @@ testcases: steps: - script: echo 2.4 assertions: - - result.systemout ShouldBeLessThan 2.5 \ No newline at end of file + - result.systemout ShouldBeLessThan 2.5 + +- name: bodyjson assert comparator test + steps: + - type: http + method: GET + url: https://eu.api.ovh.com/1.0/sms/rates/destinations?billingCountry=fr&country=fr + headers: + Content-type: application/json + assertions: + - result.bodyjson.credit ShouldBeLessThan 2 \ No newline at end of file