summaryrefslogtreecommitdiff
path: root/plugins/jobs/oooold/dispatcher_test.go
blob: 92f8c956978f81c611716e46237b127715f606e8 (plain)
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 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)
}