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
/
pipeline_test.go
89 lines (65 loc) · 2.36 KB
/
pipeline_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
88
89
package jobs
import (
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestPipeline_Map(t *testing.T) {
pipe := Pipeline{"options": map[string]interface{}{"ttl": 10}}
assert.Equal(t, 10, pipe.Map("options").Integer("ttl", 0))
assert.Equal(t, 0, pipe.Map("other").Integer("ttl", 0))
}
func TestPipeline_MapString(t *testing.T) {
pipe := Pipeline{"options": map[string]interface{}{"alias": "default"}}
assert.Equal(t, "default", pipe.Map("options").String("alias", ""))
assert.Equal(t, "", pipe.Map("other").String("alias", ""))
}
func TestPipeline_Bool(t *testing.T) {
pipe := Pipeline{"value": true}
assert.Equal(t, true, pipe.Bool("value", false))
assert.Equal(t, true, pipe.Bool("other", true))
}
func TestPipeline_String(t *testing.T) {
pipe := Pipeline{"value": "value"}
assert.Equal(t, "value", pipe.String("value", ""))
assert.Equal(t, "value", pipe.String("other", "value"))
}
func TestPipeline_Integer(t *testing.T) {
pipe := Pipeline{"value": 1}
assert.Equal(t, 1, pipe.Integer("value", 0))
assert.Equal(t, 1, pipe.Integer("other", 1))
}
func TestPipeline_Duration(t *testing.T) {
pipe := Pipeline{"value": 1}
assert.Equal(t, time.Second, pipe.Duration("value", 0))
assert.Equal(t, time.Second, pipe.Duration("other", time.Second))
}
func TestPipeline_Has(t *testing.T) {
pipe := Pipeline{"options": map[string]interface{}{"ttl": 10}}
assert.Equal(t, true, pipe.Has("options"))
assert.Equal(t, false, pipe.Has("other"))
}
func TestPipeline_FilterBroker(t *testing.T) {
pipes := Pipelines{
&Pipeline{"name": "first", "broker": "a"},
&Pipeline{"name": "second", "broker": "a"},
&Pipeline{"name": "third", "broker": "b"},
&Pipeline{"name": "forth", "broker": "b"},
}
filtered := pipes.Names("first", "third")
assert.True(t, len(filtered) == 2)
assert.Equal(t, "a", filtered[0].Broker())
assert.Equal(t, "b", filtered[1].Broker())
filtered = pipes.Names("first", "third").Reverse()
assert.True(t, len(filtered) == 2)
assert.Equal(t, "a", filtered[1].Broker())
assert.Equal(t, "b", filtered[0].Broker())
filtered = pipes.Broker("a")
assert.True(t, len(filtered) == 2)
assert.Equal(t, "first", filtered[0].Name())
assert.Equal(t, "second", filtered[1].Name())
filtered = pipes.Broker("a").Reverse()
assert.True(t, len(filtered) == 2)
assert.Equal(t, "first", filtered[1].Name())
assert.Equal(t, "second", filtered[0].Name())
}