diff options
Diffstat (limited to 'plugins/jobs/oooold/dispatcher_test.go')
-rw-r--r-- | plugins/jobs/oooold/dispatcher_test.go | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/plugins/jobs/oooold/dispatcher_test.go b/plugins/jobs/oooold/dispatcher_test.go new file mode 100644 index 00000000..92f8c956 --- /dev/null +++ b/plugins/jobs/oooold/dispatcher_test.go @@ -0,0 +1,53 @@ +package oooold + +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) +} |