forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactory_test.go
73 lines (65 loc) · 1.59 KB
/
factory_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package filestorage
import (
"context"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/extension/extensiontest"
)
func TestFactory(t *testing.T) {
f := NewFactory()
cfg := f.CreateDefaultConfig().(*Config)
if runtime.GOOS != "windows" {
require.Equal(t, "/var/lib/otelcol/file_storage", cfg.Directory)
} else {
expected := filepath.Join(os.Getenv("ProgramData"), "Otelcol", "FileStorage")
require.Equal(t, expected, cfg.Directory)
}
require.Equal(t, time.Second, cfg.Timeout)
require.Equal(t, false, cfg.FSync)
tests := []struct {
name string
config *Config
wantErr bool
wantErrMessage string
}{
{
name: "Default",
config: func() *Config {
return &Config{
Directory: t.TempDir(),
Compaction: &CompactionConfig{},
}
}(),
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
e, err := f.CreateExtension(
context.Background(),
extensiontest.NewNopCreateSettings(),
test.config,
)
if test.wantErr {
require.Error(t, err)
if test.wantErrMessage != "" {
require.True(t, strings.HasPrefix(err.Error(), test.wantErrMessage))
}
require.Nil(t, e)
} else {
require.NoError(t, err)
require.NotNil(t, e)
ctx := context.Background()
require.NoError(t, e.Start(ctx, componenttest.NewNopHost()))
require.NoError(t, e.Shutdown(ctx))
}
})
}
}