forked from digitalocean/go-workers2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmsg_test.go
More file actions
33 lines (25 loc) · 767 Bytes
/
msg_test.go
File metadata and controls
33 lines (25 loc) · 767 Bytes
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
package workers
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewMsg(t *testing.T) {
//unmarshals json
msg, _ := NewMsg("{\"hello\":\"world\",\"foo\":3}")
hello, _ := msg.Get("hello").String()
foo, _ := msg.Get("foo").Int()
assert.Equal(t, "world", hello)
assert.Equal(t, 3, foo)
//returns an error if invalid json
msg, err := NewMsg("{\"hello:\"world\",\"foo\":3}")
assert.Nil(t, msg)
assert.NotNil(t, err)
}
func TestArgs(t *testing.T) {
//returns args key
msg, _ := NewMsg("{\"hello\":\"world\",\"args\":[\"foo\",\"bar\"]}")
assert.Equal(t, "[\"foo\",\"bar\"]", msg.Args().ToJson())
//returns empty array if args key doesn't exist
msg, _ = NewMsg("{\"hello\":\"world\"}")
assert.Equal(t, "[]", msg.Args().ToJson())
}