-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchannel_identifier_test.go
51 lines (43 loc) · 970 Bytes
/
channel_identifier_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
package actioncable
import (
"encoding/json"
"testing"
)
func TestNewChannelIdentifier(t *testing.T) {
id := NewChannelIdentifier("ChatRoom", nil)
if id.channelName != "ChatRoom" {
t.Fatalf("bad: %s", id.channelName)
}
}
func TestMarshalJSON(t *testing.T) {
// no channel params
id := NewChannelIdentifier("ChatRoom", nil)
b, err := json.Marshal(id)
if err != nil {
t.Fatalf("bad: %s", err)
}
actual := string(b)
expected := `{"channel":"ChatRoom"}`
if expected != actual {
t.Fatalf("bad: %s", actual)
}
// using channel params (1)
id = NewChannelIdentifier("ChatRoom", map[string]interface{}{
"Room": "BestRoom",
})
b, err = json.Marshal(id)
if err != nil {
t.Fatalf("bad: %s", err)
}
data := map[string]interface{}{}
err = json.Unmarshal(b, &data)
if err != nil {
t.Fatalf("bad: %s", err)
}
if data["channel"] != "ChatRoom" {
t.Fatalf("bad: %s", data)
}
if data["Room"] != "BestRoom" {
t.Fatalf("bad: %s", data)
}
}