|
| 1 | +// Copyright 2019, OpenTelemetry Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package signalfxreceiver |
| 16 | + |
| 17 | +import ( |
| 18 | + "context" |
| 19 | + "testing" |
| 20 | + |
| 21 | + "github.com/open-telemetry/opentelemetry-collector/config/configcheck" |
| 22 | + "github.com/open-telemetry/opentelemetry-collector/config/configerror" |
| 23 | + "github.com/open-telemetry/opentelemetry-collector/consumer" |
| 24 | + "github.com/open-telemetry/opentelemetry-collector/consumer/consumerdata" |
| 25 | + "github.com/stretchr/testify/assert" |
| 26 | + "go.uber.org/zap" |
| 27 | +) |
| 28 | + |
| 29 | +func TestCreateDefaultConfig(t *testing.T) { |
| 30 | + factory := &Factory{} |
| 31 | + cfg := factory.CreateDefaultConfig() |
| 32 | + assert.NotNil(t, cfg, "failed to create default config") |
| 33 | + assert.NoError(t, configcheck.ValidateConfig(cfg)) |
| 34 | +} |
| 35 | + |
| 36 | +type mockMetricsConsumer struct { |
| 37 | +} |
| 38 | + |
| 39 | +var _ (consumer.MetricsConsumer) = (*mockMetricsConsumer)(nil) |
| 40 | + |
| 41 | +func (m *mockMetricsConsumer) ConsumeMetricsData(ctx context.Context, md consumerdata.MetricsData) error { |
| 42 | + return nil |
| 43 | +} |
| 44 | + |
| 45 | +func TestCreateReceiver(t *testing.T) { |
| 46 | + factory := &Factory{} |
| 47 | + cfg := factory.CreateDefaultConfig().(*Config) |
| 48 | + cfg.Endpoint = "localhost:0" // Endpoint is required, not going to be used here. |
| 49 | + |
| 50 | + tReceiver, err := factory.CreateMetricsReceiver(zap.NewNop(), cfg, &mockMetricsConsumer{}) |
| 51 | + assert.Nil(t, err, "receiver creation failed") |
| 52 | + assert.NotNil(t, tReceiver, "receiver creation failed") |
| 53 | + |
| 54 | + tReceiver, err = factory.CreateMetricsReceiver(zap.NewNop(), cfg, &mockMetricsConsumer{}) |
| 55 | + assert.Nil(t, err, "receiver creation failed") |
| 56 | + assert.NotNil(t, tReceiver, "receiver creation failed") |
| 57 | + |
| 58 | + mReceiver, err := factory.CreateTraceReceiver(context.Background(), zap.NewNop(), cfg, nil) |
| 59 | + assert.Equal(t, err, configerror.ErrDataTypeIsNotSupported) |
| 60 | + assert.Nil(t, mReceiver) |
| 61 | +} |
0 commit comments