Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/operator/reconciler_integrations_test.go
4096 views
1
package operator
2
3
import (
4
"testing"
5
6
gragent "github.com/grafana/agent/pkg/operator/apis/monitoring/v1alpha1"
7
"github.com/stretchr/testify/require"
8
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9
)
10
11
func Test_deploymentIntegrationSubset(t *testing.T) {
12
var (
13
nodeExporter = &gragent.Integration{
14
ObjectMeta: meta_v1.ObjectMeta{
15
Name: "node_exporter",
16
Namespace: "default",
17
},
18
Spec: gragent.IntegrationSpec{
19
Name: "node_exporter",
20
Type: gragent.IntegrationType{AllNodes: true},
21
},
22
}
23
process = &gragent.Integration{
24
ObjectMeta: meta_v1.ObjectMeta{
25
Name: "process",
26
Namespace: "default",
27
},
28
Spec: gragent.IntegrationSpec{
29
Name: "process",
30
Type: gragent.IntegrationType{AllNodes: true},
31
},
32
}
33
redis = &gragent.Integration{
34
ObjectMeta: meta_v1.ObjectMeta{
35
Name: "redis",
36
Namespace: "default",
37
},
38
Spec: gragent.IntegrationSpec{
39
Name: "redis",
40
Type: gragent.IntegrationType{AllNodes: false},
41
},
42
}
43
44
deploy = gragent.Deployment{
45
Integrations: []gragent.IntegrationsDeployment{
46
{Instance: nodeExporter},
47
{Instance: process},
48
{Instance: redis},
49
},
50
}
51
)
52
53
tt := []struct {
54
name string
55
allNodes bool
56
expect []*gragent.Integration
57
}{
58
{
59
name: "allNodes=false",
60
allNodes: false,
61
expect: []*gragent.Integration{redis},
62
},
63
{
64
name: "allNodes=true",
65
allNodes: true,
66
expect: []*gragent.Integration{nodeExporter, process},
67
},
68
}
69
70
for _, tc := range tt {
71
t.Run(tc.name, func(t *testing.T) {
72
res := deploymentIntegrationSubset(deploy, tc.allNodes)
73
74
integrations := make([]*gragent.Integration, 0, len(res.Integrations))
75
for _, i := range res.Integrations {
76
integrations = append(integrations, i.Instance)
77
}
78
79
require.Equal(t, tc.expect, integrations)
80
})
81
}
82
}
83
84