mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Use a custom noop host implementation that implements all non-deprecated, publicly-accessible interfaces implemented by the Collector service. I didn't implement the `ExposeExporters` interface since it is deprecated. Related to https://github.com/open-telemetry/opentelemetry-collector/pull/13577.
70 lines
2.0 KiB
Go
70 lines
2.0 KiB
Go
// Code generated by mdatagen. DO NOT EDIT.
|
|
|
|
package zpagesextension
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"go.opentelemetry.io/collector/component"
|
|
"go.opentelemetry.io/collector/component/componenttest"
|
|
"go.opentelemetry.io/collector/confmap/confmaptest"
|
|
"go.opentelemetry.io/collector/extension/extensiontest"
|
|
)
|
|
|
|
var typ = component.MustNewType("zpages")
|
|
|
|
func TestComponentFactoryType(t *testing.T) {
|
|
require.Equal(t, typ, NewFactory().Type())
|
|
}
|
|
|
|
func TestComponentConfigStruct(t *testing.T) {
|
|
require.NoError(t, componenttest.CheckConfigStruct(NewFactory().CreateDefaultConfig()))
|
|
}
|
|
|
|
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, sub.Unmarshal(&cfg))
|
|
t.Run("shutdown", func(t *testing.T) {
|
|
e, err := factory.Create(context.Background(), extensiontest.NewNopSettings(typ), cfg)
|
|
require.NoError(t, err)
|
|
err = e.Shutdown(context.Background())
|
|
require.NoError(t, err)
|
|
})
|
|
t.Run("lifecycle", func(t *testing.T) {
|
|
firstExt, err := factory.Create(context.Background(), extensiontest.NewNopSettings(typ), cfg)
|
|
require.NoError(t, err)
|
|
require.NoError(t, firstExt.Start(context.Background(), newMdatagenNopHost()))
|
|
require.NoError(t, firstExt.Shutdown(context.Background()))
|
|
|
|
secondExt, err := factory.Create(context.Background(), extensiontest.NewNopSettings(typ), cfg)
|
|
require.NoError(t, err)
|
|
require.NoError(t, secondExt.Start(context.Background(), newMdatagenNopHost()))
|
|
require.NoError(t, secondExt.Shutdown(context.Background()))
|
|
})
|
|
}
|
|
|
|
var _ component.Host = (*mdatagenNopHost)(nil)
|
|
|
|
type mdatagenNopHost struct{}
|
|
|
|
func newMdatagenNopHost() component.Host {
|
|
return &mdatagenNopHost{}
|
|
}
|
|
|
|
func (mnh *mdatagenNopHost) GetExtensions() map[component.ID]component.Component {
|
|
return nil
|
|
}
|
|
|
|
func (mnh *mdatagenNopHost) GetFactory(_ component.Kind, _ component.Type) component.Factory {
|
|
return nil
|
|
}
|