-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathusers_test.go
126 lines (97 loc) · 2.86 KB
/
users_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package slack_test
import (
"context"
"net/http/httptest"
"testing"
"time"
"github.com/lestrrat-go/slack"
"github.com/stretchr/testify/assert"
)
func TestUsersList_Info_Presence(t *testing.T) {
if !requireSlackToken(t) {
return
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c := slack.New(slackToken)
list, err := c.Users().List().Do(ctx)
if !assert.NoError(t, err, "Users.List failed") {
return
}
if !assert.True(t, len(list) > 1, "There should be more than 1 users (slackbot and more)") {
return
}
timeout := time.NewTimer(5 * time.Second)
defer timeout.Stop()
for i, user := range list {
select {
case <-timeout.C:
assert.True(t, i > 0, "processed at last 1 user")
return
default:
}
fromInfo, err := c.Users().Info(user.ID).Do(ctx)
if !assert.NoError(t, err, "Users.Info failed") {
return
}
if !assert.Equal(t, user.ID, fromInfo.ID, "User.Info should produce identical users") {
return
}
presence, err := c.Users().GetPresence(user.ID).Do(ctx)
if !assert.NoError(t, err, "Users.GetPresence failed") {
return
}
t.Logf("%#v", presence)
}
}
func TestUsersListUnit(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s := httptest.NewServer(newDummyServer())
defer s.Close()
c := newSlackWithDummy(s)
_, err := c.Users().List().Do(ctx)
assert.NoError(t, err, "Users.List should succeed")
_, err = c.Users().List().Limit(100).IncludeLocale(true).Do(ctx)
assert.NoError(t, err, "Users.List should succeed")
}
func TestUsersDeletePhotoUnit(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s := httptest.NewServer(newDummyServer())
defer s.Close()
c := newSlackWithDummy(s)
err := c.Users().DeletePhoto().Do(ctx)
assert.NoError(t, err, "Users.DeletePhoto should succeed")
}
func TestUsersGetPresenceUnit(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s := httptest.NewServer(newDummyServer())
defer s.Close()
c := newSlackWithDummy(s)
_, err := c.Users().GetPresence("foo").Do(ctx)
if !assert.NoError(t, err, "Users.GetPresence should succeed") {
return
}
}
func TestUsersIdentityUnit(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s := httptest.NewServer(newDummyServer())
defer s.Close()
c := newSlackWithDummy(s)
_, _, err := c.Users().Identity().Do(ctx)
assert.NoError(t, err, "Users.Identity should succeed")
}
func TestUsersInfoUnit(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
s := httptest.NewServer(newDummyServer())
defer s.Close()
c := newSlackWithDummy(s)
_, err := c.Users().Info("foo").Do(ctx)
assert.NoError(t, err, "Users.Info should succeed")
_, err = c.Users().Info("foo").IncludeLocale(true).Do(ctx)
assert.NoError(t, err, "Users.Info should succeed")
}