generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet_test.go
59 lines (50 loc) · 1.27 KB
/
packet_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
package marshalkit_test
import (
. "github.com/dogmatiq/marshalkit"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("type Packet", func() {
Describe("func NewPacket()", func() {
It("encodes the portable type name in the media-type", func() {
p := NewPacket(
"text/plain",
"SomeType",
[]byte("data"),
)
Expect(p).To(Equal(
Packet{
MediaType: "text/plain; type=SomeType",
Data: []byte("data"),
},
))
})
})
Describe("func ParseMediaType()", func() {
It("returns the mime-type and portable type name", func() {
p := NewPacket(
"text/plain",
"SomeType",
[]byte("data"),
)
mt, n, err := p.ParseMediaType()
Expect(err).ShouldNot(HaveOccurred())
Expect(mt).To(Equal("text/plain"))
Expect(n).To(Equal("SomeType"))
})
It("returns an error if the media-type has no type parameter", func() {
p := Packet{
MediaType: "text/plain",
}
_, _, err := p.ParseMediaType()
Expect(err).To(MatchError("the media-type 'text/plain' does not specify a 'type' parameter"))
})
It("returns an error if the media-type is malformed", func() {
p := Packet{
MediaType: "<malformed>",
}
_, _, err := p.ParseMediaType()
Expect(err).Should(HaveOccurred())
})
})
})