factory_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package gitproviderreceiver
  4. import (
  5. "context"
  6. "fmt"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. "go.opentelemetry.io/collector/component"
  10. "go.opentelemetry.io/collector/component/componenttest"
  11. "go.opentelemetry.io/collector/consumer/consumertest"
  12. "go.opentelemetry.io/collector/receiver/receivertest"
  13. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/gitproviderreceiver/internal"
  14. )
  15. var creationSet = receivertest.NewNopCreateSettings()
  16. type mockConfig struct{}
  17. func TestCreateDefaultConfig(t *testing.T) {
  18. factory := NewFactory()
  19. cfg := factory.CreateDefaultConfig()
  20. assert.NotNil(t, cfg, "failed to create default config")
  21. assert.NoError(t, componenttest.CheckConfigStruct(cfg))
  22. }
  23. func TestCreateReceiver(t *testing.T) {
  24. factory := NewFactory()
  25. cfg := factory.CreateDefaultConfig()
  26. tReceiver, err := factory.CreateTracesReceiver(context.Background(), creationSet, cfg, consumertest.NewNop())
  27. assert.Equal(t, err, component.ErrDataTypeIsNotSupported)
  28. assert.Nil(t, tReceiver)
  29. mReceiver, err := factory.CreateMetricsReceiver(context.Background(), creationSet, cfg, consumertest.NewNop())
  30. assert.NoError(t, err)
  31. assert.NotNil(t, mReceiver)
  32. tLogs, err := factory.CreateLogsReceiver(context.Background(), creationSet, cfg, consumertest.NewNop())
  33. assert.Equal(t, err, component.ErrDataTypeIsNotSupported)
  34. assert.Nil(t, tLogs)
  35. }
  36. func TestCreateReceiver_ScraperKeyConfigError(t *testing.T) {
  37. const errorKey string = "error"
  38. factory := NewFactory()
  39. cfg := &Config{Scrapers: map[string]internal.Config{errorKey: &mockConfig{}}}
  40. _, err := factory.CreateMetricsReceiver(context.Background(), creationSet, cfg, consumertest.NewNop())
  41. assert.EqualError(t, err, fmt.Sprintf("failed to create scraper %q: factory not found for scraper %q", errorKey, errorKey))
  42. }