forked from vcabbage/amqp
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for errors.As() to see the underlying AMQP error (#329)
You can now do errors.As() and grab the amqp.Error{} out of Link/Session/ConnErrors.
- Loading branch information
1 parent
1003610
commit 58e8fd8
Showing
3 changed files
with
77 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package amqp_test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
amqp "github.com/Azure/go-amqp" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestErrorUnwrap(t *testing.T) { | ||
// In the majority of common use cases, the LinkError, ConnError and SessionError will contain an amqp.Error. | ||
// It's simpler, for callers, if they can simply check errors.As(&amqp.Error) so they can write general error | ||
// handling, rather than having to check the envelope type each time. | ||
t.Run("LinkError", func(t *testing.T) { | ||
var amqpErr *amqp.Error | ||
|
||
le := &amqp.LinkError{} | ||
require.False(t, errors.As(le, &amqpErr)) | ||
|
||
le.RemoteErr = &amqp.Error{Condition: amqp.ErrCondConnectionForced} | ||
require.ErrorAs(t, le, &amqpErr) | ||
}) | ||
|
||
t.Run("ConnError", func(t *testing.T) { | ||
var amqpErr *amqp.Error | ||
|
||
ce := &amqp.ConnError{} | ||
require.False(t, errors.As(ce, &amqpErr)) | ||
|
||
ce.RemoteErr = &amqp.Error{Condition: amqp.ErrCondConnectionForced} | ||
require.ErrorAs(t, ce, &amqpErr) | ||
}) | ||
|
||
t.Run("SessionError", func(t *testing.T) { | ||
var amqpErr *amqp.Error | ||
|
||
se := &amqp.ConnError{} | ||
require.False(t, errors.As(se, &amqpErr)) | ||
|
||
se.RemoteErr = &amqp.Error{Condition: amqp.ErrCondConnectionForced} | ||
require.ErrorAs(t, se, &amqpErr) | ||
}) | ||
} |