| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package xconsumer |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
"errors" |
| 9 |
"testing" |
| 10 |
|
| 11 |
"github.com/stretchr/testify/assert" |
| 12 |
"github.com/stretchr/testify/require" |
| 13 |
|
| 14 |
"go.opentelemetry.io/collector/consumer" |
| 15 |
"go.opentelemetry.io/collector/pdata/pprofile" |
| 16 |
) |
| 17 |
|
| 18 |
func TestDefaultProfiles(t *testing.T) { |
| 19 |
cp, err := NewProfiles(func(context.Context, pprofile.Profiles) error { return nil }) |
| 20 |
assert.NoError(t, err) |
| 21 |
assert.NoError(t, cp.ConsumeProfiles(context.Background(), pprofile.NewProfiles())) |
| 22 |
assert.Equal(t, consumer.Capabilities{MutatesData: false}, cp.Capabilities()) |
| 23 |
} |
| 24 |
|
| 25 |
func TestNilFuncProfiles(t *testing.T) { |
| 26 |
_, err := NewProfiles(nil) |
| 27 |
assert.Equal(t, errNilFunc, err) |
| 28 |
} |
| 29 |
|
| 30 |
func TestWithCapabilitiesProfiles(t *testing.T) { |
| 31 |
cp, err := NewProfiles( |
| 32 |
func(context.Context, pprofile.Profiles) error { return nil }, |
| 33 |
consumer.WithCapabilities(consumer.Capabilities{MutatesData: true})) |
| 34 |
assert.NoError(t, err) |
| 35 |
assert.NoError(t, cp.ConsumeProfiles(context.Background(), pprofile.NewProfiles())) |
| 36 |
assert.Equal(t, consumer.Capabilities{MutatesData: true}, cp.Capabilities()) |
| 37 |
} |
| 38 |
|
| 39 |
func TestConsumeProfiles(t *testing.T) { |
| 40 |
consumeCalled := false |
| 41 |
cp, err := NewProfiles(func(context.Context, pprofile.Profiles) error { consumeCalled = true; return nil }) |
| 42 |
assert.NoError(t, err) |
| 43 |
assert.NoError(t, cp.ConsumeProfiles(context.Background(), pprofile.NewProfiles())) |
| 44 |
assert.True(t, consumeCalled) |
| 45 |
} |
| 46 |
|
| 47 |
func TestConsumeProfiles_ReturnError(t *testing.T) { |
| 48 |
want := errors.New("my_error") |
| 49 |
cp, err := NewProfiles(func(context.Context, pprofile.Profiles) error { return want }) |
| 50 |
require.NoError(t, err) |
| 51 |
assert.Equal(t, want, cp.ConsumeProfiles(context.Background(), pprofile.NewProfiles())) |
| 52 |
} |