Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] add mdatagen extension lifecycle tests #29734

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/mdatagen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ func templatize(tmplFile string, md metadata) *template.Template {
"isReceiver": func() bool {
return md.Status.Class == "receiver"
},
"isExtension": func() bool {
return md.Status.Class == "extension"
},
"skipLifecycle": func() bool {
return md.Tests.SkipLifecycle
},
Expand Down
39 changes: 39 additions & 0 deletions cmd/mdatagen/templates/component_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/receivertest"
{{ end }}
{{ if isExtension }}
"go.opentelemetry.io/collector/extension/extensiontest"
{{ end }}
"go.opentelemetry.io/collector/confmap/confmaptest"
{{ if or (isExporter) (isProcessor) }}
Expand Down Expand Up @@ -299,3 +302,39 @@ func Test_ComponentLifecycle(t *testing.T) {
}
}
{{ end }}

{{ if isExtension }}
func Test_ComponentLifecycle(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) {
{{ if skipLifecycle }}
// TODO support lifecycle
t.SkipNow()
{{ end }}
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()))
})
}
{{ end }}
68 changes: 68 additions & 0 deletions extension/headerssetterextension/generated_component_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions extension/headerssetterextension/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ status:
- sumo
codeowners:
active: [jpkrohling]
tests:
config:
atoulme marked this conversation as resolved.
Show resolved Hide resolved