1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
//go:build !functional
package sarama
import (
"errors"
"fmt"
"net"
"testing"
)
func TestSentinelWithSingleWrappedError(t *testing.T) {
t.Parallel()
myNetError := &net.OpError{Op: "mock", Err: errors.New("op error")}
error := Wrap(ErrOutOfBrokers, myNetError)
expected := fmt.Sprintf("%s: %s", ErrOutOfBrokers, myNetError)
actual := error.Error()
if actual != expected {
t.Errorf("unexpected value '%s' vs '%v'", expected, actual)
}
if !errors.Is(error, ErrOutOfBrokers) {
t.Error("errors.Is unexpected result")
}
if !errors.Is(error, myNetError) {
t.Error("errors.Is unexpected result")
}
var opError *net.OpError
if !errors.As(error, &opError) {
t.Error("errors.As unexpected result")
} else if opError != myNetError {
t.Error("errors.As wrong value")
}
unwrapped := errors.Unwrap(error)
if errors.Is(unwrapped, ErrOutOfBrokers) || !errors.Is(unwrapped, myNetError) {
t.Errorf("unexpected unwrapped value %v vs %vs", error, unwrapped)
}
}
func TestSentinelWithMultipleWrappedErrors(t *testing.T) {
t.Parallel()
myNetError := &net.OpError{}
myAddrError := &net.AddrError{}
error := Wrap(ErrOutOfBrokers, myNetError, myAddrError)
if !errors.Is(error, ErrOutOfBrokers) {
t.Error("errors.Is unexpected result")
}
if !errors.Is(error, myNetError) {
t.Error("errors.Is unexpected result")
}
if !errors.Is(error, myAddrError) {
t.Error("errors.Is unexpected result")
}
unwrapped := errors.Unwrap(error)
if errors.Is(unwrapped, ErrOutOfBrokers) || !errors.Is(unwrapped, myNetError) || !errors.Is(unwrapped, myAddrError) {
t.Errorf("unwrapped value unexpected result")
}
}
|