From 7b2d5f601f5cd09bb8907dc00ffcb505bb89e617 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Mon, 19 Aug 2019 15:35:03 -0700 Subject: [PATCH] vendor: update testify to v1.4.0 --- vendor/github.com/stretchr/testify/LICENSE | 35 +- .../testify/assert/assertion_format.go | 86 ++- .../testify/assert/assertion_forward.go | 172 ++++- .../testify/assert/assertion_order.go | 309 ++++++++ .../stretchr/testify/assert/assertions.go | 164 ++++- .../testify/assert/http_assertions.go | 4 +- .../github.com/stretchr/testify/mock/mock.go | 36 +- .../stretchr/testify/require/require.go | 664 +++++++++++++----- .../stretchr/testify/require/require.go.tmpl | 5 +- .../testify/require/require_forward.go | 172 ++++- .../stretchr/testify/require/requirements.go | 2 +- vendor/vendor.json | 9 +- 12 files changed, 1400 insertions(+), 258 deletions(-) create mode 100644 vendor/github.com/stretchr/testify/assert/assertion_order.go diff --git a/vendor/github.com/stretchr/testify/LICENSE b/vendor/github.com/stretchr/testify/LICENSE index 473b670a7..f38ec5956 100644 --- a/vendor/github.com/stretchr/testify/LICENSE +++ b/vendor/github.com/stretchr/testify/LICENSE @@ -1,22 +1,21 @@ -Copyright (c) 2012 - 2013 Mat Ryer and Tyler Bunnell +MIT License -Please consider promoting this project if you find it useful. +Copyright (c) 2012-2018 Mat Ryer and Tyler Bunnell -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of the Software, -and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT -OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE -OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/stretchr/testify/assert/assertion_format.go b/vendor/github.com/stretchr/testify/assert/assertion_format.go index 677e19b20..e0364e9e7 100644 --- a/vendor/github.com/stretchr/testify/assert/assertion_format.go +++ b/vendor/github.com/stretchr/testify/assert/assertion_format.go @@ -113,6 +113,17 @@ func Errorf(t TestingT, err error, msg string, args ...interface{}) bool { return Error(t, err, append([]interface{}{msg}, args...)...) } +// Eventuallyf asserts that given condition will be met in waitFor time, +// periodically checking target function each tick. +// +// assert.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") +func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + return Eventually(t, condition, waitFor, tick, append([]interface{}{msg}, args...)...) +} + // Exactlyf asserts that two objects are equal in value and type. // // assert.Exactlyf(t, int32(123, "error message %s", "formatted"), int64(123)) @@ -157,10 +168,35 @@ func FileExistsf(t TestingT, path string, msg string, args ...interface{}) bool return FileExists(t, path, append([]interface{}{msg}, args...)...) } +// Greaterf asserts that the first element is greater than the second +// +// assert.Greaterf(t, 2, 1, "error message %s", "formatted") +// assert.Greaterf(t, float64(2, "error message %s", "formatted"), float64(1)) +// assert.Greaterf(t, "b", "a", "error message %s", "formatted") +func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + return Greater(t, e1, e2, append([]interface{}{msg}, args...)...) +} + +// GreaterOrEqualf asserts that the first element is greater than or equal to the second +// +// assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted") +// assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted") +// assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted") +// assert.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted") +func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + return GreaterOrEqual(t, e1, e2, append([]interface{}{msg}, args...)...) +} + // HTTPBodyContainsf asserts that a specified handler returns a // body that contains a string. // -// assert.HTTPBodyContainsf(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") +// assert.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool { @@ -173,7 +209,7 @@ func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url // HTTPBodyNotContainsf asserts that a specified handler returns a // body that does not contain a string. // -// assert.HTTPBodyNotContainsf(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") +// assert.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool { @@ -289,6 +325,14 @@ func JSONEqf(t TestingT, expected string, actual string, msg string, args ...int return JSONEq(t, expected, actual, append([]interface{}{msg}, args...)...) } +// YAMLEqf asserts that two YAML strings are equivalent. +func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + return YAMLEq(t, expected, actual, append([]interface{}{msg}, args...)...) +} + // Lenf asserts that the specified object has specific length. // Lenf also fails if the object has a type that len() not accept. // @@ -300,6 +344,31 @@ func Lenf(t TestingT, object interface{}, length int, msg string, args ...interf return Len(t, object, length, append([]interface{}{msg}, args...)...) } +// Lessf asserts that the first element is less than the second +// +// assert.Lessf(t, 1, 2, "error message %s", "formatted") +// assert.Lessf(t, float64(1, "error message %s", "formatted"), float64(2)) +// assert.Lessf(t, "a", "b", "error message %s", "formatted") +func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + return Less(t, e1, e2, append([]interface{}{msg}, args...)...) +} + +// LessOrEqualf asserts that the first element is less than or equal to the second +// +// assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted") +// assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted") +// assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted") +// assert.LessOrEqualf(t, "b", "b", "error message %s", "formatted") +func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + return LessOrEqual(t, e1, e2, append([]interface{}{msg}, args...)...) +} + // Nilf asserts that the specified object is nil. // // assert.Nilf(t, err, "error message %s", "formatted") @@ -444,6 +513,19 @@ func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...in return Regexp(t, rx, str, append([]interface{}{msg}, args...)...) } +// Samef asserts that two pointers reference the same object. +// +// assert.Samef(t, ptr1, ptr2, "error message %s", "formatted") +// +// Both arguments must be pointer variables. Pointer variable sameness is +// determined based on the equality of both type and value. +func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + return Same(t, expected, actual, append([]interface{}{msg}, args...)...) +} + // Subsetf asserts that the specified list(array, slice...) contains all // elements given in the specified subset(array, slice...). // diff --git a/vendor/github.com/stretchr/testify/assert/assertion_forward.go b/vendor/github.com/stretchr/testify/assert/assertion_forward.go index 8adb11194..26830403a 100644 --- a/vendor/github.com/stretchr/testify/assert/assertion_forward.go +++ b/vendor/github.com/stretchr/testify/assert/assertion_forward.go @@ -215,6 +215,28 @@ func (a *Assertions) Errorf(err error, msg string, args ...interface{}) bool { return Errorf(a.t, err, msg, args...) } +// Eventually asserts that given condition will be met in waitFor time, +// periodically checking target function each tick. +// +// a.Eventually(func() bool { return true; }, time.Second, 10*time.Millisecond) +func (a *Assertions) Eventually(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return Eventually(a.t, condition, waitFor, tick, msgAndArgs...) +} + +// Eventuallyf asserts that given condition will be met in waitFor time, +// periodically checking target function each tick. +// +// a.Eventuallyf(func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") +func (a *Assertions) Eventuallyf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return Eventuallyf(a.t, condition, waitFor, tick, msg, args...) +} + // Exactly asserts that two objects are equal in value and type. // // a.Exactly(int32(123), int64(123)) @@ -303,10 +325,60 @@ func (a *Assertions) FileExistsf(path string, msg string, args ...interface{}) b return FileExistsf(a.t, path, msg, args...) } +// Greater asserts that the first element is greater than the second +// +// a.Greater(2, 1) +// a.Greater(float64(2), float64(1)) +// a.Greater("b", "a") +func (a *Assertions) Greater(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return Greater(a.t, e1, e2, msgAndArgs...) +} + +// GreaterOrEqual asserts that the first element is greater than or equal to the second +// +// a.GreaterOrEqual(2, 1) +// a.GreaterOrEqual(2, 2) +// a.GreaterOrEqual("b", "a") +// a.GreaterOrEqual("b", "b") +func (a *Assertions) GreaterOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return GreaterOrEqual(a.t, e1, e2, msgAndArgs...) +} + +// GreaterOrEqualf asserts that the first element is greater than or equal to the second +// +// a.GreaterOrEqualf(2, 1, "error message %s", "formatted") +// a.GreaterOrEqualf(2, 2, "error message %s", "formatted") +// a.GreaterOrEqualf("b", "a", "error message %s", "formatted") +// a.GreaterOrEqualf("b", "b", "error message %s", "formatted") +func (a *Assertions) GreaterOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return GreaterOrEqualf(a.t, e1, e2, msg, args...) +} + +// Greaterf asserts that the first element is greater than the second +// +// a.Greaterf(2, 1, "error message %s", "formatted") +// a.Greaterf(float64(2, "error message %s", "formatted"), float64(1)) +// a.Greaterf("b", "a", "error message %s", "formatted") +func (a *Assertions) Greaterf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return Greaterf(a.t, e1, e2, msg, args...) +} + // HTTPBodyContains asserts that a specified handler returns a // body that contains a string. // -// a.HTTPBodyContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// a.HTTPBodyContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") // // Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool { @@ -319,7 +391,7 @@ func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, u // HTTPBodyContainsf asserts that a specified handler returns a // body that contains a string. // -// a.HTTPBodyContainsf(myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") +// a.HTTPBodyContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool { @@ -332,7 +404,7 @@ func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, // HTTPBodyNotContains asserts that a specified handler returns a // body that does not contain a string. // -// a.HTTPBodyNotContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// a.HTTPBodyNotContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") // // Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool { @@ -345,7 +417,7 @@ func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string // HTTPBodyNotContainsf asserts that a specified handler returns a // body that does not contain a string. // -// a.HTTPBodyNotContainsf(myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") +// a.HTTPBodyNotContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool { @@ -567,6 +639,22 @@ func (a *Assertions) JSONEqf(expected string, actual string, msg string, args .. return JSONEqf(a.t, expected, actual, msg, args...) } +// YAMLEq asserts that two YAML strings are equivalent. +func (a *Assertions) YAMLEq(expected string, actual string, msgAndArgs ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return YAMLEq(a.t, expected, actual, msgAndArgs...) +} + +// YAMLEqf asserts that two YAML strings are equivalent. +func (a *Assertions) YAMLEqf(expected string, actual string, msg string, args ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return YAMLEqf(a.t, expected, actual, msg, args...) +} + // Len asserts that the specified object has specific length. // Len also fails if the object has a type that len() not accept. // @@ -589,6 +677,56 @@ func (a *Assertions) Lenf(object interface{}, length int, msg string, args ...in return Lenf(a.t, object, length, msg, args...) } +// Less asserts that the first element is less than the second +// +// a.Less(1, 2) +// a.Less(float64(1), float64(2)) +// a.Less("a", "b") +func (a *Assertions) Less(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return Less(a.t, e1, e2, msgAndArgs...) +} + +// LessOrEqual asserts that the first element is less than or equal to the second +// +// a.LessOrEqual(1, 2) +// a.LessOrEqual(2, 2) +// a.LessOrEqual("a", "b") +// a.LessOrEqual("b", "b") +func (a *Assertions) LessOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return LessOrEqual(a.t, e1, e2, msgAndArgs...) +} + +// LessOrEqualf asserts that the first element is less than or equal to the second +// +// a.LessOrEqualf(1, 2, "error message %s", "formatted") +// a.LessOrEqualf(2, 2, "error message %s", "formatted") +// a.LessOrEqualf("a", "b", "error message %s", "formatted") +// a.LessOrEqualf("b", "b", "error message %s", "formatted") +func (a *Assertions) LessOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return LessOrEqualf(a.t, e1, e2, msg, args...) +} + +// Lessf asserts that the first element is less than the second +// +// a.Lessf(1, 2, "error message %s", "formatted") +// a.Lessf(float64(1, "error message %s", "formatted"), float64(2)) +// a.Lessf("a", "b", "error message %s", "formatted") +func (a *Assertions) Lessf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return Lessf(a.t, e1, e2, msg, args...) +} + // Nil asserts that the specified object is nil. // // a.Nil(err) @@ -877,6 +1015,32 @@ func (a *Assertions) Regexpf(rx interface{}, str interface{}, msg string, args . return Regexpf(a.t, rx, str, msg, args...) } +// Same asserts that two pointers reference the same object. +// +// a.Same(ptr1, ptr2) +// +// Both arguments must be pointer variables. Pointer variable sameness is +// determined based on the equality of both type and value. +func (a *Assertions) Same(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return Same(a.t, expected, actual, msgAndArgs...) +} + +// Samef asserts that two pointers reference the same object. +// +// a.Samef(ptr1, ptr2, "error message %s", "formatted") +// +// Both arguments must be pointer variables. Pointer variable sameness is +// determined based on the equality of both type and value. +func (a *Assertions) Samef(expected interface{}, actual interface{}, msg string, args ...interface{}) bool { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + return Samef(a.t, expected, actual, msg, args...) +} + // Subset asserts that the specified list(array, slice...) contains all // elements given in the specified subset(array, slice...). // diff --git a/vendor/github.com/stretchr/testify/assert/assertion_order.go b/vendor/github.com/stretchr/testify/assert/assertion_order.go new file mode 100644 index 000000000..15a486ca6 --- /dev/null +++ b/vendor/github.com/stretchr/testify/assert/assertion_order.go @@ -0,0 +1,309 @@ +package assert + +import ( + "fmt" + "reflect" +) + +func compare(obj1, obj2 interface{}, kind reflect.Kind) (int, bool) { + switch kind { + case reflect.Int: + { + intobj1 := obj1.(int) + intobj2 := obj2.(int) + if intobj1 > intobj2 { + return -1, true + } + if intobj1 == intobj2 { + return 0, true + } + if intobj1 < intobj2 { + return 1, true + } + } + case reflect.Int8: + { + int8obj1 := obj1.(int8) + int8obj2 := obj2.(int8) + if int8obj1 > int8obj2 { + return -1, true + } + if int8obj1 == int8obj2 { + return 0, true + } + if int8obj1 < int8obj2 { + return 1, true + } + } + case reflect.Int16: + { + int16obj1 := obj1.(int16) + int16obj2 := obj2.(int16) + if int16obj1 > int16obj2 { + return -1, true + } + if int16obj1 == int16obj2 { + return 0, true + } + if int16obj1 < int16obj2 { + return 1, true + } + } + case reflect.Int32: + { + int32obj1 := obj1.(int32) + int32obj2 := obj2.(int32) + if int32obj1 > int32obj2 { + return -1, true + } + if int32obj1 == int32obj2 { + return 0, true + } + if int32obj1 < int32obj2 { + return 1, true + } + } + case reflect.Int64: + { + int64obj1 := obj1.(int64) + int64obj2 := obj2.(int64) + if int64obj1 > int64obj2 { + return -1, true + } + if int64obj1 == int64obj2 { + return 0, true + } + if int64obj1 < int64obj2 { + return 1, true + } + } + case reflect.Uint: + { + uintobj1 := obj1.(uint) + uintobj2 := obj2.(uint) + if uintobj1 > uintobj2 { + return -1, true + } + if uintobj1 == uintobj2 { + return 0, true + } + if uintobj1 < uintobj2 { + return 1, true + } + } + case reflect.Uint8: + { + uint8obj1 := obj1.(uint8) + uint8obj2 := obj2.(uint8) + if uint8obj1 > uint8obj2 { + return -1, true + } + if uint8obj1 == uint8obj2 { + return 0, true + } + if uint8obj1 < uint8obj2 { + return 1, true + } + } + case reflect.Uint16: + { + uint16obj1 := obj1.(uint16) + uint16obj2 := obj2.(uint16) + if uint16obj1 > uint16obj2 { + return -1, true + } + if uint16obj1 == uint16obj2 { + return 0, true + } + if uint16obj1 < uint16obj2 { + return 1, true + } + } + case reflect.Uint32: + { + uint32obj1 := obj1.(uint32) + uint32obj2 := obj2.(uint32) + if uint32obj1 > uint32obj2 { + return -1, true + } + if uint32obj1 == uint32obj2 { + return 0, true + } + if uint32obj1 < uint32obj2 { + return 1, true + } + } + case reflect.Uint64: + { + uint64obj1 := obj1.(uint64) + uint64obj2 := obj2.(uint64) + if uint64obj1 > uint64obj2 { + return -1, true + } + if uint64obj1 == uint64obj2 { + return 0, true + } + if uint64obj1 < uint64obj2 { + return 1, true + } + } + case reflect.Float32: + { + float32obj1 := obj1.(float32) + float32obj2 := obj2.(float32) + if float32obj1 > float32obj2 { + return -1, true + } + if float32obj1 == float32obj2 { + return 0, true + } + if float32obj1 < float32obj2 { + return 1, true + } + } + case reflect.Float64: + { + float64obj1 := obj1.(float64) + float64obj2 := obj2.(float64) + if float64obj1 > float64obj2 { + return -1, true + } + if float64obj1 == float64obj2 { + return 0, true + } + if float64obj1 < float64obj2 { + return 1, true + } + } + case reflect.String: + { + stringobj1 := obj1.(string) + stringobj2 := obj2.(string) + if stringobj1 > stringobj2 { + return -1, true + } + if stringobj1 == stringobj2 { + return 0, true + } + if stringobj1 < stringobj2 { + return 1, true + } + } + } + + return 0, false +} + +// Greater asserts that the first element is greater than the second +// +// assert.Greater(t, 2, 1) +// assert.Greater(t, float64(2), float64(1)) +// assert.Greater(t, "b", "a") +func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + + e1Kind := reflect.ValueOf(e1).Kind() + e2Kind := reflect.ValueOf(e2).Kind() + if e1Kind != e2Kind { + return Fail(t, "Elements should be the same type", msgAndArgs...) + } + + res, isComparable := compare(e1, e2, e1Kind) + if !isComparable { + return Fail(t, fmt.Sprintf("Can not compare type \"%s\"", reflect.TypeOf(e1)), msgAndArgs...) + } + + if res != -1 { + return Fail(t, fmt.Sprintf("\"%v\" is not greater than \"%v\"", e1, e2), msgAndArgs...) + } + + return true +} + +// GreaterOrEqual asserts that the first element is greater than or equal to the second +// +// assert.GreaterOrEqual(t, 2, 1) +// assert.GreaterOrEqual(t, 2, 2) +// assert.GreaterOrEqual(t, "b", "a") +// assert.GreaterOrEqual(t, "b", "b") +func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + + e1Kind := reflect.ValueOf(e1).Kind() + e2Kind := reflect.ValueOf(e2).Kind() + if e1Kind != e2Kind { + return Fail(t, "Elements should be the same type", msgAndArgs...) + } + + res, isComparable := compare(e1, e2, e1Kind) + if !isComparable { + return Fail(t, fmt.Sprintf("Can not compare type \"%s\"", reflect.TypeOf(e1)), msgAndArgs...) + } + + if res != -1 && res != 0 { + return Fail(t, fmt.Sprintf("\"%v\" is not greater than or equal to \"%v\"", e1, e2), msgAndArgs...) + } + + return true +} + +// Less asserts that the first element is less than the second +// +// assert.Less(t, 1, 2) +// assert.Less(t, float64(1), float64(2)) +// assert.Less(t, "a", "b") +func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + + e1Kind := reflect.ValueOf(e1).Kind() + e2Kind := reflect.ValueOf(e2).Kind() + if e1Kind != e2Kind { + return Fail(t, "Elements should be the same type", msgAndArgs...) + } + + res, isComparable := compare(e1, e2, e1Kind) + if !isComparable { + return Fail(t, fmt.Sprintf("Can not compare type \"%s\"", reflect.TypeOf(e1)), msgAndArgs...) + } + + if res != 1 { + return Fail(t, fmt.Sprintf("\"%v\" is not less than \"%v\"", e1, e2), msgAndArgs...) + } + + return true +} + +// LessOrEqual asserts that the first element is less than or equal to the second +// +// assert.LessOrEqual(t, 1, 2) +// assert.LessOrEqual(t, 2, 2) +// assert.LessOrEqual(t, "a", "b") +// assert.LessOrEqual(t, "b", "b") +func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + + e1Kind := reflect.ValueOf(e1).Kind() + e2Kind := reflect.ValueOf(e2).Kind() + if e1Kind != e2Kind { + return Fail(t, "Elements should be the same type", msgAndArgs...) + } + + res, isComparable := compare(e1, e2, e1Kind) + if !isComparable { + return Fail(t, fmt.Sprintf("Can not compare type \"%s\"", reflect.TypeOf(e1)), msgAndArgs...) + } + + if res != 1 && res != 0 { + return Fail(t, fmt.Sprintf("\"%v\" is not less than or equal to \"%v\"", e1, e2), msgAndArgs...) + } + + return true +} diff --git a/vendor/github.com/stretchr/testify/assert/assertions.go b/vendor/github.com/stretchr/testify/assert/assertions.go index 94781ea33..044da8b01 100644 --- a/vendor/github.com/stretchr/testify/assert/assertions.go +++ b/vendor/github.com/stretchr/testify/assert/assertions.go @@ -18,6 +18,7 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/pmezard/go-difflib/difflib" + yaml "gopkg.in/yaml.v2" ) //go:generate go run ../_codegen/main.go -output-package=assert -template=assertion_format.go.tmpl @@ -39,7 +40,7 @@ type ValueAssertionFunc func(TestingT, interface{}, ...interface{}) bool // for table driven tests. type BoolAssertionFunc func(TestingT, bool, ...interface{}) bool -// ValuesAssertionFunc is a common function prototype when validating an error value. Can be useful +// ErrorAssertionFunc is a common function prototype when validating an error value. Can be useful // for table driven tests. type ErrorAssertionFunc func(TestingT, error, ...interface{}) bool @@ -54,21 +55,23 @@ type Comparison func() (success bool) // // This function does no assertion of any kind. func ObjectsAreEqual(expected, actual interface{}) bool { - if expected == nil || actual == nil { return expected == actual } - if exp, ok := expected.([]byte); ok { - act, ok := actual.([]byte) - if !ok { - return false - } else if exp == nil || act == nil { - return exp == nil && act == nil - } - return bytes.Equal(exp, act) - } - return reflect.DeepEqual(expected, actual) + exp, ok := expected.([]byte) + if !ok { + return reflect.DeepEqual(expected, actual) + } + + act, ok := actual.([]byte) + if !ok { + return false + } + if exp == nil || act == nil { + return exp == nil && act == nil + } + return bytes.Equal(exp, act) } // ObjectsAreEqualValues gets whether two objects are equal, or if their @@ -177,7 +180,11 @@ func messageFromMsgAndArgs(msgAndArgs ...interface{}) string { return "" } if len(msgAndArgs) == 1 { - return msgAndArgs[0].(string) + msg := msgAndArgs[0] + if msgAsStr, ok := msg.(string); ok { + return msgAsStr + } + return fmt.Sprintf("%+v", msg) } if len(msgAndArgs) > 1 { return fmt.Sprintf(msgAndArgs[0].(string), msgAndArgs[1:]...) @@ -344,6 +351,37 @@ func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) } +// Same asserts that two pointers reference the same object. +// +// assert.Same(t, ptr1, ptr2) +// +// Both arguments must be pointer variables. Pointer variable sameness is +// determined based on the equality of both type and value. +func Same(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + + expectedPtr, actualPtr := reflect.ValueOf(expected), reflect.ValueOf(actual) + if expectedPtr.Kind() != reflect.Ptr || actualPtr.Kind() != reflect.Ptr { + return Fail(t, "Invalid operation: both arguments must be pointers", msgAndArgs...) + } + + expectedType, actualType := reflect.TypeOf(expected), reflect.TypeOf(actual) + if expectedType != actualType { + return Fail(t, fmt.Sprintf("Pointer expected to be of type %v, but was %v", + expectedType, actualType), msgAndArgs...) + } + + if expected != actual { + return Fail(t, fmt.Sprintf("Not same: \n"+ + "expected: %p %#v\n"+ + "actual : %p %#v", expected, expected, actual, actual), msgAndArgs...) + } + + return true +} + // formatUnequalValues takes two values of arbitrary types and returns string // representations appropriate to be presented to the user. // @@ -413,6 +451,17 @@ func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { return Fail(t, "Expected value not to be nil.", msgAndArgs...) } +// containsKind checks if a specified kind in the slice of kinds. +func containsKind(kinds []reflect.Kind, kind reflect.Kind) bool { + for i := 0; i < len(kinds); i++ { + if kind == kinds[i] { + return true + } + } + + return false +} + // isNil checks if a specified object is nil or not, without Failing. func isNil(object interface{}) bool { if object == nil { @@ -421,7 +470,14 @@ func isNil(object interface{}) bool { value := reflect.ValueOf(object) kind := value.Kind() - if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() { + isNilableKind := containsKind( + []reflect.Kind{ + reflect.Chan, reflect.Func, + reflect.Interface, reflect.Map, + reflect.Ptr, reflect.Slice}, + kind) + + if isNilableKind && value.IsNil() { return true } @@ -455,14 +511,14 @@ func isEmpty(object interface{}) bool { // collection types are empty when they have no element case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice: return objValue.Len() == 0 - // pointers are empty if nil or if the value they point to is empty + // pointers are empty if nil or if the value they point to is empty case reflect.Ptr: if objValue.IsNil() { return true } deref := objValue.Elem().Interface() return isEmpty(deref) - // for all other types, compare against the zero value + // for all other types, compare against the zero value default: zero := reflect.Zero(objValue.Type()) return reflect.DeepEqual(object, zero.Interface()) @@ -605,7 +661,7 @@ func NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{ func includeElement(list interface{}, element interface{}) (ok, found bool) { listValue := reflect.ValueOf(list) - elementValue := reflect.ValueOf(element) + listKind := reflect.TypeOf(list).Kind() defer func() { if e := recover(); e != nil { ok = false @@ -613,11 +669,12 @@ func includeElement(list interface{}, element interface{}) (ok, found bool) { } }() - if reflect.TypeOf(list).Kind() == reflect.String { + if listKind == reflect.String { + elementValue := reflect.ValueOf(element) return true, strings.Contains(listValue.String(), elementValue.String()) } - if reflect.TypeOf(list).Kind() == reflect.Map { + if listKind == reflect.Map { mapKeys := listValue.MapKeys() for i := 0; i < len(mapKeys); i++ { if ObjectsAreEqual(mapKeys[i].Interface(), element) { @@ -874,7 +931,7 @@ func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool { } if funcDidPanic, panicValue := didPanic(f); !funcDidPanic { - return Fail(t, fmt.Sprintf("func %#v should panic\n\tPanic value:\t%v", f, panicValue), msgAndArgs...) + return Fail(t, fmt.Sprintf("func %#v should panic\n\tPanic value:\t%#v", f, panicValue), msgAndArgs...) } return true @@ -891,10 +948,10 @@ func PanicsWithValue(t TestingT, expected interface{}, f PanicTestFunc, msgAndAr funcDidPanic, panicValue := didPanic(f) if !funcDidPanic { - return Fail(t, fmt.Sprintf("func %#v should panic\n\tPanic value:\t%v", f, panicValue), msgAndArgs...) + return Fail(t, fmt.Sprintf("func %#v should panic\n\tPanic value:\t%#v", f, panicValue), msgAndArgs...) } if panicValue != expected { - return Fail(t, fmt.Sprintf("func %#v should panic with value:\t%v\n\tPanic value:\t%v", f, expected, panicValue), msgAndArgs...) + return Fail(t, fmt.Sprintf("func %#v should panic with value:\t%#v\n\tPanic value:\t%#v", f, expected, panicValue), msgAndArgs...) } return true @@ -1313,6 +1370,24 @@ func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{ return Equal(t, expectedJSONAsInterface, actualJSONAsInterface, msgAndArgs...) } +// YAMLEq asserts that two YAML strings are equivalent. +func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + var expectedYAMLAsInterface, actualYAMLAsInterface interface{} + + if err := yaml.Unmarshal([]byte(expected), &expectedYAMLAsInterface); err != nil { + return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid yaml.\nYAML parsing error: '%s'", expected, err.Error()), msgAndArgs...) + } + + if err := yaml.Unmarshal([]byte(actual), &actualYAMLAsInterface); err != nil { + return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid yaml.\nYAML error: '%s'", actual, err.Error()), msgAndArgs...) + } + + return Equal(t, expectedYAMLAsInterface, actualYAMLAsInterface, msgAndArgs...) +} + func typeAndKind(v interface{}) (reflect.Type, reflect.Kind) { t := reflect.TypeOf(v) k := t.Kind() @@ -1325,7 +1400,7 @@ func typeAndKind(v interface{}) (reflect.Type, reflect.Kind) { } // diff returns a diff of both values as long as both are of the same type and -// are a struct, map, slice or array. Otherwise it returns an empty string. +// are a struct, map, slice, array or string. Otherwise it returns an empty string. func diff(expected interface{}, actual interface{}) string { if expected == nil || actual == nil { return "" @@ -1338,12 +1413,18 @@ func diff(expected interface{}, actual interface{}) string { return "" } - if ek != reflect.Struct && ek != reflect.Map && ek != reflect.Slice && ek != reflect.Array { + if ek != reflect.Struct && ek != reflect.Map && ek != reflect.Slice && ek != reflect.Array && ek != reflect.String { return "" } - e := spewConfig.Sdump(expected) - a := spewConfig.Sdump(actual) + var e, a string + if et != reflect.TypeOf("") { + e = spewConfig.Sdump(expected) + a = spewConfig.Sdump(actual) + } else { + e = reflect.ValueOf(expected).String() + a = reflect.ValueOf(actual).String() + } diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{ A: difflib.SplitLines(e), @@ -1384,3 +1465,34 @@ var spewConfig = spew.ConfigState{ type tHelper interface { Helper() } + +// Eventually asserts that given condition will be met in waitFor time, +// periodically checking target function each tick. +// +// assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond) +func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool { + if h, ok := t.(tHelper); ok { + h.Helper() + } + + timer := time.NewTimer(waitFor) + ticker := time.NewTicker(tick) + checkPassed := make(chan bool) + defer timer.Stop() + defer ticker.Stop() + defer close(checkPassed) + for { + select { + case <-timer.C: + return Fail(t, "Condition never satisfied", msgAndArgs...) + case result := <-checkPassed: + if result { + return true + } + case <-ticker.C: + go func() { + checkPassed <- condition() + }() + } + } +} diff --git a/vendor/github.com/stretchr/testify/assert/http_assertions.go b/vendor/github.com/stretchr/testify/assert/http_assertions.go index a87c2e1da..df46fa777 100644 --- a/vendor/github.com/stretchr/testify/assert/http_assertions.go +++ b/vendor/github.com/stretchr/testify/assert/http_assertions.go @@ -105,7 +105,7 @@ func HTTPBody(handler http.HandlerFunc, method, url string, values url.Values) s // HTTPBodyContains asserts that a specified handler returns a // body that contains a string. // -// assert.HTTPBodyContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// assert.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") // // Returns whether the assertion was successful (true) or not (false). func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool { @@ -125,7 +125,7 @@ func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method, url string, // HTTPBodyNotContains asserts that a specified handler returns a // body that does not contain a string. // -// assert.HTTPBodyNotContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// assert.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") // // Returns whether the assertion was successful (true) or not (false). func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool { diff --git a/vendor/github.com/stretchr/testify/mock/mock.go b/vendor/github.com/stretchr/testify/mock/mock.go index 4dde47d89..b5288af5b 100644 --- a/vendor/github.com/stretchr/testify/mock/mock.go +++ b/vendor/github.com/stretchr/testify/mock/mock.go @@ -176,6 +176,7 @@ func (c *Call) Maybe() *Call { // Mock. // On("MyMethod", 1).Return(nil). // On("MyOtherMethod", 'a', 'b', 'c').Return(errors.New("Some Error")) +//go:noinline func (c *Call) On(methodName string, arguments ...interface{}) *Call { return c.Parent.On(methodName, arguments...) } @@ -261,17 +262,21 @@ func (m *Mock) On(methodName string, arguments ...interface{}) *Call { // */ func (m *Mock) findExpectedCall(method string, arguments ...interface{}) (int, *Call) { - for i, call := range m.ExpectedCalls { - if call.Method == method && call.Repeatability > -1 { + var expectedCall *Call + for i, call := range m.ExpectedCalls { + if call.Method == method { _, diffCount := call.Arguments.Diff(arguments) if diffCount == 0 { - return i, call + expectedCall = call + if call.Repeatability > -1 { + return i, call + } } - } } - return -1, nil + + return -1, expectedCall } func (m *Mock) findClosestCall(method string, arguments ...interface{}) (*Call, string) { @@ -343,13 +348,17 @@ func (m *Mock) MethodCalled(methodName string, arguments ...interface{}) Argumen found, call := m.findExpectedCall(methodName, arguments...) if found < 0 { + // expected call found but it has already been called with repeatable times + if call != nil { + m.mutex.Unlock() + m.fail("\nassert: mock: The method has been called over %d times.\n\tEither do one more Mock.On(\"%s\").Return(...), or remove extra call.\n\tThis call was unexpected:\n\t\t%s\n\tat: %s", call.totalCalls, methodName, callString(methodName, arguments, true), assert.CallerInfo()) + } // we have to fail here - because we don't know what to do // as the return arguments. This is because: // // a) this is a totally unexpected call to this method, // b) the arguments are not what was expected, or // c) the developer has forgotten to add an accompanying On...Return pair. - closestCall, mismatch := m.findClosestCall(methodName, arguments...) m.mutex.Unlock() @@ -668,25 +677,30 @@ func (args Arguments) Diff(objects []interface{}) (string, int) { for i := 0; i < maxArgCount; i++ { var actual, expected interface{} + var actualFmt, expectedFmt string if len(objects) <= i { actual = "(Missing)" + actualFmt = "(Missing)" } else { actual = objects[i] + actualFmt = fmt.Sprintf("(%[1]T=%[1]v)", actual) } if len(args) <= i { expected = "(Missing)" + expectedFmt = "(Missing)" } else { expected = args[i] + expectedFmt = fmt.Sprintf("(%[1]T=%[1]v)", expected) } if matcher, ok := expected.(argumentMatcher); ok { if matcher.Matches(actual) { - output = fmt.Sprintf("%s\t%d: PASS: %s matched by %s\n", output, i, actual, matcher) + output = fmt.Sprintf("%s\t%d: PASS: %s matched by %s\n", output, i, actualFmt, matcher) } else { differences++ - output = fmt.Sprintf("%s\t%d: PASS: %s not matched by %s\n", output, i, actual, matcher) + output = fmt.Sprintf("%s\t%d: FAIL: %s not matched by %s\n", output, i, actualFmt, matcher) } } else if reflect.TypeOf(expected) == reflect.TypeOf((*AnythingOfTypeArgument)(nil)).Elem() { @@ -694,7 +708,7 @@ func (args Arguments) Diff(objects []interface{}) (string, int) { if reflect.TypeOf(actual).Name() != string(expected.(AnythingOfTypeArgument)) && reflect.TypeOf(actual).String() != string(expected.(AnythingOfTypeArgument)) { // not match differences++ - output = fmt.Sprintf("%s\t%d: FAIL: type %s != type %s - %s\n", output, i, expected, reflect.TypeOf(actual).Name(), actual) + output = fmt.Sprintf("%s\t%d: FAIL: type %s != type %s - %s\n", output, i, expected, reflect.TypeOf(actual).Name(), actualFmt) } } else { @@ -703,11 +717,11 @@ func (args Arguments) Diff(objects []interface{}) (string, int) { if assert.ObjectsAreEqual(expected, Anything) || assert.ObjectsAreEqual(actual, Anything) || assert.ObjectsAreEqual(actual, expected) { // match - output = fmt.Sprintf("%s\t%d: PASS: %s == %s\n", output, i, actual, expected) + output = fmt.Sprintf("%s\t%d: PASS: %s == %s\n", output, i, actualFmt, expectedFmt) } else { // not match differences++ - output = fmt.Sprintf("%s\t%d: FAIL: %s != %s\n", output, i, actual, expected) + output = fmt.Sprintf("%s\t%d: FAIL: %s != %s\n", output, i, actualFmt, expectedFmt) } } diff --git a/vendor/github.com/stretchr/testify/require/require.go b/vendor/github.com/stretchr/testify/require/require.go index 2110ea89c..c5903f5db 100644 --- a/vendor/github.com/stretchr/testify/require/require.go +++ b/vendor/github.com/stretchr/testify/require/require.go @@ -17,9 +17,10 @@ func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Condition(t, comp, msgAndArgs...) { - t.FailNow() + if assert.Condition(t, comp, msgAndArgs...) { + return } + t.FailNow() } // Conditionf uses a Comparison to assert a complex condition. @@ -27,9 +28,10 @@ func Conditionf(t TestingT, comp assert.Comparison, msg string, args ...interfac if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Conditionf(t, comp, msg, args...) { - t.FailNow() + if assert.Conditionf(t, comp, msg, args...) { + return } + t.FailNow() } // Contains asserts that the specified string, list(array, slice...) or map contains the @@ -42,9 +44,10 @@ func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...int if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Contains(t, s, contains, msgAndArgs...) { - t.FailNow() + if assert.Contains(t, s, contains, msgAndArgs...) { + return } + t.FailNow() } // Containsf asserts that the specified string, list(array, slice...) or map contains the @@ -57,9 +60,10 @@ func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Containsf(t, s, contains, msg, args...) { - t.FailNow() + if assert.Containsf(t, s, contains, msg, args...) { + return } + t.FailNow() } // DirExists checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists. @@ -67,9 +71,10 @@ func DirExists(t TestingT, path string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.DirExists(t, path, msgAndArgs...) { - t.FailNow() + if assert.DirExists(t, path, msgAndArgs...) { + return } + t.FailNow() } // DirExistsf checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists. @@ -77,9 +82,10 @@ func DirExistsf(t TestingT, path string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.DirExistsf(t, path, msg, args...) { - t.FailNow() + if assert.DirExistsf(t, path, msg, args...) { + return } + t.FailNow() } // ElementsMatch asserts that the specified listA(array, slice...) is equal to specified @@ -91,9 +97,10 @@ func ElementsMatch(t TestingT, listA interface{}, listB interface{}, msgAndArgs if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.ElementsMatch(t, listA, listB, msgAndArgs...) { - t.FailNow() + if assert.ElementsMatch(t, listA, listB, msgAndArgs...) { + return } + t.FailNow() } // ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified @@ -105,9 +112,10 @@ func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.ElementsMatchf(t, listA, listB, msg, args...) { - t.FailNow() + if assert.ElementsMatchf(t, listA, listB, msg, args...) { + return } + t.FailNow() } // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either @@ -118,9 +126,10 @@ func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Empty(t, object, msgAndArgs...) { - t.FailNow() + if assert.Empty(t, object, msgAndArgs...) { + return } + t.FailNow() } // Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either @@ -131,9 +140,10 @@ func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Emptyf(t, object, msg, args...) { - t.FailNow() + if assert.Emptyf(t, object, msg, args...) { + return } + t.FailNow() } // Equal asserts that two objects are equal. @@ -147,9 +157,10 @@ func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...i if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Equal(t, expected, actual, msgAndArgs...) { - t.FailNow() + if assert.Equal(t, expected, actual, msgAndArgs...) { + return } + t.FailNow() } // EqualError asserts that a function returned an error (i.e. not `nil`) @@ -161,9 +172,10 @@ func EqualError(t TestingT, theError error, errString string, msgAndArgs ...inte if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.EqualError(t, theError, errString, msgAndArgs...) { - t.FailNow() + if assert.EqualError(t, theError, errString, msgAndArgs...) { + return } + t.FailNow() } // EqualErrorf asserts that a function returned an error (i.e. not `nil`) @@ -175,9 +187,10 @@ func EqualErrorf(t TestingT, theError error, errString string, msg string, args if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.EqualErrorf(t, theError, errString, msg, args...) { - t.FailNow() + if assert.EqualErrorf(t, theError, errString, msg, args...) { + return } + t.FailNow() } // EqualValues asserts that two objects are equal or convertable to the same types @@ -188,9 +201,10 @@ func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArg if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.EqualValues(t, expected, actual, msgAndArgs...) { - t.FailNow() + if assert.EqualValues(t, expected, actual, msgAndArgs...) { + return } + t.FailNow() } // EqualValuesf asserts that two objects are equal or convertable to the same types @@ -201,9 +215,10 @@ func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg stri if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.EqualValuesf(t, expected, actual, msg, args...) { - t.FailNow() + if assert.EqualValuesf(t, expected, actual, msg, args...) { + return } + t.FailNow() } // Equalf asserts that two objects are equal. @@ -217,9 +232,10 @@ func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, ar if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Equalf(t, expected, actual, msg, args...) { - t.FailNow() + if assert.Equalf(t, expected, actual, msg, args...) { + return } + t.FailNow() } // Error asserts that a function returned an error (i.e. not `nil`). @@ -232,9 +248,10 @@ func Error(t TestingT, err error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Error(t, err, msgAndArgs...) { - t.FailNow() + if assert.Error(t, err, msgAndArgs...) { + return } + t.FailNow() } // Errorf asserts that a function returned an error (i.e. not `nil`). @@ -247,9 +264,38 @@ func Errorf(t TestingT, err error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Errorf(t, err, msg, args...) { - t.FailNow() + if assert.Errorf(t, err, msg, args...) { + return } + t.FailNow() +} + +// Eventually asserts that given condition will be met in waitFor time, +// periodically checking target function each tick. +// +// assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond) +func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { + if assert.Eventually(t, condition, waitFor, tick, msgAndArgs...) { + return + } + if h, ok := t.(tHelper); ok { + h.Helper() + } + t.FailNow() +} + +// Eventuallyf asserts that given condition will be met in waitFor time, +// periodically checking target function each tick. +// +// assert.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") +func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { + if assert.Eventuallyf(t, condition, waitFor, tick, msg, args...) { + return + } + if h, ok := t.(tHelper); ok { + h.Helper() + } + t.FailNow() } // Exactly asserts that two objects are equal in value and type. @@ -259,9 +305,10 @@ func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs .. if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Exactly(t, expected, actual, msgAndArgs...) { - t.FailNow() + if assert.Exactly(t, expected, actual, msgAndArgs...) { + return } + t.FailNow() } // Exactlyf asserts that two objects are equal in value and type. @@ -271,9 +318,10 @@ func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Exactlyf(t, expected, actual, msg, args...) { - t.FailNow() + if assert.Exactlyf(t, expected, actual, msg, args...) { + return } + t.FailNow() } // Fail reports a failure through @@ -281,9 +329,10 @@ func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Fail(t, failureMessage, msgAndArgs...) { - t.FailNow() + if assert.Fail(t, failureMessage, msgAndArgs...) { + return } + t.FailNow() } // FailNow fails test @@ -291,9 +340,10 @@ func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.FailNow(t, failureMessage, msgAndArgs...) { - t.FailNow() + if assert.FailNow(t, failureMessage, msgAndArgs...) { + return } + t.FailNow() } // FailNowf fails test @@ -301,9 +351,10 @@ func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{} if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.FailNowf(t, failureMessage, msg, args...) { - t.FailNow() + if assert.FailNowf(t, failureMessage, msg, args...) { + return } + t.FailNow() } // Failf reports a failure through @@ -311,9 +362,10 @@ func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Failf(t, failureMessage, msg, args...) { - t.FailNow() + if assert.Failf(t, failureMessage, msg, args...) { + return } + t.FailNow() } // False asserts that the specified value is false. @@ -323,9 +375,10 @@ func False(t TestingT, value bool, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.False(t, value, msgAndArgs...) { - t.FailNow() + if assert.False(t, value, msgAndArgs...) { + return } + t.FailNow() } // Falsef asserts that the specified value is false. @@ -335,9 +388,10 @@ func Falsef(t TestingT, value bool, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Falsef(t, value, msg, args...) { - t.FailNow() + if assert.Falsef(t, value, msg, args...) { + return } + t.FailNow() } // FileExists checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file. @@ -345,9 +399,10 @@ func FileExists(t TestingT, path string, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.FileExists(t, path, msgAndArgs...) { - t.FailNow() + if assert.FileExists(t, path, msgAndArgs...) { + return } + t.FailNow() } // FileExistsf checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file. @@ -355,69 +410,136 @@ func FileExistsf(t TestingT, path string, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.FileExistsf(t, path, msg, args...) { - t.FailNow() + if assert.FileExistsf(t, path, msg, args...) { + return } + t.FailNow() +} + +// Greater asserts that the first element is greater than the second +// +// assert.Greater(t, 2, 1) +// assert.Greater(t, float64(2), float64(1)) +// assert.Greater(t, "b", "a") +func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.Greater(t, e1, e2, msgAndArgs...) { + return + } + t.FailNow() +} + +// GreaterOrEqual asserts that the first element is greater than or equal to the second +// +// assert.GreaterOrEqual(t, 2, 1) +// assert.GreaterOrEqual(t, 2, 2) +// assert.GreaterOrEqual(t, "b", "a") +// assert.GreaterOrEqual(t, "b", "b") +func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.GreaterOrEqual(t, e1, e2, msgAndArgs...) { + return + } + t.FailNow() +} + +// GreaterOrEqualf asserts that the first element is greater than or equal to the second +// +// assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted") +// assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted") +// assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted") +// assert.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted") +func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.GreaterOrEqualf(t, e1, e2, msg, args...) { + return + } + t.FailNow() +} + +// Greaterf asserts that the first element is greater than the second +// +// assert.Greaterf(t, 2, 1, "error message %s", "formatted") +// assert.Greaterf(t, float64(2, "error message %s", "formatted"), float64(1)) +// assert.Greaterf(t, "b", "a", "error message %s", "formatted") +func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.Greaterf(t, e1, e2, msg, args...) { + return + } + t.FailNow() } // HTTPBodyContains asserts that a specified handler returns a // body that contains a string. // -// assert.HTTPBodyContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// assert.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") // // Returns whether the assertion was successful (true) or not (false). func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.HTTPBodyContains(t, handler, method, url, values, str, msgAndArgs...) { - t.FailNow() + if assert.HTTPBodyContains(t, handler, method, url, values, str, msgAndArgs...) { + return } + t.FailNow() } // HTTPBodyContainsf asserts that a specified handler returns a // body that contains a string. // -// assert.HTTPBodyContainsf(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") +// assert.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.HTTPBodyContainsf(t, handler, method, url, values, str, msg, args...) { - t.FailNow() + if assert.HTTPBodyContainsf(t, handler, method, url, values, str, msg, args...) { + return } + t.FailNow() } // HTTPBodyNotContains asserts that a specified handler returns a // body that does not contain a string. // -// assert.HTTPBodyNotContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// assert.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") // // Returns whether the assertion was successful (true) or not (false). func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.HTTPBodyNotContains(t, handler, method, url, values, str, msgAndArgs...) { - t.FailNow() + if assert.HTTPBodyNotContains(t, handler, method, url, values, str, msgAndArgs...) { + return } + t.FailNow() } // HTTPBodyNotContainsf asserts that a specified handler returns a // body that does not contain a string. // -// assert.HTTPBodyNotContainsf(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") +// assert.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.HTTPBodyNotContainsf(t, handler, method, url, values, str, msg, args...) { - t.FailNow() + if assert.HTTPBodyNotContainsf(t, handler, method, url, values, str, msg, args...) { + return } + t.FailNow() } // HTTPError asserts that a specified handler returns an error status code. @@ -429,9 +551,10 @@ func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.HTTPError(t, handler, method, url, values, msgAndArgs...) { - t.FailNow() + if assert.HTTPError(t, handler, method, url, values, msgAndArgs...) { + return } + t.FailNow() } // HTTPErrorf asserts that a specified handler returns an error status code. @@ -443,9 +566,10 @@ func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.HTTPErrorf(t, handler, method, url, values, msg, args...) { - t.FailNow() + if assert.HTTPErrorf(t, handler, method, url, values, msg, args...) { + return } + t.FailNow() } // HTTPRedirect asserts that a specified handler returns a redirect status code. @@ -457,9 +581,10 @@ func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url strin if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.HTTPRedirect(t, handler, method, url, values, msgAndArgs...) { - t.FailNow() + if assert.HTTPRedirect(t, handler, method, url, values, msgAndArgs...) { + return } + t.FailNow() } // HTTPRedirectf asserts that a specified handler returns a redirect status code. @@ -471,9 +596,10 @@ func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url stri if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.HTTPRedirectf(t, handler, method, url, values, msg, args...) { - t.FailNow() + if assert.HTTPRedirectf(t, handler, method, url, values, msg, args...) { + return } + t.FailNow() } // HTTPSuccess asserts that a specified handler returns a success status code. @@ -485,9 +611,10 @@ func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.HTTPSuccess(t, handler, method, url, values, msgAndArgs...) { - t.FailNow() + if assert.HTTPSuccess(t, handler, method, url, values, msgAndArgs...) { + return } + t.FailNow() } // HTTPSuccessf asserts that a specified handler returns a success status code. @@ -499,9 +626,10 @@ func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url strin if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.HTTPSuccessf(t, handler, method, url, values, msg, args...) { - t.FailNow() + if assert.HTTPSuccessf(t, handler, method, url, values, msg, args...) { + return } + t.FailNow() } // Implements asserts that an object is implemented by the specified interface. @@ -511,9 +639,10 @@ func Implements(t TestingT, interfaceObject interface{}, object interface{}, msg if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Implements(t, interfaceObject, object, msgAndArgs...) { - t.FailNow() + if assert.Implements(t, interfaceObject, object, msgAndArgs...) { + return } + t.FailNow() } // Implementsf asserts that an object is implemented by the specified interface. @@ -523,9 +652,10 @@ func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, ms if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Implementsf(t, interfaceObject, object, msg, args...) { - t.FailNow() + if assert.Implementsf(t, interfaceObject, object, msg, args...) { + return } + t.FailNow() } // InDelta asserts that the two numerals are within delta of each other. @@ -535,9 +665,10 @@ func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64 if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.InDelta(t, expected, actual, delta, msgAndArgs...) { - t.FailNow() + if assert.InDelta(t, expected, actual, delta, msgAndArgs...) { + return } + t.FailNow() } // InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. @@ -545,9 +676,10 @@ func InDeltaMapValues(t TestingT, expected interface{}, actual interface{}, delt if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.InDeltaMapValues(t, expected, actual, delta, msgAndArgs...) { - t.FailNow() + if assert.InDeltaMapValues(t, expected, actual, delta, msgAndArgs...) { + return } + t.FailNow() } // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys. @@ -555,9 +687,10 @@ func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, del if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.InDeltaMapValuesf(t, expected, actual, delta, msg, args...) { - t.FailNow() + if assert.InDeltaMapValuesf(t, expected, actual, delta, msg, args...) { + return } + t.FailNow() } // InDeltaSlice is the same as InDelta, except it compares two slices. @@ -565,9 +698,10 @@ func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta fl if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) { - t.FailNow() + if assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) { + return } + t.FailNow() } // InDeltaSlicef is the same as InDelta, except it compares two slices. @@ -575,9 +709,10 @@ func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta f if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.InDeltaSlicef(t, expected, actual, delta, msg, args...) { - t.FailNow() + if assert.InDeltaSlicef(t, expected, actual, delta, msg, args...) { + return } + t.FailNow() } // InDeltaf asserts that the two numerals are within delta of each other. @@ -587,9 +722,10 @@ func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float6 if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.InDeltaf(t, expected, actual, delta, msg, args...) { - t.FailNow() + if assert.InDeltaf(t, expected, actual, delta, msg, args...) { + return } + t.FailNow() } // InEpsilon asserts that expected and actual have a relative error less than epsilon @@ -597,9 +733,10 @@ func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon flo if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) { - t.FailNow() + if assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) { + return } + t.FailNow() } // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. @@ -607,9 +744,10 @@ func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilo if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.InEpsilonSlice(t, expected, actual, epsilon, msgAndArgs...) { - t.FailNow() + if assert.InEpsilonSlice(t, expected, actual, epsilon, msgAndArgs...) { + return } + t.FailNow() } // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices. @@ -617,9 +755,10 @@ func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsil if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.InEpsilonSlicef(t, expected, actual, epsilon, msg, args...) { - t.FailNow() + if assert.InEpsilonSlicef(t, expected, actual, epsilon, msg, args...) { + return } + t.FailNow() } // InEpsilonf asserts that expected and actual have a relative error less than epsilon @@ -627,9 +766,10 @@ func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon fl if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.InEpsilonf(t, expected, actual, epsilon, msg, args...) { - t.FailNow() + if assert.InEpsilonf(t, expected, actual, epsilon, msg, args...) { + return } + t.FailNow() } // IsType asserts that the specified objects are of the same type. @@ -637,9 +777,10 @@ func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.IsType(t, expectedType, object, msgAndArgs...) { - t.FailNow() + if assert.IsType(t, expectedType, object, msgAndArgs...) { + return } + t.FailNow() } // IsTypef asserts that the specified objects are of the same type. @@ -647,9 +788,10 @@ func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg strin if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.IsTypef(t, expectedType, object, msg, args...) { - t.FailNow() + if assert.IsTypef(t, expectedType, object, msg, args...) { + return } + t.FailNow() } // JSONEq asserts that two JSON strings are equivalent. @@ -659,9 +801,10 @@ func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{ if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.JSONEq(t, expected, actual, msgAndArgs...) { - t.FailNow() + if assert.JSONEq(t, expected, actual, msgAndArgs...) { + return } + t.FailNow() } // JSONEqf asserts that two JSON strings are equivalent. @@ -671,9 +814,32 @@ func JSONEqf(t TestingT, expected string, actual string, msg string, args ...int if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.JSONEqf(t, expected, actual, msg, args...) { - t.FailNow() + if assert.JSONEqf(t, expected, actual, msg, args...) { + return } + t.FailNow() +} + +// YAMLEq asserts that two YAML strings are equivalent. +func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.YAMLEq(t, expected, actual, msgAndArgs...) { + return + } + t.FailNow() +} + +// YAMLEqf asserts that two YAML strings are equivalent. +func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.YAMLEqf(t, expected, actual, msg, args...) { + return + } + t.FailNow() } // Len asserts that the specified object has specific length. @@ -684,9 +850,10 @@ func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Len(t, object, length, msgAndArgs...) { - t.FailNow() + if assert.Len(t, object, length, msgAndArgs...) { + return } + t.FailNow() } // Lenf asserts that the specified object has specific length. @@ -697,9 +864,72 @@ func Lenf(t TestingT, object interface{}, length int, msg string, args ...interf if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Lenf(t, object, length, msg, args...) { - t.FailNow() + if assert.Lenf(t, object, length, msg, args...) { + return } + t.FailNow() +} + +// Less asserts that the first element is less than the second +// +// assert.Less(t, 1, 2) +// assert.Less(t, float64(1), float64(2)) +// assert.Less(t, "a", "b") +func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.Less(t, e1, e2, msgAndArgs...) { + return + } + t.FailNow() +} + +// LessOrEqual asserts that the first element is less than or equal to the second +// +// assert.LessOrEqual(t, 1, 2) +// assert.LessOrEqual(t, 2, 2) +// assert.LessOrEqual(t, "a", "b") +// assert.LessOrEqual(t, "b", "b") +func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.LessOrEqual(t, e1, e2, msgAndArgs...) { + return + } + t.FailNow() +} + +// LessOrEqualf asserts that the first element is less than or equal to the second +// +// assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted") +// assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted") +// assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted") +// assert.LessOrEqualf(t, "b", "b", "error message %s", "formatted") +func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.LessOrEqualf(t, e1, e2, msg, args...) { + return + } + t.FailNow() +} + +// Lessf asserts that the first element is less than the second +// +// assert.Lessf(t, 1, 2, "error message %s", "formatted") +// assert.Lessf(t, float64(1, "error message %s", "formatted"), float64(2)) +// assert.Lessf(t, "a", "b", "error message %s", "formatted") +func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.Lessf(t, e1, e2, msg, args...) { + return + } + t.FailNow() } // Nil asserts that the specified object is nil. @@ -709,9 +939,10 @@ func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Nil(t, object, msgAndArgs...) { - t.FailNow() + if assert.Nil(t, object, msgAndArgs...) { + return } + t.FailNow() } // Nilf asserts that the specified object is nil. @@ -721,9 +952,10 @@ func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Nilf(t, object, msg, args...) { - t.FailNow() + if assert.Nilf(t, object, msg, args...) { + return } + t.FailNow() } // NoError asserts that a function returned no error (i.e. `nil`). @@ -736,9 +968,10 @@ func NoError(t TestingT, err error, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NoError(t, err, msgAndArgs...) { - t.FailNow() + if assert.NoError(t, err, msgAndArgs...) { + return } + t.FailNow() } // NoErrorf asserts that a function returned no error (i.e. `nil`). @@ -751,9 +984,10 @@ func NoErrorf(t TestingT, err error, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NoErrorf(t, err, msg, args...) { - t.FailNow() + if assert.NoErrorf(t, err, msg, args...) { + return } + t.FailNow() } // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the @@ -766,9 +1000,10 @@ func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ... if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotContains(t, s, contains, msgAndArgs...) { - t.FailNow() + if assert.NotContains(t, s, contains, msgAndArgs...) { + return } + t.FailNow() } // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the @@ -781,9 +1016,10 @@ func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, a if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotContainsf(t, s, contains, msg, args...) { - t.FailNow() + if assert.NotContainsf(t, s, contains, msg, args...) { + return } + t.FailNow() } // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either @@ -796,9 +1032,10 @@ func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotEmpty(t, object, msgAndArgs...) { - t.FailNow() + if assert.NotEmpty(t, object, msgAndArgs...) { + return } + t.FailNow() } // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either @@ -811,9 +1048,10 @@ func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotEmptyf(t, object, msg, args...) { - t.FailNow() + if assert.NotEmptyf(t, object, msg, args...) { + return } + t.FailNow() } // NotEqual asserts that the specified values are NOT equal. @@ -826,9 +1064,10 @@ func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs . if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotEqual(t, expected, actual, msgAndArgs...) { - t.FailNow() + if assert.NotEqual(t, expected, actual, msgAndArgs...) { + return } + t.FailNow() } // NotEqualf asserts that the specified values are NOT equal. @@ -841,9 +1080,10 @@ func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotEqualf(t, expected, actual, msg, args...) { - t.FailNow() + if assert.NotEqualf(t, expected, actual, msg, args...) { + return } + t.FailNow() } // NotNil asserts that the specified object is not nil. @@ -853,9 +1093,10 @@ func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotNil(t, object, msgAndArgs...) { - t.FailNow() + if assert.NotNil(t, object, msgAndArgs...) { + return } + t.FailNow() } // NotNilf asserts that the specified object is not nil. @@ -865,9 +1106,10 @@ func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotNilf(t, object, msg, args...) { - t.FailNow() + if assert.NotNilf(t, object, msg, args...) { + return } + t.FailNow() } // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. @@ -877,9 +1119,10 @@ func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotPanics(t, f, msgAndArgs...) { - t.FailNow() + if assert.NotPanics(t, f, msgAndArgs...) { + return } + t.FailNow() } // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic. @@ -889,9 +1132,10 @@ func NotPanicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interfac if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotPanicsf(t, f, msg, args...) { - t.FailNow() + if assert.NotPanicsf(t, f, msg, args...) { + return } + t.FailNow() } // NotRegexp asserts that a specified regexp does not match a string. @@ -902,9 +1146,10 @@ func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interf if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotRegexp(t, rx, str, msgAndArgs...) { - t.FailNow() + if assert.NotRegexp(t, rx, str, msgAndArgs...) { + return } + t.FailNow() } // NotRegexpf asserts that a specified regexp does not match a string. @@ -915,9 +1160,10 @@ func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args .. if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotRegexpf(t, rx, str, msg, args...) { - t.FailNow() + if assert.NotRegexpf(t, rx, str, msg, args...) { + return } + t.FailNow() } // NotSubset asserts that the specified list(array, slice...) contains not all @@ -928,9 +1174,10 @@ func NotSubset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...i if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotSubset(t, list, subset, msgAndArgs...) { - t.FailNow() + if assert.NotSubset(t, list, subset, msgAndArgs...) { + return } + t.FailNow() } // NotSubsetf asserts that the specified list(array, slice...) contains not all @@ -941,9 +1188,10 @@ func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, ar if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotSubsetf(t, list, subset, msg, args...) { - t.FailNow() + if assert.NotSubsetf(t, list, subset, msg, args...) { + return } + t.FailNow() } // NotZero asserts that i is not the zero value for its type. @@ -951,9 +1199,10 @@ func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotZero(t, i, msgAndArgs...) { - t.FailNow() + if assert.NotZero(t, i, msgAndArgs...) { + return } + t.FailNow() } // NotZerof asserts that i is not the zero value for its type. @@ -961,9 +1210,10 @@ func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.NotZerof(t, i, msg, args...) { - t.FailNow() + if assert.NotZerof(t, i, msg, args...) { + return } + t.FailNow() } // Panics asserts that the code inside the specified PanicTestFunc panics. @@ -973,9 +1223,10 @@ func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Panics(t, f, msgAndArgs...) { - t.FailNow() + if assert.Panics(t, f, msgAndArgs...) { + return } + t.FailNow() } // PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that @@ -986,9 +1237,10 @@ func PanicsWithValue(t TestingT, expected interface{}, f assert.PanicTestFunc, m if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.PanicsWithValue(t, expected, f, msgAndArgs...) { - t.FailNow() + if assert.PanicsWithValue(t, expected, f, msgAndArgs...) { + return } + t.FailNow() } // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that @@ -999,9 +1251,10 @@ func PanicsWithValuef(t TestingT, expected interface{}, f assert.PanicTestFunc, if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.PanicsWithValuef(t, expected, f, msg, args...) { - t.FailNow() + if assert.PanicsWithValuef(t, expected, f, msg, args...) { + return } + t.FailNow() } // Panicsf asserts that the code inside the specified PanicTestFunc panics. @@ -1011,9 +1264,10 @@ func Panicsf(t TestingT, f assert.PanicTestFunc, msg string, args ...interface{} if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Panicsf(t, f, msg, args...) { - t.FailNow() + if assert.Panicsf(t, f, msg, args...) { + return } + t.FailNow() } // Regexp asserts that a specified regexp matches a string. @@ -1024,9 +1278,10 @@ func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Regexp(t, rx, str, msgAndArgs...) { - t.FailNow() + if assert.Regexp(t, rx, str, msgAndArgs...) { + return } + t.FailNow() } // Regexpf asserts that a specified regexp matches a string. @@ -1037,9 +1292,42 @@ func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...in if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Regexpf(t, rx, str, msg, args...) { - t.FailNow() + if assert.Regexpf(t, rx, str, msg, args...) { + return } + t.FailNow() +} + +// Same asserts that two pointers reference the same object. +// +// assert.Same(t, ptr1, ptr2) +// +// Both arguments must be pointer variables. Pointer variable sameness is +// determined based on the equality of both type and value. +func Same(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.Same(t, expected, actual, msgAndArgs...) { + return + } + t.FailNow() +} + +// Samef asserts that two pointers reference the same object. +// +// assert.Samef(t, ptr1, ptr2, "error message %s", "formatted") +// +// Both arguments must be pointer variables. Pointer variable sameness is +// determined based on the equality of both type and value. +func Samef(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) { + if h, ok := t.(tHelper); ok { + h.Helper() + } + if assert.Samef(t, expected, actual, msg, args...) { + return + } + t.FailNow() } // Subset asserts that the specified list(array, slice...) contains all @@ -1050,9 +1338,10 @@ func Subset(t TestingT, list interface{}, subset interface{}, msgAndArgs ...inte if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Subset(t, list, subset, msgAndArgs...) { - t.FailNow() + if assert.Subset(t, list, subset, msgAndArgs...) { + return } + t.FailNow() } // Subsetf asserts that the specified list(array, slice...) contains all @@ -1063,9 +1352,10 @@ func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Subsetf(t, list, subset, msg, args...) { - t.FailNow() + if assert.Subsetf(t, list, subset, msg, args...) { + return } + t.FailNow() } // True asserts that the specified value is true. @@ -1075,9 +1365,10 @@ func True(t TestingT, value bool, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.True(t, value, msgAndArgs...) { - t.FailNow() + if assert.True(t, value, msgAndArgs...) { + return } + t.FailNow() } // Truef asserts that the specified value is true. @@ -1087,9 +1378,10 @@ func Truef(t TestingT, value bool, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Truef(t, value, msg, args...) { - t.FailNow() + if assert.Truef(t, value, msg, args...) { + return } + t.FailNow() } // WithinDuration asserts that the two times are within duration delta of each other. @@ -1099,9 +1391,10 @@ func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) { - t.FailNow() + if assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) { + return } + t.FailNow() } // WithinDurationf asserts that the two times are within duration delta of each other. @@ -1111,9 +1404,10 @@ func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta tim if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.WithinDurationf(t, expected, actual, delta, msg, args...) { - t.FailNow() + if assert.WithinDurationf(t, expected, actual, delta, msg, args...) { + return } + t.FailNow() } // Zero asserts that i is the zero value for its type. @@ -1121,9 +1415,10 @@ func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Zero(t, i, msgAndArgs...) { - t.FailNow() + if assert.Zero(t, i, msgAndArgs...) { + return } + t.FailNow() } // Zerof asserts that i is the zero value for its type. @@ -1131,7 +1426,8 @@ func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.Zerof(t, i, msg, args...) { - t.FailNow() + if assert.Zerof(t, i, msg, args...) { + return } + t.FailNow() } diff --git a/vendor/github.com/stretchr/testify/require/require.go.tmpl b/vendor/github.com/stretchr/testify/require/require.go.tmpl index 9fb2577d4..55e42ddeb 100644 --- a/vendor/github.com/stretchr/testify/require/require.go.tmpl +++ b/vendor/github.com/stretchr/testify/require/require.go.tmpl @@ -1,7 +1,6 @@ {{.Comment}} func {{.DocInfo.Name}}(t TestingT, {{.Params}}) { if h, ok := t.(tHelper); ok { h.Helper() } - if !assert.{{.DocInfo.Name}}(t, {{.ForwardedParams}}) { - t.FailNow() - } + if assert.{{.DocInfo.Name}}(t, {{.ForwardedParams}}) { return } + t.FailNow() } diff --git a/vendor/github.com/stretchr/testify/require/require_forward.go b/vendor/github.com/stretchr/testify/require/require_forward.go index 9c66cd3c3..804fae035 100644 --- a/vendor/github.com/stretchr/testify/require/require_forward.go +++ b/vendor/github.com/stretchr/testify/require/require_forward.go @@ -216,6 +216,28 @@ func (a *Assertions) Errorf(err error, msg string, args ...interface{}) { Errorf(a.t, err, msg, args...) } +// Eventually asserts that given condition will be met in waitFor time, +// periodically checking target function each tick. +// +// a.Eventually(func() bool { return true; }, time.Second, 10*time.Millisecond) +func (a *Assertions) Eventually(condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + Eventually(a.t, condition, waitFor, tick, msgAndArgs...) +} + +// Eventuallyf asserts that given condition will be met in waitFor time, +// periodically checking target function each tick. +// +// a.Eventuallyf(func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted") +func (a *Assertions) Eventuallyf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + Eventuallyf(a.t, condition, waitFor, tick, msg, args...) +} + // Exactly asserts that two objects are equal in value and type. // // a.Exactly(int32(123), int64(123)) @@ -304,10 +326,60 @@ func (a *Assertions) FileExistsf(path string, msg string, args ...interface{}) { FileExistsf(a.t, path, msg, args...) } +// Greater asserts that the first element is greater than the second +// +// a.Greater(2, 1) +// a.Greater(float64(2), float64(1)) +// a.Greater("b", "a") +func (a *Assertions) Greater(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + Greater(a.t, e1, e2, msgAndArgs...) +} + +// GreaterOrEqual asserts that the first element is greater than or equal to the second +// +// a.GreaterOrEqual(2, 1) +// a.GreaterOrEqual(2, 2) +// a.GreaterOrEqual("b", "a") +// a.GreaterOrEqual("b", "b") +func (a *Assertions) GreaterOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + GreaterOrEqual(a.t, e1, e2, msgAndArgs...) +} + +// GreaterOrEqualf asserts that the first element is greater than or equal to the second +// +// a.GreaterOrEqualf(2, 1, "error message %s", "formatted") +// a.GreaterOrEqualf(2, 2, "error message %s", "formatted") +// a.GreaterOrEqualf("b", "a", "error message %s", "formatted") +// a.GreaterOrEqualf("b", "b", "error message %s", "formatted") +func (a *Assertions) GreaterOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + GreaterOrEqualf(a.t, e1, e2, msg, args...) +} + +// Greaterf asserts that the first element is greater than the second +// +// a.Greaterf(2, 1, "error message %s", "formatted") +// a.Greaterf(float64(2, "error message %s", "formatted"), float64(1)) +// a.Greaterf("b", "a", "error message %s", "formatted") +func (a *Assertions) Greaterf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + Greaterf(a.t, e1, e2, msg, args...) +} + // HTTPBodyContains asserts that a specified handler returns a // body that contains a string. // -// a.HTTPBodyContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// a.HTTPBodyContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") // // Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { @@ -320,7 +392,7 @@ func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, u // HTTPBodyContainsf asserts that a specified handler returns a // body that contains a string. // -// a.HTTPBodyContainsf(myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") +// a.HTTPBodyContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { @@ -333,7 +405,7 @@ func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, // HTTPBodyNotContains asserts that a specified handler returns a // body that does not contain a string. // -// a.HTTPBodyNotContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky") +// a.HTTPBodyNotContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky") // // Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) { @@ -346,7 +418,7 @@ func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string // HTTPBodyNotContainsf asserts that a specified handler returns a // body that does not contain a string. // -// a.HTTPBodyNotContainsf(myHandler, "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") +// a.HTTPBodyNotContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted") // // Returns whether the assertion was successful (true) or not (false). func (a *Assertions) HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) { @@ -568,6 +640,22 @@ func (a *Assertions) JSONEqf(expected string, actual string, msg string, args .. JSONEqf(a.t, expected, actual, msg, args...) } +// YAMLEq asserts that two YAML strings are equivalent. +func (a *Assertions) YAMLEq(expected string, actual string, msgAndArgs ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + YAMLEq(a.t, expected, actual, msgAndArgs...) +} + +// YAMLEqf asserts that two YAML strings are equivalent. +func (a *Assertions) YAMLEqf(expected string, actual string, msg string, args ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + YAMLEqf(a.t, expected, actual, msg, args...) +} + // Len asserts that the specified object has specific length. // Len also fails if the object has a type that len() not accept. // @@ -590,6 +678,56 @@ func (a *Assertions) Lenf(object interface{}, length int, msg string, args ...in Lenf(a.t, object, length, msg, args...) } +// Less asserts that the first element is less than the second +// +// a.Less(1, 2) +// a.Less(float64(1), float64(2)) +// a.Less("a", "b") +func (a *Assertions) Less(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + Less(a.t, e1, e2, msgAndArgs...) +} + +// LessOrEqual asserts that the first element is less than or equal to the second +// +// a.LessOrEqual(1, 2) +// a.LessOrEqual(2, 2) +// a.LessOrEqual("a", "b") +// a.LessOrEqual("b", "b") +func (a *Assertions) LessOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + LessOrEqual(a.t, e1, e2, msgAndArgs...) +} + +// LessOrEqualf asserts that the first element is less than or equal to the second +// +// a.LessOrEqualf(1, 2, "error message %s", "formatted") +// a.LessOrEqualf(2, 2, "error message %s", "formatted") +// a.LessOrEqualf("a", "b", "error message %s", "formatted") +// a.LessOrEqualf("b", "b", "error message %s", "formatted") +func (a *Assertions) LessOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + LessOrEqualf(a.t, e1, e2, msg, args...) +} + +// Lessf asserts that the first element is less than the second +// +// a.Lessf(1, 2, "error message %s", "formatted") +// a.Lessf(float64(1, "error message %s", "formatted"), float64(2)) +// a.Lessf("a", "b", "error message %s", "formatted") +func (a *Assertions) Lessf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + Lessf(a.t, e1, e2, msg, args...) +} + // Nil asserts that the specified object is nil. // // a.Nil(err) @@ -878,6 +1016,32 @@ func (a *Assertions) Regexpf(rx interface{}, str interface{}, msg string, args . Regexpf(a.t, rx, str, msg, args...) } +// Same asserts that two pointers reference the same object. +// +// a.Same(ptr1, ptr2) +// +// Both arguments must be pointer variables. Pointer variable sameness is +// determined based on the equality of both type and value. +func (a *Assertions) Same(expected interface{}, actual interface{}, msgAndArgs ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + Same(a.t, expected, actual, msgAndArgs...) +} + +// Samef asserts that two pointers reference the same object. +// +// a.Samef(ptr1, ptr2, "error message %s", "formatted") +// +// Both arguments must be pointer variables. Pointer variable sameness is +// determined based on the equality of both type and value. +func (a *Assertions) Samef(expected interface{}, actual interface{}, msg string, args ...interface{}) { + if h, ok := a.t.(tHelper); ok { + h.Helper() + } + Samef(a.t, expected, actual, msg, args...) +} + // Subset asserts that the specified list(array, slice...) contains all // elements given in the specified subset(array, slice...). // diff --git a/vendor/github.com/stretchr/testify/require/requirements.go b/vendor/github.com/stretchr/testify/require/requirements.go index 690583a8e..6b85c5ece 100644 --- a/vendor/github.com/stretchr/testify/require/requirements.go +++ b/vendor/github.com/stretchr/testify/require/requirements.go @@ -22,7 +22,7 @@ type ValueAssertionFunc func(TestingT, interface{}, ...interface{}) // for table driven tests. type BoolAssertionFunc func(TestingT, bool, ...interface{}) -// ValuesAssertionFunc is a common function prototype when validating an error value. Can be useful +// ErrorAssertionFunc is a common function prototype when validating an error value. Can be useful // for table driven tests. type ErrorAssertionFunc func(TestingT, error, ...interface{}) diff --git a/vendor/vendor.json b/vendor/vendor.json index 68b09ed4e..3f5906c60 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -367,10 +367,13 @@ {"path":"github.com/skratchdot/open-golang/open","checksumSHA1":"h/HMhokbQHTdLUbruoBBTee+NYw=","revision":"75fb7ed4208cf72d323d7d02fd1a5964a7a9073c","revisionTime":"2016-03-02T14:40:31Z"}, {"path":"github.com/spf13/pflag","checksumSHA1":"Q52Y7t0lEtk/wcDn5q7tS7B+jqs=","revision":"7aff26db30c1be810f9de5038ec5ef96ac41fd7c","revisionTime":"2017-08-24T17:57:12Z"}, {"path":"github.com/stretchr/objx","checksumSHA1":"K0crHygPTP42i1nLKWphSlvOQJw=","revision":"1a9d0bb9f541897e62256577b352fdbc1fb4fd94","revisionTime":"2015-09-28T12:21:52Z"}, - {"path":"github.com/stretchr/testify/assert","checksumSHA1":"6LwXZI7kXm1C0h4Ui0Y52p9uQhk=","revision":"c679ae2cc0cb27ec3293fea7e254e47386f05d69","revisionTime":"2018-03-14T08:05:35Z"}, - {"path":"github.com/stretchr/testify/mock","checksumSHA1":"Qloi2PTvZv+D9FDHXM/banCoaFY=","revision":"c679ae2cc0cb27ec3293fea7e254e47386f05d69","revisionTime":"2018-03-14T08:05:35Z"}, - {"path":"github.com/stretchr/testify/require","checksumSHA1":"KqYmXUcuGwsvBL6XVsQnXsFb3LI=","revision":"c679ae2cc0cb27ec3293fea7e254e47386f05d69","revisionTime":"2018-03-14T08:05:35Z"}, + {"path":"github.com/stretchr/testify/assert","checksumSHA1":"/7bZ0f2fM9AAsLf3nMca6Gtlm6E=","revision":"221dbe5ed46703ee255b1da0dec05086f5035f62","revisionTime":"2019-05-17T17:51:56Z","version":"v1.4.0","versionExact":"v1.4.0"}, + {"path":"github.com/stretchr/testify/mock","checksumSHA1":"bg70xAHEu6HRf2iFu8h5iJBjUfg=","revision":"221dbe5ed46703ee255b1da0dec05086f5035f62","revisionTime":"2019-05-17T17:51:56Z","version":"v1.4.0","versionExact":"v1.4.0"}, + {"path":"github.com/stretchr/testify/require","checksumSHA1":"ABkrw83kq3/d6oSRX+BFq57/BiY=","revision":"221dbe5ed46703ee255b1da0dec05086f5035f62","revisionTime":"2019-05-17T17:51:56Z","version":"v1.4.0","versionExact":"v1.4.0"}, {"path":"github.com/syndtr/gocapability/capability","checksumSHA1":"PgEklGW56c5RLHqQhORxt6jS3fY=","revision":"db04d3cc01c8b54962a58ec7e491717d06cfcc16","revisionTime":"2017-07-04T07:02:18Z"}, + {"path":"github.com/testify/assert","revision":"v1.4.0","version":"v1.4.0"}, + {"path":"github.com/testify/mock","revision":"v1.4.0","version":"v1.4.0"}, + {"path":"github.com/testify/require","revision":"v1.4.0","version":"v1.4.0"}, {"path":"github.com/tonnerre/golang-text","checksumSHA1":"t24KnvC9jRxiANVhpw2pqFpmEu8=","revision":"048ed3d792f7104850acbc8cfc01e5a6070f4c04","revisionTime":"2013-09-25T19:58:46Z"}, {"path":"github.com/tv42/httpunix","checksumSHA1":"2xcr/mhxBFlDjpxe/Mc2Wb4RGR8=","revision":"b75d8614f926c077e48d85f1f8f7885b758c6225","revisionTime":"2015-04-27T01:28:21Z"}, {"path":"github.com/ugorji/go/codec","checksumSHA1":"8G1zvpE4gTtWQRuP/x2HPVDmflo=","revision":"0053ebfd9d0ee06ccefbfe17072021e1d4acebee","revisionTime":"2017-06-20T06:01:02Z"},