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: make ErrOutOfBrokers wrap underlying net err
Ensure that ErrOutOfBrokers exception(s) include the actual underlying error that prevented successful connection(s) to the brokers. Fixes IBM#2128
- Loading branch information
Showing
8 changed files
with
207 additions
and
53 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
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,65 @@ | ||
package sarama | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net" | ||
"testing" | ||
) | ||
|
||
func TestSentinelWithWrappedError(t *testing.T) { | ||
t.Parallel() | ||
myNetError := &net.OpError{Op: "mock", Err: errors.New("op error")} | ||
error := Wrap(ErrOutOfBrokers, myNetError) | ||
|
||
expected := fmt.Sprintf("%s: 1 error occurred:\n\t* %s\n\n", 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") | ||
} | ||
} |
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
Oops, something went wrong.