Path: blob/main/pkg/operator/reconciler_integrations_test.go
4096 views
package operator12import (3"testing"45gragent "github.com/grafana/agent/pkg/operator/apis/monitoring/v1alpha1"6"github.com/stretchr/testify/require"7meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"8)910func Test_deploymentIntegrationSubset(t *testing.T) {11var (12nodeExporter = &gragent.Integration{13ObjectMeta: meta_v1.ObjectMeta{14Name: "node_exporter",15Namespace: "default",16},17Spec: gragent.IntegrationSpec{18Name: "node_exporter",19Type: gragent.IntegrationType{AllNodes: true},20},21}22process = &gragent.Integration{23ObjectMeta: meta_v1.ObjectMeta{24Name: "process",25Namespace: "default",26},27Spec: gragent.IntegrationSpec{28Name: "process",29Type: gragent.IntegrationType{AllNodes: true},30},31}32redis = &gragent.Integration{33ObjectMeta: meta_v1.ObjectMeta{34Name: "redis",35Namespace: "default",36},37Spec: gragent.IntegrationSpec{38Name: "redis",39Type: gragent.IntegrationType{AllNodes: false},40},41}4243deploy = gragent.Deployment{44Integrations: []gragent.IntegrationsDeployment{45{Instance: nodeExporter},46{Instance: process},47{Instance: redis},48},49}50)5152tt := []struct {53name string54allNodes bool55expect []*gragent.Integration56}{57{58name: "allNodes=false",59allNodes: false,60expect: []*gragent.Integration{redis},61},62{63name: "allNodes=true",64allNodes: true,65expect: []*gragent.Integration{nodeExporter, process},66},67}6869for _, tc := range tt {70t.Run(tc.name, func(t *testing.T) {71res := deploymentIntegrationSubset(deploy, tc.allNodes)7273integrations := make([]*gragent.Integration, 0, len(res.Integrations))74for _, i := range res.Integrations {75integrations = append(integrations, i.Instance)76}7778require.Equal(t, tc.expect, integrations)79})80}81}828384