factory_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package mezmoexporter
  4. import (
  5. "context"
  6. "testing"
  7. "time"
  8. "github.com/stretchr/testify/assert"
  9. "go.opentelemetry.io/collector/component"
  10. "go.opentelemetry.io/collector/component/componenttest"
  11. "go.opentelemetry.io/collector/config/confighttp"
  12. "go.opentelemetry.io/collector/exporter/exporterhelper"
  13. "go.opentelemetry.io/collector/exporter/exportertest"
  14. "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/mezmoexporter/internal/metadata"
  15. )
  16. func TestType(t *testing.T) {
  17. factory := NewFactory()
  18. pType := factory.Type()
  19. assert.Equal(t, pType, component.Type(metadata.Type))
  20. }
  21. func TestCreateDefaultConfig(t *testing.T) {
  22. factory := NewFactory()
  23. cfg := factory.CreateDefaultConfig()
  24. assert.Equal(t, cfg, &Config{
  25. IngestURL: defaultIngestURL,
  26. IngestKey: "",
  27. HTTPClientSettings: confighttp.HTTPClientSettings{
  28. Timeout: 5 * time.Second,
  29. },
  30. RetrySettings: exporterhelper.NewDefaultRetrySettings(),
  31. QueueSettings: exporterhelper.NewDefaultQueueSettings(),
  32. })
  33. assert.NoError(t, componenttest.CheckConfigStruct(cfg))
  34. }
  35. func TestIngestUrlMustConform(t *testing.T) {
  36. cfg := createDefaultConfig().(*Config)
  37. cfg.IngestURL = "/collector"
  38. cfg.IngestKey = "1234-1234"
  39. assert.Error(t, cfg.Validate(), `"ingest_url" must contain a valid host`)
  40. }
  41. func TestCreateLogsExporter(t *testing.T) {
  42. cfg := createDefaultConfig().(*Config)
  43. cfg.IngestURL = "https://example.com:8088/otel/ingest/rest"
  44. cfg.IngestKey = "1234-1234"
  45. params := exportertest.NewNopCreateSettings()
  46. _, err := createLogsExporter(context.Background(), params, cfg)
  47. assert.NoError(t, err)
  48. }
  49. func TestCreateLogsExporterNoConfig(t *testing.T) {
  50. params := exportertest.NewNopCreateSettings()
  51. _, err := createLogsExporter(context.Background(), params, nil)
  52. assert.Error(t, err)
  53. }