-
Notifications
You must be signed in to change notification settings - Fork 1
/
store_test.go
98 lines (77 loc) · 1.83 KB
/
store_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
package slack
import (
"testing"
"github.com/nlopes/slack"
"github.com/stretchr/testify/assert"
)
func TestStore_users(t *testing.T) {
store := newMemoryStore(&slack.Client{})
info := slackUserInfo()
store.Load(info)
var (
user slack.User
ok bool
)
user, ok = store.UserByID("U1234")
assert.Equal(t, info.Users[0], user)
assert.True(t, ok)
_, ok = store.UserByID("U4321")
assert.False(t, ok)
user, ok = store.UserByName("Jean")
assert.Equal(t, info.Users[0], user)
assert.True(t, ok)
_, ok = store.UserByName("Joan")
assert.False(t, ok)
}
func TestStore_channels(t *testing.T) {
store := newMemoryStore(&slack.Client{})
info := slackUserInfo()
store.Load(info)
var (
channel slack.Channel
ok bool
)
channel, ok = store.ChannelByID("C1234")
assert.Equal(t, info.Channels[0], channel)
assert.True(t, ok)
_, ok = store.ChannelByID("C4321")
assert.False(t, ok)
channel, ok = store.ChannelByName("general")
assert.Equal(t, info.Channels[0], channel)
assert.True(t, ok)
_, ok = store.ChannelByName("random")
assert.False(t, ok)
}
func TestStore_ims(t *testing.T) {
store := newMemoryStore(&slack.Client{})
info := slackUserInfo()
store.Load(info)
var (
im slack.IM
ok bool
)
im, ok = store.IMByID("D1234")
assert.Equal(t, info.IMs[0], im)
assert.True(t, ok)
_, ok = store.IMByID("D4321")
assert.False(t, ok)
im, ok = store.IMByUserID("U1234")
assert.Equal(t, info.IMs[0], im)
assert.True(t, ok)
_, ok = store.IMByUserID("U4321")
assert.False(t, ok)
}
func slackUserInfo() *slack.Info {
user := slack.User{ID: "U1234", Name: "Jean"}
channel := slack.Channel{}
channel.ID = "C1234"
channel.Name = "general"
im := slack.IM{}
im.ID = "D1234"
im.User = "U1234"
return &slack.Info{
Users: []slack.User{user},
Channels: []slack.Channel{channel},
IMs: []slack.IM{im},
}
}