Helper method to expose internal errors associated with a public error category (#3233)
<!-- PR description--> Helper method to expose internal errors associated with a public error category, useful for testing `errs.Is` scenarios. The internal error needs to be used because `errs.Is` checks if the error chain contains a ref to the internal error. #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [x] 🧹 Tech Debt/Cleanup #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * #COR-77 #### Test Plan <!-- How will this be tested prior to merging.--> - [x] 💪 Manual - [x] ⚡ Unit test - [x] 💚 E2E
This commit is contained in:
parent
534924f696
commit
c28673b2f0
@ -29,6 +29,11 @@ var internalToExternal = map[errEnum][]error{
|
|||||||
ResourceOwnerNotFound: {graph.ErrResourceOwnerNotFound},
|
ResourceOwnerNotFound: {graph.ErrResourceOwnerNotFound},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Internal returns the internal errors which match to the public error category.
|
||||||
|
func Internal(enum errEnum) []error {
|
||||||
|
return internalToExternal[enum]
|
||||||
|
}
|
||||||
|
|
||||||
// Is checks if the provided error contains an internal error that matches
|
// Is checks if the provided error contains an internal error that matches
|
||||||
// the public error category.
|
// the public error category.
|
||||||
func Is(err error, enum errEnum) bool {
|
func Is(err error, enum errEnum) bool {
|
||||||
|
|||||||
@ -19,6 +19,23 @@ func TestErrUnitSuite(t *testing.T) {
|
|||||||
suite.Run(t, &ErrUnitSuite{Suite: tester.NewUnitSuite(t)})
|
suite.Run(t, &ErrUnitSuite{Suite: tester.NewUnitSuite(t)})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *ErrUnitSuite) TestInternal() {
|
||||||
|
table := []struct {
|
||||||
|
get errEnum
|
||||||
|
expect []error
|
||||||
|
}{
|
||||||
|
{RepoAlreadyExists, []error{repository.ErrorRepoAlreadyExists}},
|
||||||
|
{BackupNotFound, []error{repository.ErrorBackupNotFound}},
|
||||||
|
{ServiceNotEnabled, []error{graph.ErrServiceNotEnabled}},
|
||||||
|
{ResourceOwnerNotFound, []error{graph.ErrResourceOwnerNotFound}},
|
||||||
|
}
|
||||||
|
for _, test := range table {
|
||||||
|
suite.Run(string(test.get), func() {
|
||||||
|
assert.ElementsMatch(suite.T(), test.expect, Internal(test.get))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *ErrUnitSuite) TestIs() {
|
func (suite *ErrUnitSuite) TestIs() {
|
||||||
table := []struct {
|
table := []struct {
|
||||||
is errEnum
|
is errEnum
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user