-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[rekognition] Add helper for invalid image encoding
- Loading branch information
1 parent
a65c79b
commit b3a3f55
Showing
2 changed files
with
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package rekognition | ||
|
||
import "strings" | ||
|
||
var msgInvalidImageEncoding = `InvalidImageFormatException: Invalid image encoding` | ||
|
||
// IsErrorInvalidImageEncoding checks if gicen error is `Invalid image encoding`. | ||
func IsErrorInvalidImageEncoding(err error) (ok bool) { | ||
if err == nil { | ||
return false | ||
} | ||
|
||
return strings.Contains(err.Error(), msgInvalidImageEncoding) | ||
} |
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,35 @@ | ||
package rekognition | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsErrorInvalidImageEncoding(t *testing.T) { | ||
a := assert.New(t) | ||
|
||
tests := []struct { | ||
expected bool | ||
text string | ||
}{ | ||
{true, "InvalidImageFormatException: Invalid image encoding"}, | ||
{true, "status code: 400, request id: 00ff00ff-00ff-00ff-00ff-00ff00ff00ff, InvalidImageFormatException: Invalid image encoding"}, | ||
{true, "InvalidImageFormatException: Invalid image encoding, error"}, | ||
{true, "error, InvalidImageFormatException: Invalid image encoding, error"}, | ||
{false, "No errors"}, | ||
{false, "InvalidImageFormatException: Invalid image encodin"}, | ||
{false, "nvalidImageFormatException: Invalid image encoding"}, | ||
{false, ""}, | ||
} | ||
|
||
for _, tt := range tests { | ||
target := fmt.Sprintf("%+v", tt) | ||
|
||
err := errors.New(tt.text) | ||
a.Equal(tt.expected, IsErrorInvalidImageEncoding(err), target) | ||
} | ||
a.Equal(false, IsErrorInvalidImageEncoding(nil), "When error=nil") | ||
} |