-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_test.go
75 lines (64 loc) · 2.27 KB
/
common_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
package restify_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/phogolabs/restify"
)
var _ = Describe("Content", func() {
Context("when the content-type is text/plain", func() {
It("parses the content successfully", func() {
content, err := restify.ParseContent("text/plain")
Expect(err).To(BeNil())
Expect(content.Type).To(Equal(restify.ContentTypePlainText))
})
})
Context("when the content-type is text/html", func() {
It("parses the content successfully", func() {
content, err := restify.ParseContent("text/html")
Expect(err).To(BeNil())
Expect(content.Type).To(Equal(restify.ContentTypeHTML))
})
})
Context("when the content-type is application/json", func() {
It("parses the content successfully", func() {
content, err := restify.ParseContent("application/json")
Expect(err).To(BeNil())
Expect(content.Type).To(Equal(restify.ContentTypeJSON))
})
})
Context("when the content-type is application/xml", func() {
It("parses the content successfully", func() {
content, err := restify.ParseContent("application/xml")
Expect(err).To(BeNil())
Expect(content.Type).To(Equal(restify.ContentTypeXML))
})
})
Context("when the content-type is application/x-www-form-urlencoded", func() {
It("parses the content successfully", func() {
content, err := restify.ParseContent("application/x-www-form-urlencoded")
Expect(err).To(BeNil())
Expect(content.Type).To(Equal(restify.ContentTypeForm))
})
})
Context("when the content-type is text/event-stream", func() {
It("parses the content successfully", func() {
content, err := restify.ParseContent("text/event-stream")
Expect(err).To(BeNil())
Expect(content.Type).To(Equal(restify.ContentTypeEventStream))
})
})
Context("when the content-type is empty", func() {
It("parses the content successfully", func() {
content, err := restify.ParseContent("")
Expect(err).To(BeNil())
Expect(content.Type).To(Equal(restify.ContentTypeUnknown))
})
})
Context("when the content-type has invalid parameter", func() {
It("parses the content successfully", func() {
content, err := restify.ParseContent("application/json;charset=")
Expect(err).To(MatchError("mime: invalid media parameter"))
Expect(content).To(BeNil())
})
})
})