factory_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package googlecloudspannerreceiver
  4. import (
  5. "context"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/stretchr/testify/require"
  9. "go.opentelemetry.io/collector/component"
  10. "go.opentelemetry.io/collector/consumer/consumertest"
  11. "go.opentelemetry.io/collector/receiver/receivertest"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/googlecloudspannerreceiver/internal/metadata"
  13. )
  14. func TestCreateDefaultConfig(t *testing.T) {
  15. factory := NewFactory()
  16. cfg := factory.CreateDefaultConfig()
  17. assert.NotNil(t, cfg, "failed to create default config")
  18. }
  19. func TestType(t *testing.T) {
  20. factory := NewFactory()
  21. assert.Equal(t, component.Type(metadata.Type), factory.Type())
  22. }
  23. func TestCreateMetricsReceiver(t *testing.T) {
  24. factory := NewFactory()
  25. cfg := factory.CreateDefaultConfig()
  26. receiverConfig := cfg.(*Config)
  27. receiver, err := factory.CreateMetricsReceiver(
  28. context.Background(),
  29. receivertest.NewNopCreateSettings(),
  30. receiverConfig,
  31. consumertest.NewNop(),
  32. )
  33. assert.NoError(t, err)
  34. assert.NotNil(t, receiver, "failed to create metrics receiver")
  35. _, err = factory.CreateMetricsReceiver(context.Background(), receivertest.NewNopCreateSettings(), receiverConfig, nil)
  36. require.Error(t, err)
  37. }