1// Copyright The OpenTelemetry Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package extensionhelper
16
17import (
18	"context"
19	"testing"
20
21	"github.com/stretchr/testify/assert"
22
23	"go.opentelemetry.io/collector/component"
24	"go.opentelemetry.io/collector/component/componenttest"
25	"go.opentelemetry.io/collector/config"
26)
27
28const typeStr = "test"
29
30var (
31	defaultCfg           = config.NewExtensionSettings(config.NewID(typeStr))
32	nopExtensionInstance = new(nopExtension)
33)
34
35func TestNewFactory(t *testing.T) {
36	factory := NewFactory(
37		typeStr,
38		defaultConfig,
39		createExtension)
40	assert.EqualValues(t, typeStr, factory.Type())
41	assert.EqualValues(t, &defaultCfg, factory.CreateDefaultConfig())
42	ext, err := factory.CreateExtension(context.Background(), componenttest.NewNopExtensionCreateSettings(), &defaultCfg)
43	assert.NoError(t, err)
44	assert.Same(t, nopExtensionInstance, ext)
45}
46
47func defaultConfig() config.Extension {
48	return &defaultCfg
49}
50
51func createExtension(context.Context, component.ExtensionCreateSettings, config.Extension) (component.Extension, error) {
52	return nopExtensionInstance, nil
53}
54
55type nopExtension struct {
56}
57
58func (ne *nopExtension) Start(context.Context, component.Host) error {
59	return nil
60}
61
62// Shutdown stops the exporter and is invoked during shutdown.
63func (ne *nopExtension) Shutdown(context.Context) error {
64	return nil
65}
66