This repository has been archived by the owner on Jan 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdispatcher_test.go
53 lines (43 loc) · 1.71 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
package jobs
import (
"github.com/stretchr/testify/assert"
"testing"
)
func Test_Map_All(t *testing.T) {
m := initDispatcher(map[string]*Options{"default": {Pipeline: "default"}})
assert.Equal(t, "default", m.match(&Job{Job: "default"}).Pipeline)
}
func Test_Map_Miss(t *testing.T) {
m := initDispatcher(map[string]*Options{"some.*": {Pipeline: "default"}})
assert.Nil(t, m.match(&Job{Job: "miss"}))
}
func Test_Map_Best(t *testing.T) {
m := initDispatcher(map[string]*Options{
"some.*": {Pipeline: "default"},
"some.other.*": {Pipeline: "other"},
})
assert.Equal(t, "default", m.match(&Job{Job: "some"}).Pipeline)
assert.Equal(t, "default", m.match(&Job{Job: "some.any"}).Pipeline)
assert.Equal(t, "other", m.match(&Job{Job: "some.other"}).Pipeline)
assert.Equal(t, "other", m.match(&Job{Job: "some.other.job"}).Pipeline)
}
func Test_Map_BestUpper(t *testing.T) {
m := initDispatcher(map[string]*Options{
"some.*": {Pipeline: "default"},
"some.Other.*": {Pipeline: "other"},
})
assert.Equal(t, "default", m.match(&Job{Job: "some"}).Pipeline)
assert.Equal(t, "default", m.match(&Job{Job: "some.any"}).Pipeline)
assert.Equal(t, "other", m.match(&Job{Job: "some.OTHER"}).Pipeline)
assert.Equal(t, "other", m.match(&Job{Job: "Some.other.job"}).Pipeline)
}
func Test_Map_BestReversed(t *testing.T) {
m := initDispatcher(map[string]*Options{
"some.*": {Pipeline: "default"},
"some.other.*": {Pipeline: "other"},
})
assert.Equal(t, "other", m.match(&Job{Job: "some.other.job"}).Pipeline)
assert.Equal(t, "other", m.match(&Job{Job: "some.other"}).Pipeline)
assert.Equal(t, "default", m.match(&Job{Job: "some.any"}).Pipeline)
assert.Equal(t, "default", m.match(&Job{Job: "some"}).Pipeline)
}