-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecode_attributes_test.go
32 lines (28 loc) · 952 Bytes
/
decode_attributes_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
package jsonapi_test
import (
"github.com/ryanmoran/jsonapi"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("DecodeAttributes", func() {
Describe("UnmarshalJSON", func() {
Context("failure cases", func() {
Context("when the JSON cannot be unmarshaled", func() {
It("returns an error", func() {
var payload AttributesPayload
attributes := jsonapi.NewDecodeAttributes(&payload)
err := attributes.UnmarshalJSON([]byte("%%%"))
Expect(err).To(MatchError(ContainSubstring("invalid character '%'")))
})
})
Context("when the attribute field types do not match", func() {
It("returns an error", func() {
var payload AttributesPayload
attributes := jsonapi.NewDecodeAttributes(&payload)
err := attributes.UnmarshalJSON([]byte(`{ "some-attr": 123 }`))
Expect(err).To(MatchError("json: cannot unmarshal number into Go value of type string"))
})
})
})
})
})