generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type_test.go
51 lines (45 loc) · 1.09 KB
/
type_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
package marshalkit_test
import (
"reflect"
. "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 MustMarshalType()", func() {
It("marshals the type using the marshaler", func() {
n := MustMarshalType(
fixtures.Marshaler,
reflect.TypeOf(&AggregateRoot{}),
)
Expect(n).To(Equal("AggregateRoot"))
})
It("panics if the type is not registered", func() {
Expect(func() {
MustMarshalType(
fixtures.Marshaler,
reflect.TypeOf("<scalar value>"),
)
}).To(Panic())
})
})
var _ = Describe("func MustUnmarshalType()", func() {
It("unmarshals the type using the marshaler", func() {
rt := MustUnmarshalType(
fixtures.Marshaler,
"AggregateRoot",
)
Expect(rt).To(Equal(
reflect.TypeOf(&AggregateRoot{}),
))
})
It("returns an error if the type is not registered", func() {
Expect(func() {
MustUnmarshalType(
fixtures.Marshaler,
"Unsupported",
)
}).To(Panic())
})
})