forked from pusher/pusher-http-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
82 lines (70 loc) · 2.19 KB
/
util_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
71
72
73
74
75
76
77
78
79
80
81
82
package pusher
import (
"testing"
"gopkg.in/stretchr/testify.v1/assert"
)
func TestParseUserAuthenticationRequestParamsNoSock(t *testing.T) {
params := "abc=hello"
_, result := parseUserAuthenticationRequestParams([]byte(params))
assert.Error(t, result)
assert.EqualError(t, result, "socket_id not found")
}
func TestInvalidUserAuthenticationParams(t *testing.T) {
params := "%$@£$${}$£%|$^%$^|"
_, result := parseUserAuthenticationRequestParams([]byte(params))
assert.Error(t, result)
}
func TestUserAuthenticationParamsSuccess(t *testing.T) {
params := "socket_id=123"
socket_id, result := parseUserAuthenticationRequestParams([]byte(params))
assert.Equal(t, socket_id, "123")
assert.NoError(t, result)
}
func TestParseChannelAuthorizationRequestParamsNoSock(t *testing.T) {
params := "channel_name=hello"
_, _, result := parseChannelAuthorizationRequestParams([]byte(params))
assert.Error(t, result)
assert.EqualError(t, result, "socket_id not found")
}
func TestParseChannelAuthorizationRequestParamsNoChan(t *testing.T) {
params := "socket_id=45.3"
_, _, result := parseChannelAuthorizationRequestParams([]byte(params))
assert.Error(t, result)
assert.EqualError(t, result, "channel_name not found")
}
func TestInvalidChannelAuthorizationParams(t *testing.T) {
params := "%$@£$${}$£%|$^%$^|"
_, _, result := parseChannelAuthorizationRequestParams([]byte(params))
assert.Error(t, result)
}
func TestValidateUserDataSuccess(t *testing.T) {
m := map[string]interface{}{
"id": "12345",
"email": "test@test.com",
}
err := validateUserData(m)
assert.NoError(t, err)
}
func TestValidateUserDataNoId(t *testing.T) {
m := map[string]interface{}{
"email": "test@test.com",
}
err := validateUserData(m)
assert.EqualError(t, err, "Missing id in user data")
}
func TestValidateUserDataIdIsNotString(t *testing.T) {
m := map[string]interface{}{
"id": 123,
"email": "test@test.com",
}
err := validateUserData(m)
assert.EqualError(t, err, "id field in user data is not a string")
}
func TestValidateUserDataInvalidId(t *testing.T) {
m := map[string]interface{}{
"id": "",
"email": "test@test.com",
}
err := validateUserData(m)
assert.EqualError(t, err, "Invalid id in user data: ''")
}