| 1 |
// Code generated by mdatagen. DO NOT EDIT. |
| 2 |
|
| 3 |
package otlpreceiver |
| 4 |
|
| 5 |
import ( |
| 6 |
"context" |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/require" |
| 10 |
|
| 11 |
"go.opentelemetry.io/collector/component" |
| 12 |
"go.opentelemetry.io/collector/component/componenttest" |
| 13 |
"go.opentelemetry.io/collector/confmap/confmaptest" |
| 14 |
"go.opentelemetry.io/collector/consumer/consumertest" |
| 15 |
"go.opentelemetry.io/collector/receiver" |
| 16 |
"go.opentelemetry.io/collector/receiver/receivertest" |
| 17 |
) |
| 18 |
|
| 19 |
var typ = component.MustNewType("otlp") |
| 20 |
|
| 21 |
func TestComponentFactoryType(t *testing.T) { |
| 22 |
require.Equal(t, typ, NewFactory().Type()) |
| 23 |
} |
| 24 |
|
| 25 |
func TestComponentConfigStruct(t *testing.T) { |
| 26 |
require.NoError(t, componenttest.CheckConfigStruct(NewFactory().CreateDefaultConfig())) |
| 27 |
} |
| 28 |
|
| 29 |
func TestComponentLifecycle(t *testing.T) { |
| 30 |
factory := NewFactory() |
| 31 |
|
| 32 |
tests := []struct { |
| 33 |
createFn func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) |
| 34 |
name string |
| 35 |
}{ |
| 36 |
|
| 37 |
{ |
| 38 |
name: "logs", |
| 39 |
createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { |
| 40 |
return factory.CreateLogs(ctx, set, cfg, consumertest.NewNop()) |
| 41 |
}, |
| 42 |
}, |
| 43 |
|
| 44 |
{ |
| 45 |
name: "metrics", |
| 46 |
createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { |
| 47 |
return factory.CreateMetrics(ctx, set, cfg, consumertest.NewNop()) |
| 48 |
}, |
| 49 |
}, |
| 50 |
|
| 51 |
{ |
| 52 |
name: "traces", |
| 53 |
createFn: func(ctx context.Context, set receiver.Settings, cfg component.Config) (component.Component, error) { |
| 54 |
return factory.CreateTraces(ctx, set, cfg, consumertest.NewNop()) |
| 55 |
}, |
| 56 |
}, |
| 57 |
} |
| 58 |
|
| 59 |
cm, err := confmaptest.LoadConf("metadata.yaml") |
| 60 |
require.NoError(t, err) |
| 61 |
cfg := factory.CreateDefaultConfig() |
| 62 |
sub, err := cm.Sub("tests::config") |
| 63 |
require.NoError(t, err) |
| 64 |
require.NoError(t, sub.Unmarshal(&cfg)) |
| 65 |
|
| 66 |
for _, tt := range tests { |
| 67 |
t.Run(tt.name+"-shutdown", func(t *testing.T) { |
| 68 |
c, err := tt.createFn(context.Background(), receivertest.NewNopSettings(typ), cfg) |
| 69 |
require.NoError(t, err) |
| 70 |
err = c.Shutdown(context.Background()) |
| 71 |
require.NoError(t, err) |
| 72 |
}) |
| 73 |
t.Run(tt.name+"-lifecycle", func(t *testing.T) { |
| 74 |
firstRcvr, err := tt.createFn(context.Background(), receivertest.NewNopSettings(typ), cfg) |
| 75 |
require.NoError(t, err) |
| 76 |
host := newMdatagenNopHost() |
| 77 |
require.NoError(t, err) |
| 78 |
require.NoError(t, firstRcvr.Start(context.Background(), host)) |
| 79 |
require.NoError(t, firstRcvr.Shutdown(context.Background())) |
| 80 |
secondRcvr, err := tt.createFn(context.Background(), receivertest.NewNopSettings(typ), cfg) |
| 81 |
require.NoError(t, err) |
| 82 |
require.NoError(t, secondRcvr.Start(context.Background(), host)) |
| 83 |
require.NoError(t, secondRcvr.Shutdown(context.Background())) |
| 84 |
}) |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
var _ component.Host = (*mdatagenNopHost)(nil) |
| 89 |
|
| 90 |
type mdatagenNopHost struct{} |
| 91 |
|
| 92 |
func newMdatagenNopHost() component.Host { |
| 93 |
return &mdatagenNopHost{} |
| 94 |
} |
| 95 |
|
| 96 |
func (mnh *mdatagenNopHost) GetExtensions() map[component.ID]component.Component { |
| 97 |
return nil |
| 98 |
} |
| 99 |
|
| 100 |
func (mnh *mdatagenNopHost) GetFactory(_ component.Kind, _ component.Type) component.Factory { |
| 101 |
return nil |
| 102 |
} |