-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrtm_client_test.go
75 lines (63 loc) · 1.58 KB
/
rtm_client_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
package bearychat
import (
"errors"
"testing"
)
const (
testRTMToken = "foobar"
)
func TestNewRTMClient(t *testing.T) {
c, err := NewRTMClient(testRTMToken)
if err != nil {
t.Errorf("unexpected error: %+v", err)
}
if c.Token != testRTMToken {
t.Errorf("unexpected token: %s", c.Token)
}
if c.APIBase != DEFAULT_RTM_API_BASE {
t.Errorf("should use default rtm api base: %s", c.APIBase)
}
if c.CurrentTeam == nil {
t.Errorf("should create current team service")
}
if c.User == nil {
t.Errorf("should create user service")
}
}
func TestNewRTMClient_error(t *testing.T) {
newError := errors.New("error")
_, err := NewRTMClient(testRTMToken, func(c *RTMClient) error {
return newError
})
if err != newError {
t.Errorf("should return error: %+v", err)
}
}
func TestNewRTMClient_WithRTMAPIBase(t *testing.T) {
apiBase := "http://foo.bar"
c, err := NewRTMClient(testRTMToken, WithRTMAPIBase(apiBase))
if err != nil {
t.Errorf("unexpected error: %+v", err)
}
if c.APIBase != apiBase {
t.Errorf("should set api base: %s", c.APIBase)
}
}
func TestNewRTMClient_WithRTMHTTPClient(t *testing.T) {
c, err := NewRTMClient(testRTMToken, WithRTMHTTPClient(nil))
if err != nil {
t.Errorf("unexpected error: %+v", err)
}
if c.httpClient != nil {
t.Errorf("should set http client: %+v", c.httpClient)
}
}
func testAddTokenToResourceUri(t *testing.T) {
u, err := addTokenToResourceUri("http://foobar.com", "foobar")
if err != nil {
t.Errorf("unexpected error: %+v", err)
}
if u != "http://foobar.com?token=foobar" {
t.Errorf("unexpected resource uri: %s", u)
}
}