Add specs for AWS Backoff

This commit is contained in:
dan 2015-05-06 09:18:15 -07:00 committed by Harlow Ward
parent 8c660f79fb
commit 95fe49e7e0

35
awsbackoff_test.go Normal file
View file

@ -0,0 +1,35 @@
package connector
import (
"fmt"
"net"
"testing"
"github.com/lib/pq"
"github.com/sendgridlabs/go-kinesis"
)
func Test_isRecoverableError(t *testing.T) {
testCases := []struct {
err error
isRecoverable bool
}{
{err: &kinesis.Error{Code: "ProvisionedThroughputExceededException"}, isRecoverable: true},
{err: &kinesis.Error{Code: "Throttling"}, isRecoverable: true},
{err: &kinesis.Error{Code: "ServiceUnavailable"}, isRecoverable: true},
{err: &kinesis.Error{Code: "ExpiredIteratorException"}, isRecoverable: false},
{err: &net.OpError{Err: fmt.Errorf("connection reset by peer")}, isRecoverable: true},
{err: &net.OpError{Err: fmt.Errorf("unexpected error")}, isRecoverable: false},
{err: fmt.Errorf("an arbitrary error"), isRecoverable: false},
{err: pq.Error{Message: "The specified S3 prefix 'somefilethatismissing' does not exist"}, isRecoverable: true},
{err: pq.Error{Message: "Some other pq error"}, isRecoverable: false},
}
for idx, tc := range testCases {
isRecoverable := isRecoverableError(tc.err)
if isRecoverable != tc.isRecoverable {
t.Errorf("test case %d: isRecoverable expected %t, actual %t, for error %+v", idx, tc.isRecoverable, isRecoverable, tc.err)
}
}
}