generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
value_test.go
60 lines (55 loc) · 1.32 KB
/
value_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
58
59
60
package marshalkit_test
import (
. "github.com/dogmatiq/dogma/fixtures"
. "github.com/dogmatiq/marshalkit"
"github.com/dogmatiq/marshalkit/fixtures" // can't dot-import due to conflicts
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("func MustMarshal()", func() {
It("marshals the value using the marshaler", func() {
p := MustMarshal(
fixtures.Marshaler,
&ProcessRoot{
Value: "<value>",
},
)
Expect(p.MediaType).To(Equal("application/json; type=ProcessRoot"))
Expect(p.Data).To(Equal([]byte(`{"Value":"\u003cvalue\u003e"}`)))
})
It("panics if the type is not registered", func() {
Expect(func() {
MustMarshal(
fixtures.Marshaler,
"<scalar value>",
)
}).To(Panic())
})
})
var _ = Describe("func MustUnmarshal()", func() {
It("unmarshals the value using the marshaler", func() {
v := MustUnmarshal(
fixtures.Marshaler,
Packet{
"application/json; type=ProcessRoot",
[]byte(`{"Value":"\u003cvalue\u003e"}`),
},
)
Expect(v).To(Equal(
&ProcessRoot{
Value: "<value>",
},
))
})
It("returns an error if the type is not registered", func() {
Expect(func() {
MustUnmarshal(
fixtures.Marshaler,
Packet{
"application/json; type=Unsupported",
[]byte(`{"Value":"\u003cvalue\u003e"}`),
},
)
}).To(Panic())
})
})