factory_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package lokireceiver
  4. import (
  5. "context"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "go.opentelemetry.io/collector/component/componenttest"
  9. "go.opentelemetry.io/collector/config/configgrpc"
  10. "go.opentelemetry.io/collector/config/confignet"
  11. "go.opentelemetry.io/collector/consumer/consumertest"
  12. "go.opentelemetry.io/collector/receiver/receivertest"
  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. assert.NoError(t, componenttest.CheckConfigStruct(cfg))
  19. }
  20. func TestCreateReceiver(t *testing.T) {
  21. factory := NewFactory()
  22. cfg := factory.CreateDefaultConfig()
  23. cfg.(*Config).Protocols.GRPC = &configgrpc.GRPCServerSettings{
  24. NetAddr: confignet.NetAddr{
  25. Endpoint: defaultGRPCBindEndpoint,
  26. Transport: "tcp",
  27. },
  28. }
  29. set := receivertest.NewNopCreateSettings()
  30. receiver, err := factory.CreateLogsReceiver(context.Background(), set, cfg, consumertest.NewNop())
  31. assert.NoError(t, err, "receiver creation failed")
  32. assert.NotNil(t, receiver, "receiver creation failed")
  33. }