forked from michaelklishin/rabbit-hole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_test.go
95 lines (79 loc) · 2.46 KB
/
unit_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
package rabbithole
import (
"encoding/json"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Unit tests", func() {
Context("DeleteAfter marshalling", func() {
It("unmarshalls DeleteAfter when it is a number", func() {
var d DeleteAfter
s := []byte("1")
err := d.UnmarshalJSON(s)
Ω(err).ShouldNot(HaveOccurred())
Ω(d).Should(Equal(DeleteAfter("1")))
})
It("unmarshalls DeleteAfter when it is a quoted string", func() {
var d DeleteAfter
s := []byte("\"3\"")
err := d.UnmarshalJSON(s)
Ω(err).ShouldNot(HaveOccurred())
Ω(d).Should(Equal(DeleteAfter("3")))
})
})
Context("URISet marshalling", func() {
It("unmarshalls a single string", func() {
var us URISet
bs := []byte("\"amqp://127.0.0.1:5672\"")
err := us.UnmarshalJSON(bs)
Ω(err).ShouldNot(HaveOccurred())
Ω(us).Should(Equal(URISet([]string{"amqp://127.0.0.1:5672"})))
})
It("unmarshalls a list of strings", func() {
var us URISet
bs := []byte("[\"amqp://127.0.0.1:5672\", \"amqp://localhost:5672\"]")
err := us.UnmarshalJSON(bs)
Ω(err).ShouldNot(HaveOccurred())
Ω(us).Should(Equal(URISet([]string{"amqp://127.0.0.1:5672", "amqp://localhost:5672"})))
})
})
Context("Port marshalling", func() {
It("unmarshal Port when it is a number", func() {
var d Port
s := []byte("123")
err := d.UnmarshalJSON(s)
Ω(err).ShouldNot(HaveOccurred())
Ω(d).Should(Equal(Port(123)))
})
It("unmarshal Port when it is a quoted string", func() {
var d Port
s := []byte("\"456\"")
err := d.UnmarshalJSON(s)
Ω(err).ShouldNot(HaveOccurred())
Ω(d).Should(Equal(Port(456)))
})
It("unmarshal Port when it is a undefined", func() {
var d Port
s := []byte("\"undefined\"")
err := d.UnmarshalJSON(s)
Ω(err).ShouldNot(HaveOccurred())
Ω(d).Should(Equal(Port(0)))
})
})
Context("ConsumerDetails marshalling", func() {
It("unmarshal ConsumerDetails when channel_details is an empty array", func() {
var d ConsumerDetail
s := []byte("{\"channel_details\":[]}")
err := json.Unmarshal(s, &d)
Ω(err).ShouldNot(HaveOccurred())
Ω(d.ChannelDetails).Should(Equal(ChannelDetails{}))
})
It("unmarshal ConsumerDetails when channel_details is an object", func() {
var d ConsumerDetail
s := []byte("{\"channel_details\":{\"name\":\"foo\"}}")
err := json.Unmarshal(s, &d)
Ω(err).ShouldNot(HaveOccurred())
Ω(d.ChannelDetails).Should(Equal(ChannelDetails{Name: "foo"}))
})
})
})