Retry temporary errors by default (#107)
* Adding Aurora URL validator in order to handle scenarios where incomplete information is passed to the client. The client will do its best to guess the missing information such as protocol and port. * Upgraded to testify 1.3.0. * Added configuration to fail on a non-temporary error. This is reverting to the original behavior of the retry mechanism. However, this allows the user to opt to fail in a non-temporary error.
This commit is contained in:
parent
4ffb509939
commit
6dc4bf93b9
37 changed files with 2795 additions and 1009 deletions
226
vendor/github.com/stretchr/testify/assert/assertions_test.go
generated
vendored
226
vendor/github.com/stretchr/testify/assert/assertions_test.go
generated
vendored
|
@ -2,6 +2,7 @@ package assert
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -174,6 +175,8 @@ func TestIsType(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
type myType string
|
||||
|
||||
func TestEqual(t *testing.T) {
|
||||
|
||||
mockT := new(testing.T)
|
||||
|
@ -199,6 +202,9 @@ func TestEqual(t *testing.T) {
|
|||
if !Equal(mockT, uint64(123), uint64(123)) {
|
||||
t.Error("Equal should return true")
|
||||
}
|
||||
if !Equal(mockT, myType("1"), myType("1")) {
|
||||
t.Error("Equal should return true")
|
||||
}
|
||||
if !Equal(mockT, &struct{}{}, &struct{}{}) {
|
||||
t.Error("Equal should return true (pointer equality is based on equality of underlying value)")
|
||||
}
|
||||
|
@ -206,6 +212,9 @@ func TestEqual(t *testing.T) {
|
|||
if Equal(mockT, m["bar"], "something") {
|
||||
t.Error("Equal should return false")
|
||||
}
|
||||
if Equal(mockT, myType("1"), myType("2")) {
|
||||
t.Error("Equal should return false")
|
||||
}
|
||||
}
|
||||
|
||||
// bufferT implements TestingT. Its implementation of Errorf writes the output that would be produced by
|
||||
|
@ -250,6 +259,21 @@ func (t *bufferT) Errorf(format string, args ...interface{}) {
|
|||
t.buf.WriteString(decorate(fmt.Sprintf(format, args...)))
|
||||
}
|
||||
|
||||
func TestStringEqual(t *testing.T) {
|
||||
for i, currCase := range []struct {
|
||||
equalWant string
|
||||
equalGot string
|
||||
msgAndArgs []interface{}
|
||||
want string
|
||||
}{
|
||||
{equalWant: "hi, \nmy name is", equalGot: "what,\nmy name is", want: "\tassertions.go:\\d+: \n\t+Error Trace:\t\n\t+Error:\\s+Not equal:\\s+\n\\s+expected: \"hi, \\\\nmy name is\"\n\\s+actual\\s+: \"what,\\\\nmy name is\"\n\\s+Diff:\n\\s+-+ Expected\n\\s+\\++ Actual\n\\s+@@ -1,2 \\+1,2 @@\n\\s+-hi, \n\\s+\\+what,\n\\s+my name is"},
|
||||
} {
|
||||
mockT := &bufferT{}
|
||||
Equal(mockT, currCase.equalWant, currCase.equalGot, currCase.msgAndArgs...)
|
||||
Regexp(t, regexp.MustCompile(currCase.want), mockT.buf.String(), "Case %d", i)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEqualFormatting(t *testing.T) {
|
||||
for i, currCase := range []struct {
|
||||
equalWant string
|
||||
|
@ -257,8 +281,10 @@ func TestEqualFormatting(t *testing.T) {
|
|||
msgAndArgs []interface{}
|
||||
want string
|
||||
}{
|
||||
{equalWant: "want", equalGot: "got", want: "\tassertions.go:[0-9]+: \r \r\tError Trace:\t\n\t\t\r\tError: \tNot equal: \n\t\t\r\t \texpected: \"want\"\n\t\t\r\t \tactual : \"got\"\n"},
|
||||
{equalWant: "want", equalGot: "got", msgAndArgs: []interface{}{"hello, %v!", "world"}, want: "\tassertions.go:[0-9]+: \r \r\tError Trace:\t\n\t\t\r\tError: \tNot equal: \n\t\t\r\t \texpected: \"want\"\n\t\t\r\t \tactual : \"got\"\n\t\t\r\tMessages: \thello, world!\n"},
|
||||
{equalWant: "want", equalGot: "got", want: "\tassertions.go:\\d+: \n\t+Error Trace:\t\n\t+Error:\\s+Not equal:\\s+\n\\s+expected: \"want\"\n\\s+actual\\s+: \"got\"\n\\s+Diff:\n\\s+-+ Expected\n\\s+\\++ Actual\n\\s+@@ -1 \\+1 @@\n\\s+-want\n\\s+\\+got\n"},
|
||||
{equalWant: "want", equalGot: "got", msgAndArgs: []interface{}{"hello, %v!", "world"}, want: "\tassertions.go:[0-9]+: \n\t+Error Trace:\t\n\t+Error:\\s+Not equal:\\s+\n\\s+expected: \"want\"\n\\s+actual\\s+: \"got\"\n\\s+Diff:\n\\s+-+ Expected\n\\s+\\++ Actual\n\\s+@@ -1 \\+1 @@\n\\s+-want\n\\s+\\+got\n\\s+Messages:\\s+hello, world!\n"},
|
||||
{equalWant: "want", equalGot: "got", msgAndArgs: []interface{}{123}, want: "\tassertions.go:[0-9]+: \n\t+Error Trace:\t\n\t+Error:\\s+Not equal:\\s+\n\\s+expected: \"want\"\n\\s+actual\\s+: \"got\"\n\\s+Diff:\n\\s+-+ Expected\n\\s+\\++ Actual\n\\s+@@ -1 \\+1 @@\n\\s+-want\n\\s+\\+got\n\\s+Messages:\\s+123\n"},
|
||||
{equalWant: "want", equalGot: "got", msgAndArgs: []interface{}{struct{ a string }{"hello"}}, want: "\tassertions.go:[0-9]+: \n\t+Error Trace:\t\n\t+Error:\\s+Not equal:\\s+\n\\s+expected: \"want\"\n\\s+actual\\s+: \"got\"\n\\s+Diff:\n\\s+-+ Expected\n\\s+\\++ Actual\n\\s+@@ -1 \\+1 @@\n\\s+-want\n\\s+\\+got\n\\s+Messages:\\s+{a:hello}\n"},
|
||||
} {
|
||||
mockT := &bufferT{}
|
||||
Equal(mockT, currCase.equalWant, currCase.equalGot, currCase.msgAndArgs...)
|
||||
|
@ -1579,3 +1605,199 @@ func TestEqualArgsValidation(t *testing.T) {
|
|||
err := validateEqualArgs(time.Now, time.Now)
|
||||
EqualError(t, err, "cannot take func type as argument")
|
||||
}
|
||||
|
||||
func ExampleComparisonAssertionFunc() {
|
||||
t := &testing.T{} // provided by test
|
||||
|
||||
adder := func(x, y int) int {
|
||||
return x + y
|
||||
}
|
||||
|
||||
type args struct {
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
expect int
|
||||
assertion ComparisonAssertionFunc
|
||||
}{
|
||||
{"2+2=4", args{2, 2}, 4, Equal},
|
||||
{"2+2!=5", args{2, 2}, 5, NotEqual},
|
||||
{"2+3==5", args{2, 3}, 5, Exactly},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.assertion(t, tt.expect, adder(tt.args.x, tt.args.y))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestComparisonAssertionFunc(t *testing.T) {
|
||||
type iface interface {
|
||||
Name() string
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
expect interface{}
|
||||
got interface{}
|
||||
assertion ComparisonAssertionFunc
|
||||
}{
|
||||
{"implements", (*iface)(nil), t, Implements},
|
||||
{"isType", (*testing.T)(nil), t, IsType},
|
||||
{"equal", t, t, Equal},
|
||||
{"equalValues", t, t, EqualValues},
|
||||
{"exactly", t, t, Exactly},
|
||||
{"notEqual", t, nil, NotEqual},
|
||||
{"notContains", []int{1, 2, 3}, 4, NotContains},
|
||||
{"subset", []int{1, 2, 3, 4}, []int{2, 3}, Subset},
|
||||
{"notSubset", []int{1, 2, 3, 4}, []int{0, 3}, NotSubset},
|
||||
{"elementsMatch", []byte("abc"), []byte("bac"), ElementsMatch},
|
||||
{"regexp", "^t.*y$", "testify", Regexp},
|
||||
{"notRegexp", "^t.*y$", "Testify", NotRegexp},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.assertion(t, tt.expect, tt.got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleValueAssertionFunc() {
|
||||
t := &testing.T{} // provided by test
|
||||
|
||||
dumbParse := func(input string) interface{} {
|
||||
var x interface{}
|
||||
json.Unmarshal([]byte(input), &x)
|
||||
return x
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
arg string
|
||||
assertion ValueAssertionFunc
|
||||
}{
|
||||
{"true is not nil", "true", NotNil},
|
||||
{"empty string is nil", "", Nil},
|
||||
{"zero is not nil", "0", NotNil},
|
||||
{"zero is zero", "0", Zero},
|
||||
{"false is zero", "false", Zero},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.assertion(t, dumbParse(tt.arg))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValueAssertionFunc(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
value interface{}
|
||||
assertion ValueAssertionFunc
|
||||
}{
|
||||
{"notNil", true, NotNil},
|
||||
{"nil", nil, Nil},
|
||||
{"empty", []int{}, Empty},
|
||||
{"notEmpty", []int{1}, NotEmpty},
|
||||
{"zero", false, Zero},
|
||||
{"notZero", 42, NotZero},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.assertion(t, tt.value)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleBoolAssertionFunc() {
|
||||
t := &testing.T{} // provided by test
|
||||
|
||||
isOkay := func(x int) bool {
|
||||
return x >= 42
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
arg int
|
||||
assertion BoolAssertionFunc
|
||||
}{
|
||||
{"-1 is bad", -1, False},
|
||||
{"42 is good", 42, True},
|
||||
{"41 is bad", 41, False},
|
||||
{"45 is cool", 45, True},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.assertion(t, isOkay(tt.arg))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBoolAssertionFunc(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
value bool
|
||||
assertion BoolAssertionFunc
|
||||
}{
|
||||
{"true", true, True},
|
||||
{"false", false, False},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.assertion(t, tt.value)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleErrorAssertionFunc() {
|
||||
t := &testing.T{} // provided by test
|
||||
|
||||
dumbParseNum := func(input string, v interface{}) error {
|
||||
return json.Unmarshal([]byte(input), v)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
arg string
|
||||
assertion ErrorAssertionFunc
|
||||
}{
|
||||
{"1.2 is number", "1.2", NoError},
|
||||
{"1.2.3 not number", "1.2.3", Error},
|
||||
{"true is not number", "true", Error},
|
||||
{"3 is number", "3", NoError},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var x float64
|
||||
tt.assertion(t, dumbParseNum(tt.arg, &x))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrorAssertionFunc(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
err error
|
||||
assertion ErrorAssertionFunc
|
||||
}{
|
||||
{"noError", nil, NoError},
|
||||
{"error", errors.New("whoops"), Error},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tt.assertion(t, tt.err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue