forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs_test.go
60 lines (53 loc) · 1.97 KB
/
funcs_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
package slacktest
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGenerateDefaultRTMInfo(t *testing.T) {
wsurl := "ws://127.0.0.1:5555/ws"
ctx := context.TODO()
info := generateRTMInfo(ctx, wsurl)
assert.Equal(t, wsurl, info.URL)
assert.True(t, info.Ok)
assert.Equal(t, defaultBotID, info.User.ID)
assert.Equal(t, defaultBotName, info.User.Name)
assert.Equal(t, defaultTeamID, info.Team.ID)
assert.Equal(t, defaultTeamName, info.Team.Name)
assert.Equal(t, defaultTeamDomain, info.Team.Domain)
}
func TestCustomDefaultRTMInfo(t *testing.T) {
wsurl := "ws://127.0.0.1:5555/ws"
ctx := context.TODO()
ctx = context.WithValue(ctx, ServerBotIDContextKey, "U1234567890")
ctx = context.WithValue(ctx, ServerBotNameContextKey, "SomeTestBotThing")
info := generateRTMInfo(ctx, wsurl)
assert.Equal(t, wsurl, info.URL)
assert.True(t, info.Ok)
assert.Equal(t, "U1234567890", info.User.ID)
assert.Equal(t, "SomeTestBotThing", info.User.Name)
assert.Equal(t, defaultTeamID, info.Team.ID)
assert.Equal(t, defaultTeamName, info.Team.Name)
assert.Equal(t, defaultTeamDomain, info.Team.Domain)
}
func TestGetHubMissingServerAddr(t *testing.T) {
mc, err := getHubForServer("")
assert.Nil(t, mc.seen, "seen should be nil")
assert.Nil(t, mc.sent, "sent should be nil")
assert.Nil(t, mc.posted, "posted should be nil")
assert.Error(t, err, "should return an error")
assert.EqualError(t, err, ErrPassedEmptyServerAddr.Error())
}
func TestGetHubNoQueuesForServer(t *testing.T) {
mc, err := getHubForServer("foo")
assert.Nil(t, mc.seen, "seen should be nil")
assert.Nil(t, mc.sent, "sent should be nil")
assert.Nil(t, mc.posted, "posted should be nil")
assert.Error(t, err, "should return an error")
assert.EqualError(t, err, ErrNoQueuesRegisteredForServer.Error())
}
func TestUnableToAddToHub(t *testing.T) {
err := addServerToHub(&Server{}, &messageChannels{})
assert.Error(t, err, "should return and error")
assert.EqualError(t, err, ErrEmptyServerToHub.Error())
}