factory_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package dockerstatsreceiver
  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/consumer/consumertest"
  11. "go.opentelemetry.io/collector/receiver/receivertest"
  12. )
  13. func TestCreateDefaultConfig(t *testing.T) {
  14. factory := NewFactory()
  15. assert.Equal(t, "docker_stats", string(factory.Type()))
  16. config := factory.CreateDefaultConfig()
  17. assert.NotNil(t, config, "failed to create default config")
  18. assert.NoError(t, componenttest.CheckConfigStruct(config))
  19. }
  20. func TestCreateReceiver(t *testing.T) {
  21. factory := NewFactory()
  22. config := factory.CreateDefaultConfig()
  23. params := receivertest.NewNopCreateSettings()
  24. traceReceiver, err := factory.CreateTracesReceiver(context.Background(), params, config, consumertest.NewNop())
  25. assert.ErrorIs(t, err, component.ErrDataTypeIsNotSupported)
  26. assert.Nil(t, traceReceiver)
  27. metricReceiver, err := factory.CreateMetricsReceiver(context.Background(), params, config, consumertest.NewNop())
  28. assert.NoError(t, err, "Metric receiver creation failed")
  29. assert.NotNil(t, metricReceiver, "receiver creation failed")
  30. }