-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdispatcher_test.go
68 lines (57 loc) · 1.69 KB
/
dispatcher_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
package common
import (
"os"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSimpleDispatcher(t *testing.T) {
os.Setenv("AGGREGATE_CHANNEL_ID", "CIDFOOBAR")
t.Cleanup(func() { os.Unsetenv("AGGREGATE_CHANNEL_ID") })
d, err := NewDispatcher()
assert.Nil(t, err)
assert.Equal(t, "common.simpleDispatcher", reflect.TypeOf(d).String())
assert.Equal(t, "CIDFOOBAR", d.Dispatch("hoge"))
assert.Equal(t, "CIDFOOBAR", d.Dispatch("poyo"))
}
func TestMapDispatcher(t *testing.T) {
json := `[{"prefix": "times_",
"cid": "CIDTIMES"
},{
"suffix": "_zatsu",
"cid": "CIDZATSU"
},{
"suffix": "_foobar",
"cid": "CIDFOOBAR"
}]`
os.Setenv("DISPATCH_CHANNEL", json)
t.Cleanup(func() { os.Unsetenv("DISPATCH_CHANNEL") })
d, err := NewDispatcher()
assert.Nil(t, err)
assert.Equal(t, "*common.mappedDispatcher", reflect.TypeOf(d).String())
assert.Equal(t, "", d.Dispatch("hoge"))
assert.Equal(t, "CIDTIMES", d.Dispatch("times_poyo"))
assert.Equal(t, "CIDTIMES", d.Dispatch("times_hoge"))
assert.Equal(t, "CIDTIMES", d.Dispatch("times_hoge_zatsu"))
assert.Equal(t, "CIDZATSU", d.Dispatch("timez_hoge_zatsu"))
assert.Equal(t, "", d.Dispatch("poyo"))
assert.Equal(t, "CIDFOOBAR", d.Dispatch("poyo_foobar"))
}
func TestNewMapDispatcher(t *testing.T) {
json := `[{"prefix": "times_",
"cid": "CIDTIMES"
},{
"suffix": "_zatsu",
"cid": "CIDZATSU"
},{
"suffix": "_foobar",
"cid": "CIDFOOBAR"
}]`
os.Setenv("DISPATCH_CHANNEL", json)
t.Cleanup(func() { os.Unsetenv("DISPATCH_CHANNEL") })
v, err := newMapDispatcher()
assert.Nil(t, err)
assert.Equal(t, "CIDTIMES", v.prefixMap["times_"])
assert.Equal(t, "CIDZATSU", v.suffixMap["_zatsu"])
assert.Equal(t, "CIDFOOBAR", v.suffixMap["_foobar"])
}