123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- // Copyright The OpenTelemetry Authors
- // SPDX-License-Identifier: Apache-2.0
- package prometheusexporter
- import (
- "context"
- "testing"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
- "go.opentelemetry.io/collector/component/componenttest"
- "go.opentelemetry.io/collector/exporter/exportertest"
- )
- func TestCreateDefaultConfig(t *testing.T) {
- cfg := createDefaultConfig()
- assert.NotNil(t, cfg, "failed to create default config")
- assert.NoError(t, componenttest.CheckConfigStruct(cfg))
- }
- func TestCreateMetricsExporter(t *testing.T) {
- cfg := createDefaultConfig()
- oCfg := cfg.(*Config)
- oCfg.Endpoint = ""
- exp, err := createMetricsExporter(
- context.Background(),
- exportertest.NewNopCreateSettings(),
- cfg)
- require.Equal(t, errBlankPrometheusAddress, err)
- require.Nil(t, exp)
- }
- func TestCreateMetricsExporterExportHelperError(t *testing.T) {
- cfg, ok := createDefaultConfig().(*Config)
- require.True(t, ok)
- cfg.Endpoint = "http://localhost:8889"
- set := exportertest.NewNopCreateSettings()
- set.Logger = nil
- // Should give us an exporterhelper.errNilLogger
- exp, err := createMetricsExporter(context.Background(), set, cfg)
- assert.Nil(t, exp)
- assert.Error(t, err)
- }
|