-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathlabeler_test.go
87 lines (81 loc) · 1.63 KB
/
labeler_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
package helper
import (
"os"
"testing"
"github.com/observiq/stanza/entry"
"github.com/stretchr/testify/require"
)
func TestLabeler(t *testing.T) {
os.Setenv("TEST_METADATA_PLUGIN_ENV", "foo")
defer os.Unsetenv("TEST_METADATA_PLUGIN_ENV")
cases := []struct {
name string
config LabelerConfig
input *entry.Entry
expected *entry.Entry
}{
{
"AddLabelLiteral",
func() LabelerConfig {
cfg := NewLabelerConfig()
cfg.Labels = map[string]ExprStringConfig{
"label1": "value1",
}
return cfg
}(),
entry.New(),
func() *entry.Entry {
e := entry.New()
e.Labels = map[string]string{
"label1": "value1",
}
return e
}(),
},
{
"AddLabelExpr",
func() LabelerConfig {
cfg := NewLabelerConfig()
cfg.Labels = map[string]ExprStringConfig{
"label1": `EXPR("start" + "end")`,
}
return cfg
}(),
entry.New(),
func() *entry.Entry {
e := entry.New()
e.Labels = map[string]string{
"label1": "startend",
}
return e
}(),
},
{
"AddLabelEnv",
func() LabelerConfig {
cfg := NewLabelerConfig()
cfg.Labels = map[string]ExprStringConfig{
"label1": `EXPR(env("TEST_METADATA_PLUGIN_ENV"))`,
}
return cfg
}(),
entry.New(),
func() *entry.Entry {
e := entry.New()
e.Labels = map[string]string{
"label1": "foo",
}
return e
}(),
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
labeler, err := tc.config.Build()
require.NoError(t, err)
err = labeler.Label(tc.input)
require.NoError(t, err)
require.Equal(t, tc.expected.Labels, tc.input.Labels)
})
}
}