-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/DawoudMahmud/terraform-pr…
- Loading branch information
Showing
53 changed files
with
1,218 additions
and
210 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
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 |
---|---|---|
@@ -1,13 +1,22 @@ | ||
package client | ||
|
||
import "errors" | ||
|
||
type NotFound struct { | ||
s string | ||
} | ||
|
||
func NewNotFound(text string) error { | ||
return &NotFound{text} | ||
return NotFound{text} | ||
} | ||
|
||
func (e *NotFound) Error() string { | ||
func (e NotFound) Error() string { | ||
return e.s | ||
} | ||
|
||
func IsNotFoundError(err error) bool { | ||
var e NotFound | ||
var ePtr *NotFound | ||
|
||
return errors.As(err, &e) || errors.As(err, &ePtr) | ||
} |
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,54 @@ | ||
package client | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIsNotFoundError(t *testing.T) { | ||
|
||
testCases := []struct { | ||
name string | ||
err error | ||
expected bool | ||
}{ | ||
{ | ||
name: "nil error", | ||
expected: false, | ||
}, | ||
{ | ||
name: "created via NewNotFoundError()", | ||
err: NewNotFound("not found"), | ||
expected: true, | ||
}, | ||
{ | ||
name: "created directly via struct initialization", | ||
err: NotFound{}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "chained with other errors", | ||
err: fmt.Errorf("cannot load object info: %w", NewNotFound("no such object")), | ||
expected: true, | ||
}, | ||
{ | ||
name: "chain of non-matching errors", | ||
err: fmt.Errorf("cannot load object info: %w", errors.New("no such object")), | ||
expected: false, | ||
}, | ||
{ | ||
name: "generic error", | ||
err: errors.New("no such object"), | ||
expected: false, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
result := IsNotFoundError(tc.err) | ||
require.Equal(t, tc.expected, 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
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
Oops, something went wrong.