forked from go-joe/slack-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options_test.go
87 lines (70 loc) · 2.12 KB
/
options_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
package slack
import (
"testing"
"github.com/go-joe/joe"
"github.com/slack-go/slack"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
)
func joeConf(t *testing.T) *joe.Config {
joeConf := new(joe.Config)
require.NoError(t, joe.WithLogger(zaptest.NewLogger(t)).Apply(joeConf))
return joeConf
}
func TestDefaultConfig(t *testing.T) {
conf, err := newConf("my-secret-token", joeConf(t), nil)
require.NoError(t, err)
assert.NotNil(t, conf.Logger)
assert.Equal(t, "full", conf.SendMsgParams.Parse)
assert.Equal(t, 1, conf.SendMsgParams.LinkNames)
}
func TestWithLogger(t *testing.T) {
logger := zaptest.NewLogger(t)
conf, err := newConf("my-secret-token", joeConf(t), []Option{
WithLogger(logger),
})
require.NoError(t, err)
assert.Equal(t, logger, conf.Logger)
}
func TestWithDebug(t *testing.T) {
conf, err := newConf("my-secret-token", joeConf(t), []Option{
WithDebug(true),
})
require.NoError(t, err)
assert.Equal(t, true, conf.Debug)
conf, err = newConf("my-secret-token", joeConf(t), []Option{
WithDebug(false),
})
require.NoError(t, err)
assert.Equal(t, false, conf.Debug)
}
func TestWithMessageParams(t *testing.T) {
conf, err := newConf("my-secret-token", joeConf(t), []Option{
WithMessageParams(slack.PostMessageParameters{
Parse: "none",
LinkNames: 0,
}),
})
require.NoError(t, err)
assert.NotNil(t, conf.Logger)
assert.Equal(t, "none", conf.SendMsgParams.Parse)
assert.Equal(t, 0, conf.SendMsgParams.LinkNames)
}
func TestWithLogUnknownMessageTypes(t *testing.T) {
conf, err := newConf("my-secret-token", joeConf(t), nil)
require.NoError(t, err)
assert.Equal(t, false, conf.LogUnknownMessageTypes, "LogUnknownMessageTypes should be disabled by default")
conf, err = newConf("my-secret-token", joeConf(t), []Option{
WithLogUnknownMessageTypes(),
})
require.NoError(t, err)
assert.Equal(t, true, conf.LogUnknownMessageTypes)
}
func TestWithListenPassive(t *testing.T) {
conf, err := newConf("my-secret-token", joeConf(t), []Option{
WithListenPassive(),
})
require.NoError(t, err)
assert.Equal(t, true, conf.ListenPassive)
}