forked from pusher/pusher-http-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_parsing_test.go
70 lines (61 loc) · 2.81 KB
/
response_parsing_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
package pusher
import (
"testing"
"gopkg.in/stretchr/testify.v1/assert"
)
func TestParsingTriggerChannelsList(t *testing.T) {
testJSON := []byte(`{"channels":{"presence-session-d41a439c438a100756f5-4bf35003e819bb138249-5cbTiUiPNGI":{},"presence-session-d41a439c438a100756f5-4bf35003e819bb138249-PbZ5E1pP8uF":{"user_count":1},"presence-session-d41a439c438a100756f5-4bf35003e819bb138249-oz6iqpSxMwG":{"user_count":2,"subscription_count":3}}}`)
expectedUserCount1 := 1
expectedUserCount2 := 2
expectedSubscriptionCount2 := 3
expected := &TriggerChannelsList{
Channels: map[string]TriggerChannelListItem{
"presence-session-d41a439c438a100756f5-4bf35003e819bb138249-5cbTiUiPNGI": TriggerChannelListItem{},
"presence-session-d41a439c438a100756f5-4bf35003e819bb138249-PbZ5E1pP8uF": TriggerChannelListItem{UserCount: &expectedUserCount1},
"presence-session-d41a439c438a100756f5-4bf35003e819bb138249-oz6iqpSxMwG": TriggerChannelListItem{UserCount: &expectedUserCount2, SubscriptionCount: &expectedSubscriptionCount2},
},
}
result, err := unmarshalledTriggerChannelsList(testJSON)
assert.Equal(t, expected, result)
assert.NoError(t, err)
}
func TestParsingChannelsList(t *testing.T) {
testJSON := []byte(`{"channels":{"presence-session-d41a439c438a100756f5-4bf35003e819bb138249-5cbTiUiPNGI":{"user_count":1},"presence-session-d41a439c438a100756f5-4bf35003e819bb138249-PbZ5E1pP8uF":{"user_count":1},"presence-session-d41a439c438a100756f5-4bf35003e819bb138249-oz6iqpSxMwG":{"user_count":1}}}`)
expected := &ChannelsList{
Channels: map[string]ChannelListItem{
"presence-session-d41a439c438a100756f5-4bf35003e819bb138249-5cbTiUiPNGI": ChannelListItem{UserCount: 1},
"presence-session-d41a439c438a100756f5-4bf35003e819bb138249-PbZ5E1pP8uF": ChannelListItem{UserCount: 1},
"presence-session-d41a439c438a100756f5-4bf35003e819bb138249-oz6iqpSxMwG": ChannelListItem{UserCount: 1},
},
}
result, err := unmarshalledChannelsList(testJSON)
assert.Equal(t, expected, result)
assert.NoError(t, err)
}
func TestParsingChannel(t *testing.T) {
testJSON := []byte(`{"user_count":1,"occupied":true,"subscription_count":1}`)
channelName := "test"
expected := &Channel{
Name: channelName,
Occupied: true,
UserCount: 1,
SubscriptionCount: 1,
}
result, err := unmarshalledChannel(testJSON, channelName)
assert.Equal(t, expected, result)
assert.NoError(t, err)
}
func TestParsingChannelUsers(t *testing.T) {
testJSON := []byte(`{"users":[{"id":"red"},{"id":"blue"}]}`)
expected := &Users{
List: []User{User{ID: "red"}, User{ID: "blue"}},
}
result, err := unmarshalledChannelUsers(testJSON)
assert.Equal(t, expected, result)
assert.NoError(t, err)
}
func TestParserError(t *testing.T) {
testJSON := []byte("[];;[[p{{}}{{{}[][][]@£$@")
_, err := unmarshalledChannelsList(testJSON)
assert.Error(t, err)
}