1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- // Copyright The OpenTelemetry Authors
- // SPDX-License-Identifier: Apache-2.0
- package statsdreceiver
- import (
- "context"
- "testing"
- "github.com/stretchr/testify/assert"
- "go.opentelemetry.io/collector/component"
- "go.opentelemetry.io/collector/component/componenttest"
- "go.opentelemetry.io/collector/consumer/consumertest"
- "go.opentelemetry.io/collector/receiver/receivertest"
- )
- type testHost struct {
- component.Host
- t *testing.T
- }
- // ReportFatalError causes the test to be run to fail.
- func (h *testHost) ReportFatalError(err error) {
- h.t.Fatalf("receiver reported a fatal error: %v", err)
- }
- var _ component.Host = (*testHost)(nil)
- func TestCreateDefaultConfig(t *testing.T) {
- factory := NewFactory()
- cfg := factory.CreateDefaultConfig()
- assert.NotNil(t, cfg, "failed to create default config")
- assert.NoError(t, componenttest.CheckConfigStruct(cfg))
- }
- func TestCreateReceiver(t *testing.T) {
- cfg := createDefaultConfig().(*Config)
- cfg.NetAddr.Endpoint = "localhost:0" // Endpoint is required, not going to be used here.
- params := receivertest.NewNopCreateSettings()
- tReceiver, err := createMetricsReceiver(context.Background(), params, cfg, consumertest.NewNop())
- assert.NoError(t, err)
- assert.NotNil(t, tReceiver, "receiver creation failed")
- }
- func TestCreateMetricsReceiverWithNilConsumer(t *testing.T) {
- receiver, err := createMetricsReceiver(
- context.Background(),
- receivertest.NewNopCreateSettings(),
- createDefaultConfig(),
- nil,
- )
- assert.Error(t, err, "nil consumer")
- assert.Nil(t, receiver)
- }
|