factory_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package purefareceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/purefareceiver"
  4. import (
  5. "context"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "go.opentelemetry.io/collector/component"
  9. "go.opentelemetry.io/collector/component/componenttest"
  10. "go.opentelemetry.io/collector/receiver/receivertest"
  11. )
  12. func TestTypeStr(t *testing.T) {
  13. factory := NewFactory()
  14. assert.Equal(t, "purefa", string(factory.Type()))
  15. }
  16. func TestCreateDefaultConfig(t *testing.T) {
  17. factory := NewFactory()
  18. cfg := factory.CreateDefaultConfig()
  19. assert.NotNil(t, cfg, "failed to create default config")
  20. assert.NoError(t, componenttest.CheckConfigStruct(cfg))
  21. }
  22. func TestCreateReceiver(t *testing.T) {
  23. factory := NewFactory()
  24. cfg := factory.CreateDefaultConfig()
  25. set := receivertest.NewNopCreateSettings()
  26. mReceiver, err := factory.CreateMetricsReceiver(context.Background(), set, cfg, nil)
  27. assert.NoError(t, err, "receiver creation failed")
  28. assert.NotNil(t, mReceiver, "receiver creation failed")
  29. tReceiver, err := factory.CreateTracesReceiver(context.Background(), set, cfg, nil)
  30. assert.Equal(t, err, component.ErrDataTypeIsNotSupported)
  31. assert.Nil(t, tReceiver)
  32. }