From 6b85afd695e0270339f6d2c83fb10b5c5448874d Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Fri, 12 Jan 2024 17:31:48 -0800 Subject: [PATCH] [chore] move oidcauth extension to generated lifecycle tests (#30425) Relates to https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/27849 --- .../generated_component_test.go | 71 +++++++++++++++++++ extension/oidcauthextension/go.mod | 2 +- extension/oidcauthextension/metadata.yaml | 4 ++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 extension/oidcauthextension/generated_component_test.go diff --git a/extension/oidcauthextension/generated_component_test.go b/extension/oidcauthextension/generated_component_test.go new file mode 100644 index 000000000000..4debcc20b033 --- /dev/null +++ b/extension/oidcauthextension/generated_component_test.go @@ -0,0 +1,71 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package oidcauthextension + +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/extension/extensiontest" + + "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 TestComponentLifecycle(t *testing.T) { + factory := NewFactory() + + 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)) + + t.Run("shutdown", func(t *testing.T) { + e, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + err = e.Shutdown(context.Background()) + require.NoError(t, err) + }) + + t.Run("lifecycle", func(t *testing.T) { + + // TODO support lifecycle + t.SkipNow() + + firstExt, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + require.NoError(t, firstExt.Start(context.Background(), newAssertNoErrorHost(t))) + require.NoError(t, firstExt.Shutdown(context.Background())) + + secondExt, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + require.NoError(t, secondExt.Start(context.Background(), newAssertNoErrorHost(t))) + require.NoError(t, secondExt.Shutdown(context.Background())) + }) +} diff --git a/extension/oidcauthextension/go.mod b/extension/oidcauthextension/go.mod index 8480caa02d39..c1ae2dfe92b1 100644 --- a/extension/oidcauthextension/go.mod +++ b/extension/oidcauthextension/go.mod @@ -7,6 +7,7 @@ require ( github.com/stretchr/testify v1.8.4 go.opentelemetry.io/collector v0.92.1-0.20240112172857-83d463ceba06 go.opentelemetry.io/collector/component v0.92.1-0.20240112172857-83d463ceba06 + go.opentelemetry.io/collector/confmap v0.92.1-0.20240112172857-83d463ceba06 go.opentelemetry.io/collector/extension v0.92.1-0.20240112172857-83d463ceba06 go.opentelemetry.io/collector/extension/auth v0.92.1-0.20240112172857-83d463ceba06 go.opentelemetry.io/otel/metric v1.21.0 @@ -43,7 +44,6 @@ require ( github.com/prometheus/statsd_exporter v0.22.7 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/collector/config/configtelemetry v0.92.1-0.20240112172857-83d463ceba06 // indirect - go.opentelemetry.io/collector/confmap v0.92.1-0.20240112172857-83d463ceba06 // indirect go.opentelemetry.io/collector/featuregate v1.0.2-0.20240112172857-83d463ceba06 // indirect go.opentelemetry.io/collector/pdata v1.0.2-0.20240112172857-83d463ceba06 // indirect go.opentelemetry.io/otel v1.21.0 // indirect diff --git a/extension/oidcauthextension/metadata.yaml b/extension/oidcauthextension/metadata.yaml index e498713fa6c7..c937c6262031 100644 --- a/extension/oidcauthextension/metadata.yaml +++ b/extension/oidcauthextension/metadata.yaml @@ -7,3 +7,7 @@ status: distributions: [contrib, observiq, sumo] codeowners: active: [jpkrohling] + +tests: + config: + skip_lifecycle: true