From 36f047714ecbf9867761246dadbef91aaf5d7a4e Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 18 Dec 2023 09:14:47 -0800 Subject: [PATCH] [chore] move azureblob receiver to generated lifecycle tests (#30025) Related to https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/27850 --- .../generated_component_test.go | 96 +++++++++++++++++++ receiver/azureblobreceiver/go.mod | 2 +- receiver/azureblobreceiver/metadata.yaml | 5 + 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 receiver/azureblobreceiver/generated_component_test.go diff --git a/receiver/azureblobreceiver/generated_component_test.go b/receiver/azureblobreceiver/generated_component_test.go new file mode 100644 index 000000000000..7ad60d743860 --- /dev/null +++ b/receiver/azureblobreceiver/generated_component_test.go @@ -0,0 +1,96 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package azureblobreceiver + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/component/componenttest" + + "go.opentelemetry.io/collector/consumer/consumertest" + "go.opentelemetry.io/collector/receiver" + "go.opentelemetry.io/collector/receiver/receivertest" + + "go.opentelemetry.io/collector/confmap/confmaptest" +) + +// assertNoErrorHost implements a component.Host that asserts that there were no errors. +type assertNoErrorHost struct { + component.Host + *testing.T +} + +var _ component.Host = (*assertNoErrorHost)(nil) + +// newAssertNoErrorHost returns a new instance of assertNoErrorHost. +func newAssertNoErrorHost(t *testing.T) component.Host { + return &assertNoErrorHost{ + componenttest.NewNopHost(), + t, + } +} + +func (aneh *assertNoErrorHost) ReportFatalError(err error) { + assert.NoError(aneh, err) +} + +func Test_ComponentLifecycle(t *testing.T) { + factory := NewFactory() + + tests := []struct { + name string + createFn func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) + }{ + + { + name: "logs", + createFn: func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) { + return factory.CreateLogsReceiver(ctx, set, cfg, consumertest.NewNop()) + }, + }, + + { + name: "traces", + createFn: func(ctx context.Context, set receiver.CreateSettings, cfg component.Config) (component.Component, error) { + return factory.CreateTracesReceiver(ctx, set, cfg, consumertest.NewNop()) + }, + }, + } + + cm, err := confmaptest.LoadConf("metadata.yaml") + require.NoError(t, err) + cfg := factory.CreateDefaultConfig() + sub, err := cm.Sub("tests::config") + require.NoError(t, err) + require.NoError(t, component.UnmarshalConfig(sub, cfg)) + + for _, test := range tests { + t.Run(test.name+"-shutdown", func(t *testing.T) { + c, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + err = c.Shutdown(context.Background()) + require.NoError(t, err) + }) + + t.Run(test.name+"-lifecycle", func(t *testing.T) { + + // TODO support lifecycle + t.SkipNow() + + firstRcvr, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + host := newAssertNoErrorHost(t) + require.NoError(t, err) + require.NoError(t, firstRcvr.Start(context.Background(), host)) + require.NoError(t, firstRcvr.Shutdown(context.Background())) + secondRcvr, err := test.createFn(context.Background(), receivertest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + require.NoError(t, secondRcvr.Start(context.Background(), host)) + require.NoError(t, secondRcvr.Shutdown(context.Background())) + }) + } +} diff --git a/receiver/azureblobreceiver/go.mod b/receiver/azureblobreceiver/go.mod index 9e98b72a9053..3b49191ec5ce 100644 --- a/receiver/azureblobreceiver/go.mod +++ b/receiver/azureblobreceiver/go.mod @@ -8,6 +8,7 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent v0.91.0 github.com/stretchr/testify v1.8.4 go.opentelemetry.io/collector/component v0.91.0 + go.opentelemetry.io/collector/confmap v0.91.0 go.opentelemetry.io/collector/consumer v0.91.0 go.opentelemetry.io/collector/otelcol v0.91.0 go.opentelemetry.io/collector/pdata v1.0.0 @@ -78,7 +79,6 @@ require ( go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/collector v0.91.0 // indirect go.opentelemetry.io/collector/config/configtelemetry v0.91.0 // indirect - go.opentelemetry.io/collector/confmap v0.91.0 // indirect go.opentelemetry.io/collector/connector v0.91.0 // indirect go.opentelemetry.io/collector/exporter v0.91.0 // indirect go.opentelemetry.io/collector/extension v0.91.0 // indirect diff --git a/receiver/azureblobreceiver/metadata.yaml b/receiver/azureblobreceiver/metadata.yaml index 3cf4f6c83017..d9cbacf8e7d8 100644 --- a/receiver/azureblobreceiver/metadata.yaml +++ b/receiver/azureblobreceiver/metadata.yaml @@ -7,3 +7,8 @@ status: distributions: [contrib] codeowners: active: [eedorenko, mx-psi] + +tests: + config: + connection_string: DefaultEndpointsProtocol=https;AccountName=accountName;AccountKey=+idLkHYcL0MUWIKYHm2j4Q==;EndpointSuffix=core.windows.net + skip_lifecycle: true