Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/common/relabel/relabel_test.go
4096 views
1
package relabel
2
3
import (
4
"testing"
5
6
"github.com/stretchr/testify/require"
7
8
"github.com/grafana/agent/pkg/river"
9
)
10
11
func TestParseConfig(t *testing.T) {
12
for _, tt := range []struct {
13
name string
14
cfg string
15
expectErr bool
16
}{
17
{
18
name: "valid keepequal config",
19
cfg: `
20
action = "keepequal"
21
target_label = "foo"
22
source_labels = ["bar"]
23
`,
24
},
25
{
26
name: "valid dropequal config",
27
cfg: `
28
action = "dropequal"
29
target_label = "foo"
30
source_labels = ["bar"]
31
`,
32
},
33
{
34
name: "missing dropequal target",
35
cfg: `
36
action = "dropequal"
37
source_labels = ["bar"]
38
`,
39
expectErr: true,
40
},
41
{
42
name: "missing dropequal source",
43
cfg: `
44
action = "dropequal"
45
target_label = "foo"
46
`,
47
expectErr: true,
48
},
49
{
50
name: "missing keepequal target",
51
cfg: `
52
action = "keepequal"
53
source_labels = ["bar"]
54
`,
55
expectErr: true,
56
},
57
{
58
name: "missing keepequal source",
59
cfg: `
60
action = "keepequal"
61
target_label = "foo"
62
`,
63
expectErr: true,
64
},
65
{
66
name: "unknown action",
67
cfg: `
68
action = "foo"
69
`,
70
expectErr: true,
71
},
72
} {
73
tt := tt
74
t.Run(tt.name, func(t *testing.T) {
75
t.Parallel()
76
var cfg Config
77
err := river.Unmarshal([]byte(tt.cfg), &cfg)
78
if tt.expectErr {
79
require.Error(t, err)
80
} else {
81
require.NoError(t, err)
82
}
83
})
84
}
85
}
86
87