// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 package prometheusreceiver import ( "context" "path/filepath" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/component/componenttest" "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/receiver/receivertest" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/internal/metadata" ) func TestCreateDefaultConfig(t *testing.T) { cfg := createDefaultConfig() assert.NotNil(t, cfg, "failed to create default config") assert.NoError(t, componenttest.CheckConfigStruct(cfg)) } func TestCreateReceiver(t *testing.T) { cfg := createDefaultConfig() // The default config does not provide scrape_config so we expect that metrics receiver // creation must also fail. creationSet := receivertest.NewNopCreateSettings() mReceiver, _ := createMetricsReceiver(context.Background(), creationSet, cfg, nil) assert.NotNil(t, mReceiver) assert.NotNil(t, mReceiver.(*pReceiver).cfg.PrometheusConfig.GlobalConfig) } func TestFactoryCanParseServiceDiscoveryConfigs(t *testing.T) { cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config_sd.yaml")) require.NoError(t, err) factory := NewFactory() cfg := factory.CreateDefaultConfig() sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) require.NoError(t, err) assert.NoError(t, component.UnmarshalConfig(sub, cfg)) }