From 378b552d255040a73a81e9090cca80a42a65db5d Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 12 Feb 2024 13:58:01 -0800 Subject: [PATCH] [chore] use generated tests for zipkinencodingextension (#31148) Relates to #27849 Co-authored-by: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> --- .../generated_component_test.go | 55 +++++++++++++++++++ .../encoding/zipkinencodingextension/go.mod | 2 +- .../zipkinencodingextension/metadata.yaml | 5 +- 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 extension/encoding/zipkinencodingextension/generated_component_test.go diff --git a/extension/encoding/zipkinencodingextension/generated_component_test.go b/extension/encoding/zipkinencodingextension/generated_component_test.go new file mode 100644 index 000000000000..43fe6de97d7b --- /dev/null +++ b/extension/encoding/zipkinencodingextension/generated_component_test.go @@ -0,0 +1,55 @@ +// Code generated by mdatagen. DO NOT EDIT. + +package zipkinencodingextension + +import ( + "context" + "testing" + + "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) + +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) { + + firstExt, err := factory.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg) + require.NoError(t, err) + require.NoError(t, firstExt.Start(context.Background(), componenttest.NewNopHost())) + 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(), componenttest.NewNopHost())) + require.NoError(t, secondExt.Shutdown(context.Background())) + }) +} diff --git a/extension/encoding/zipkinencodingextension/go.mod b/extension/encoding/zipkinencodingextension/go.mod index f1c952a449ec..70a4ac9593f4 100644 --- a/extension/encoding/zipkinencodingextension/go.mod +++ b/extension/encoding/zipkinencodingextension/go.mod @@ -7,6 +7,7 @@ require ( github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin v0.94.0 github.com/stretchr/testify v1.8.4 go.opentelemetry.io/collector/component v0.94.1 + go.opentelemetry.io/collector/confmap v0.94.1 go.opentelemetry.io/collector/extension v0.94.1 go.opentelemetry.io/collector/pdata v1.1.0 go.opentelemetry.io/otel/metric v1.23.0 @@ -42,7 +43,6 @@ require ( github.com/prometheus/common v0.46.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect go.opentelemetry.io/collector/config/configtelemetry v0.94.1 // indirect - go.opentelemetry.io/collector/confmap v0.94.1 // indirect go.opentelemetry.io/collector/semconv v0.94.1 // indirect go.opentelemetry.io/otel v1.23.0 // indirect go.opentelemetry.io/otel/exporters/prometheus v0.45.1 // indirect diff --git a/extension/encoding/zipkinencodingextension/metadata.yaml b/extension/encoding/zipkinencodingextension/metadata.yaml index 7d3e5f324e10..e90f94c3a4ae 100644 --- a/extension/encoding/zipkinencodingextension/metadata.yaml +++ b/extension/encoding/zipkinencodingextension/metadata.yaml @@ -6,4 +6,7 @@ status: development: [extension] distributions: [] codeowners: - active: [MovieStoreGuy, dao-jun] \ No newline at end of file + active: [MovieStoreGuy, dao-jun] + +tests: + config: