| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package testcomponents |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/stretchr/testify/assert" |
| 11 |
"github.com/stretchr/testify/require" |
| 12 |
|
| 13 |
"go.opentelemetry.io/collector/component/componenttest" |
| 14 |
"go.opentelemetry.io/collector/pdata/plog" |
| 15 |
"go.opentelemetry.io/collector/pdata/pmetric" |
| 16 |
"go.opentelemetry.io/collector/pdata/pprofile" |
| 17 |
"go.opentelemetry.io/collector/pdata/ptrace" |
| 18 |
) |
| 19 |
|
| 20 |
func TestExampleExporter(t *testing.T) { |
| 21 |
exp := &ExampleExporter{} |
| 22 |
host := componenttest.NewNopHost() |
| 23 |
assert.False(t, exp.Started()) |
| 24 |
require.NoError(t, exp.Start(context.Background(), host)) |
| 25 |
assert.True(t, exp.Started()) |
| 26 |
|
| 27 |
assert.Empty(t, exp.Traces) |
| 28 |
require.NoError(t, exp.ConsumeTraces(context.Background(), ptrace.NewTraces())) |
| 29 |
assert.Len(t, exp.Traces, 1) |
| 30 |
|
| 31 |
assert.Empty(t, exp.Metrics) |
| 32 |
require.NoError(t, exp.ConsumeMetrics(context.Background(), pmetric.NewMetrics())) |
| 33 |
assert.Len(t, exp.Metrics, 1) |
| 34 |
|
| 35 |
assert.Empty(t, exp.Logs) |
| 36 |
require.NoError(t, exp.ConsumeLogs(context.Background(), plog.NewLogs())) |
| 37 |
assert.Len(t, exp.Logs, 1) |
| 38 |
|
| 39 |
assert.Empty(t, exp.Profiles) |
| 40 |
require.NoError(t, exp.ConsumeProfiles(context.Background(), pprofile.NewProfiles())) |
| 41 |
assert.Len(t, exp.Profiles, 1) |
| 42 |
|
| 43 |
assert.False(t, exp.Stopped()) |
| 44 |
require.NoError(t, exp.Shutdown(context.Background())) |
| 45 |
assert.True(t, exp.Stopped()) |
| 46 |
} |