forked from mxmCherry/openrtb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraw_json_test.go
57 lines (43 loc) · 1.24 KB
/
raw_json_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package openrtb_test
import (
"encoding/json"
"github.com/mxmCherry/openrtb"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("RawJSON", func() {
var _ json.Marshaler = (openrtb.RawJSON)(nil)
var _ json.Unmarshaler = (*openrtb.RawJSON)(nil)
It("should encode JSON", func() {
subject := openrtb.RawJSON(`true`)
actual, err := subject.MarshalJSON()
Expect(err).NotTo(HaveOccurred())
Expect(actual).To(Equal([]byte(`true`)))
})
It("should decode JSON", func() {
subject := openrtb.RawJSON(nil)
err := subject.UnmarshalJSON([]byte(`true`))
Expect(err).NotTo(HaveOccurred())
Expect(subject).To(Equal(openrtb.RawJSON(`true`)))
})
It("should decode JSON when embedded into struct", func() {
wrapper := struct {
Raw openrtb.RawJSON `json:"raw"`
}{
Raw: nil,
}
err := json.Unmarshal([]byte(`{"raw":true}`), &wrapper)
Expect(err).NotTo(HaveOccurred())
Expect(wrapper.Raw).To(Equal(openrtb.RawJSON(`true`)))
})
It("should encode JSON when embedded into struct", func() {
wrapper := struct {
Raw openrtb.RawJSON `json:"raw"`
}{
Raw: openrtb.RawJSON(`true`),
}
actual, err := json.Marshal(wrapper)
Expect(err).NotTo(HaveOccurred())
Expect(actual).To(MatchJSON(`{"raw":true}`))
})
})