forked from IBM/sarama
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix IBM#2128 - make ErrOutOfBrokers wrap the underlying net exception…
…s that prevented connection
- Loading branch information
Showing
4 changed files
with
193 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package sarama | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net" | ||
"testing" | ||
) | ||
|
||
func TestMultiError(t *testing.T) { | ||
|
||
myNetError := &net.OpError{Op: "mock", Err: errors.New("op error")} | ||
myAddrError := &net.AddrError{Err: "mock addr error"} | ||
|
||
multiError := NewMultiError(myNetError, myAddrError) | ||
|
||
expected := "mock: op error,mock addr error" | ||
actual := multiError.Error() | ||
if actual != expected { | ||
t.Errorf("unexpected value '%s' vs '%s'", expected, actual) | ||
} | ||
|
||
if !errors.Is(multiError, myNetError) { | ||
t.Error("errors.Is unexpected result") | ||
} | ||
|
||
if !errors.Is(multiError, myAddrError) { | ||
t.Error("errors.Is unexpected result") | ||
} | ||
|
||
var opError *net.OpError | ||
if !errors.As(multiError, &opError) { | ||
t.Error("errors.As unexpected result") | ||
} else if opError != myNetError { | ||
t.Error("errors.As wrong value") | ||
} | ||
|
||
var addrError *net.AddrError | ||
if !errors.As(multiError, &addrError) { | ||
t.Error("errors.As unexpected result") | ||
} else if addrError != myAddrError { | ||
t.Error("errors.As wrong value") | ||
} | ||
} | ||
|
||
func TestSentinelWithWrappedError(t *testing.T) { | ||
myNetError := &net.OpError{Op: "mock", Err: errors.New("op error")} | ||
error := Wrap(ErrOutOfBrokers, myNetError) | ||
|
||
expected := fmt.Sprintf("%s: mock: op error", ErrOutOfBrokers) | ||
actual := error.Error() | ||
if actual != expected { | ||
t.Errorf("unexpected value '%s' vs '%s'", 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) { | ||
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") | ||
} | ||
} |