Path: blob/main/pkg/integrations/install/install_test.go
5304 views
package install12import (3"fmt"4"strings"5"testing"67v1 "github.com/grafana/agent/pkg/integrations"8v2 "github.com/grafana/agent/pkg/integrations/v2"9"github.com/stretchr/testify/require"10)1112// TestV1_Shims ensures that every v1 integration has a v2 counterpart.13func TestV1_Shims(t *testing.T) {14var (15v2Integrations = make(map[string]v2.Config) // Native v2 integrations16shimmedIntegrations = make(map[string]v1.Config) // Shimmed v1 integrations17)1819for _, v2Integration := range v2.Registered() {20uc, ok := v2Integration.(v2.UpgradedConfig)21if !ok {22v2Integrations[v2Integration.Name()] = v2Integration23continue24}2526v1Integration, _ := uc.LegacyConfig()27shimmedIntegrations[v1Integration.Name()] = v1Integration28}2930for _, v1Integration := range v1.RegisteredIntegrations() {31t.Run(v1Integration.Name(), func(t *testing.T) {32_, v2Native := v2Integrations[v1Integration.Name()]33_, shimmed := shimmedIntegrations[v1Integration.Name()]34require.True(t, shimmed || v2Native, "integration not shimmed to v2 or does not have a native counterpart")35})36}37}3839// TestV2_NoExporterSuffix ensures that v2 integrations do not have a name40// ending in _exporter. The test may be updated to exclude specific41// integrations from this requirement.42func TestV2_NoExporterSuffix(t *testing.T) {43exceptions := map[string]struct{}{44"node_exporter": {}, // node_exporter is an exception because its name is well-understood45}4647var invalidNames []string4849for _, v2Integration := range v2.Registered() {50name := v2Integration.Name()51if _, excluded := exceptions[name]; excluded {52continue53}5455if strings.HasSuffix(name, "_exporter") {56invalidNames = append(invalidNames, name)57}58}5960if len(invalidNames) > 0 {61require.FailNow(62t,63"Found v2 integrations named with unexpected _exporter suffix",64fmt.Sprintf("The following integrations must not end in _exporter: %s. Either drop the suffix or add them as an exception in this test.", strings.Join(invalidNames, ", ")),65)66}67}686970