Skip to content

Commit

Permalink
[rekognition] Add helper for invalid image encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
evalphobia committed Nov 16, 2017
1 parent a65c79b commit b3a3f55
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
14 changes: 14 additions & 0 deletions rekognition/error.go
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)
}
35 changes: 35 additions & 0 deletions rekognition/error_test.go
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")
}

0 comments on commit b3a3f55

Please sign in to comment.