-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored errors to better allow generic error handling
- Loading branch information
Showing
6 changed files
with
95 additions
and
77 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,50 @@ | ||
package bascule | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type ErrorSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func (suite *ErrorSuite) TestUnsupportedSchemeError() { | ||
err := UnsupportedSchemeError{ | ||
Scheme: Scheme("scheme"), | ||
} | ||
|
||
suite.Contains(err.Error(), "scheme") | ||
suite.Equal(ErrorTypeBadCredentials, err.Type()) | ||
} | ||
|
||
func (suite *ErrorSuite) TestBadCredentialsError() { | ||
err := BadCredentialsError{ | ||
Raw: "these are an unparseable, raw credentials", | ||
} | ||
|
||
suite.Contains(err.Error(), "these are an unparseable, raw credentials") | ||
suite.Equal(ErrorTypeBadCredentials, err.Type()) | ||
} | ||
|
||
func (suite *ErrorSuite) TestGetErrorType() { | ||
suite.Run("Unknown", func() { | ||
suite.Equal( | ||
ErrorTypeUnknown, | ||
GetErrorType(errors.New("this is an error that is unknown to bascule")), | ||
) | ||
}) | ||
|
||
suite.Run("ImplementsError", func() { | ||
suite.Equal( | ||
ErrorTypeBadCredentials, | ||
GetErrorType(new(BadCredentialsError)), | ||
) | ||
}) | ||
} | ||
|
||
func TestError(t *testing.T) { | ||
suite.Run(t, new(ErrorSuite)) | ||
} |