factory_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package prometheusexporter
  4. import (
  5. "context"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/stretchr/testify/require"
  9. "go.opentelemetry.io/collector/component/componenttest"
  10. "go.opentelemetry.io/collector/exporter/exportertest"
  11. )
  12. func TestCreateDefaultConfig(t *testing.T) {
  13. cfg := createDefaultConfig()
  14. assert.NotNil(t, cfg, "failed to create default config")
  15. assert.NoError(t, componenttest.CheckConfigStruct(cfg))
  16. }
  17. func TestCreateMetricsExporter(t *testing.T) {
  18. cfg := createDefaultConfig()
  19. oCfg := cfg.(*Config)
  20. oCfg.Endpoint = ""
  21. exp, err := createMetricsExporter(
  22. context.Background(),
  23. exportertest.NewNopCreateSettings(),
  24. cfg)
  25. require.Equal(t, errBlankPrometheusAddress, err)
  26. require.Nil(t, exp)
  27. }
  28. func TestCreateMetricsExporterExportHelperError(t *testing.T) {
  29. cfg, ok := createDefaultConfig().(*Config)
  30. require.True(t, ok)
  31. cfg.Endpoint = "http://localhost:8889"
  32. set := exportertest.NewNopCreateSettings()
  33. set.Logger = nil
  34. // Should give us an exporterhelper.errNilLogger
  35. exp, err := createMetricsExporter(context.Background(), set, cfg)
  36. assert.Nil(t, exp)
  37. assert.Error(t, err)
  38. }