-
Notifications
You must be signed in to change notification settings - Fork 165
/
msg_test.go
38 lines (31 loc) · 957 Bytes
/
msg_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
package workers
import (
"github.com/customerio/gospec"
. "github.com/customerio/gospec"
)
func MsgSpec(c gospec.Context) {
c.Specify("NewMsg", func() {
c.Specify("unmarshals json", func() {
msg, _ := NewMsg("{\"hello\":\"world\",\"foo\":3}")
hello, _ := msg.Get("hello").String()
foo, _ := msg.Get("foo").Int()
c.Expect(hello, Equals, "world")
c.Expect(foo, Equals, 3)
})
c.Specify("returns an error if invalid json", func() {
msg, err := NewMsg("{\"hello:\"world\",\"foo\":3}")
c.Expect(msg, IsNil)
c.Expect(err, Not(IsNil))
})
})
c.Specify("Args", func() {
c.Specify("returns args key", func() {
msg, _ := NewMsg("{\"hello\":\"world\",\"args\":[\"foo\",\"bar\"]}")
c.Expect(msg.Args().ToJson(), Equals, "[\"foo\",\"bar\"]")
})
c.Specify("returns empty array if args key doesn't exist", func() {
msg, _ := NewMsg("{\"hello\":\"world\"}")
c.Expect(msg.Args().ToJson(), Equals, "[]")
})
})
}