Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/operator/config/integration_templates_test.go
4096 views
1
package config
2
3
import (
4
"testing"
5
6
gragent "github.com/grafana/agent/pkg/operator/apis/monitoring/v1alpha1"
7
"github.com/grafana/agent/pkg/util"
8
"github.com/grafana/agent/pkg/util/subset"
9
"github.com/stretchr/testify/require"
10
apiext_v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
11
"sigs.k8s.io/yaml"
12
)
13
14
func TestIntegration(t *testing.T) {
15
toJSON := func(in string) apiext_v1.JSON {
16
t.Helper()
17
out, err := yaml.YAMLToJSONStrict([]byte(in))
18
require.NoError(t, err)
19
return apiext_v1.JSON{Raw: out}
20
}
21
22
tt := []struct {
23
name string
24
input map[string]interface{}
25
expect string
26
}{
27
{
28
name: "configured integration",
29
input: map[string]interface{}{
30
"integration": &gragent.Integration{
31
Spec: gragent.IntegrationSpec{
32
Name: "mysqld_exporter",
33
Config: toJSON(`
34
data_source_names: root@(server-a:3306)/
35
`),
36
},
37
},
38
},
39
expect: util.Untab(`
40
data_source_names: root@(server-a:3306)/
41
`),
42
},
43
{
44
name: "integration no config",
45
input: map[string]interface{}{
46
"integration": &gragent.Integration{
47
Spec: gragent.IntegrationSpec{
48
Name: "mysqld_exporter",
49
},
50
},
51
},
52
expect: util.Untab(`{}`),
53
},
54
}
55
56
for _, tc := range tt {
57
t.Run(tc.name, func(t *testing.T) {
58
vm, err := createVM(testStore())
59
require.NoError(t, err)
60
61
actual, err := runSnippetTLA(t, vm, "./integrations.libsonnet", tc.input)
62
require.NoError(t, err)
63
require.NoError(t, subset.YAMLAssert([]byte(tc.expect), []byte(actual)), "incomplete yaml\n%s", actual)
64
})
65
}
66
}
67
68