generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
envelope_test.go
111 lines (92 loc) · 2.87 KB
/
envelope_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package marshalkit_test
import (
"time"
"github.com/dogmatiq/configkit"
. "github.com/dogmatiq/dogma/fixtures"
. "github.com/dogmatiq/interopspec/envelopespec"
. "github.com/dogmatiq/marshalkit"
"github.com/dogmatiq/marshalkit/fixtures"
. "github.com/jmalloc/gomegax"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("func MustMarshalMessageIntoEnvelope()", func() {
It("marshals the message into the envelope", func() {
var env Envelope
MustMarshalMessageIntoEnvelope(
fixtures.Marshaler,
MessageA1,
&env,
)
Expect(&env).To(EqualX(
&Envelope{
PortableName: fixtures.MessageAPortableName,
MediaType: fixtures.MessageA1Packet.MediaType,
Data: fixtures.MessageA1Packet.Data,
},
))
})
})
var _ = Describe("func UnmarshalMessageFromEnvelope()", func() {
It("unmarshals the message from the envelope", func() {
env := &Envelope{
PortableName: fixtures.MessageAPortableName,
MediaType: fixtures.MessageA1Packet.MediaType,
Data: fixtures.MessageA1Packet.Data,
}
m, err := UnmarshalMessageFromEnvelope(fixtures.Marshaler, env)
Expect(err).ShouldNot(HaveOccurred())
Expect(m).To(Equal(MessageA1))
})
})
var _ = Describe("func MustMarshalEnvelopeIdentity()", func() {
It("returns the protocol buffers identity", func() {
in := configkit.MustNewIdentity("<name>", "81ff36f1-96ba-401a-8291-024a725cf60c")
out := MustMarshalEnvelopeIdentity(in)
Expect(out).To(EqualX(
&Identity{
Name: "<name>",
Key: "81ff36f1-96ba-401a-8291-024a725cf60c",
},
))
})
})
var _ = Describe("func UnmarshalEnvelopeIdentity()", func() {
It("returns the configkit identity", func() {
in := &Identity{
Name: "<name>",
Key: "ed555abf-d9fd-45e5-9725-542e47a61667",
}
out, err := UnmarshalEnvelopeIdentity(in)
Expect(err).ShouldNot(HaveOccurred())
Expect(out).To(Equal(
configkit.MustNewIdentity("<name>", "ed555abf-d9fd-45e5-9725-542e47a61667"),
))
})
})
var _ = Describe("func MustMarshalEnvelopeTime()", func() {
It("returns the time formatted as per RFC-3339", func() {
in := time.Date(2001, 02, 03, 04, 05, 06, 0, time.UTC)
out := MustMarshalEnvelopeTime(in)
Expect(out).To(Equal("2001-02-03T04:05:06Z"))
})
It("returns an empty string if the time is the zero-value", func() {
var in time.Time
out := MustMarshalEnvelopeTime(in)
Expect(out).To(Equal(""))
})
})
var _ = Describe("func UnmarshalEnvelopeTime()", func() {
It("parses the time from RFC-3339 format", func() {
in := "2001-02-03T04:05:06Z"
out, err := UnmarshalEnvelopeTime(in)
Expect(err).ShouldNot(HaveOccurred())
expect := time.Date(2001, 02, 03, 04, 05, 06, 0, time.UTC)
Expect(out).To(BeTemporally("==", expect))
})
It("returns the zero-value if the input is empty", func() {
out, err := UnmarshalEnvelopeTime("")
Expect(err).ShouldNot(HaveOccurred())
Expect(out.IsZero()).To(BeTrue())
})
})