-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathemit_test.go
More file actions
49 lines (43 loc) · 844 Bytes
/
emit_test.go
File metadata and controls
49 lines (43 loc) · 844 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"encoding/json"
"testing"
)
func TestEmitMessage(t *testing.T) {
tests := []struct {
Emit EmitMessage
Expected string
}{
{
EmitMessage{
Topic: "hello",
Payload: json.RawMessage(`{"foo": 42}`),
},
`{"emit":["hello",{"foo":42}]}`,
},
{
EmitMessage{
Topic: "ack",
},
`{"emit":["ack"]}`,
},
}
for _, tc := range tests {
out, err := tc.Emit.MarshalJSON()
if err != nil {
t.Errorf("failed to marshal: %q", err)
}
if got, want := string(out), tc.Expected; got != want {
t.Errorf("got:\n\t%s; want\n\t%s", got, want)
}
}
}
func TestMarshalEmit(t *testing.T) {
out, err := MarshalEmit("ready", nil)
if err != nil {
t.Fatal(err)
}
if got, want := string(out), `{"emit":["ready"]}`; got != want {
t.Errorf("got:\n\t%s; want\n\t%s", got, want)
}
}