forked from dugancathal/dynago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors_test.go
36 lines (31 loc) · 1.07 KB
/
errors_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package dynago
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestErrorStringRepresentation(t *testing.T) {
e := Error{
Type: ErrorThrottling,
Exception: "ThrottlingException",
AmazonRawType: "dynamodb#ThrottlingBlah",
Message: "FooBar",
}
assert.Equal(t, "dynago.Error(ErrorThrottling): ThrottlingException: FooBar", e.Error())
e.Exception = ""
assert.Equal(t, "dynago.Error(ErrorThrottling): dynamodb#ThrottlingBlah: FooBar", e.Error())
}
func TestErrorBuildError(t *testing.T) {
assert := assert.New(t)
input := `{"__type": "dynamodb#MissingAction", "message": "The FooBar happened."}`
req, _ := http.NewRequest("POST", "http://fake/fake", nil)
resp := &http.Response{}
err := buildError(req, nil, resp, []byte(input))
e := err.(*Error)
assert.Equal(ErrorInvalidParameter, e.Type)
assert.Equal([]byte(input), e.ResponseBody)
assert.Equal("MissingAction", e.Exception)
e = buildError(req, nil, resp, []byte("\n")).(*Error)
assert.Equal(ErrorUnknown, e.Type)
assert.Equal("unexpected end of JSON input", e.Message)
}