-
Notifications
You must be signed in to change notification settings - Fork 36
/
config_test.go
99 lines (93 loc) · 3.06 KB
/
config_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package jobreceiver
import (
"path/filepath"
"testing"
"time"
"github.com/SumoLogic/sumologic-otel-collector/pkg/receiver/jobreceiver/asset"
"github.com/SumoLogic/sumologic-otel-collector/pkg/receiver/jobreceiver/output/event"
"github.com/SumoLogic/sumologic-otel-collector/pkg/receiver/jobreceiver/output/logentries"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/split"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/confmaptest"
)
func TestConfigValidate(t *testing.T) {
cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml"))
require.NoError(t, err)
factory := NewFactory()
testCases := []struct {
Name string
Expected func() component.Config
}{
{
Name: "minimal",
Expected: func() component.Config {
c := factory.CreateDefaultConfig().(*Config)
c.Schedule.Interval = time.Hour
c.Exec.Command = "echo"
c.Exec.Arguments = []string{"hello world"}
return c
},
},
{
Name: "log_ntp",
Expected: func() component.Config {
c := factory.CreateDefaultConfig().(*Config)
c.Schedule.Interval = time.Hour
c.Exec.Command = "check_ntp_time"
c.Exec.RuntimeAssets = []asset.Spec{
{
Name: "monitoring-plugins",
URL: "https://assets.bonsai.sensu.io/asset.zip",
},
}
c.Exec.Arguments = []string{"-H", "time.nist.gov"}
c.Exec.Timeout = time.Second * 8
c.Output.InputConfig.OperatorType = "log_entries"
c.Output.InputConfig.Attributes = map[string]helper.ExprStringConfig{"label": "foo"}
c.Output.InputConfig.Resource = map[string]helper.ExprStringConfig{"label": "bar"}
c.Output.Builder = &logentries.LogEntriesConfig{
IncludeCommandName: true,
IncludeStreamName: true,
MaxLogSize: 16 * 1000,
Encoding: "utf-8",
Multiline: split.Config{
LineStartPattern: "$start",
},
}
return c
},
},
{
Name: "event_ntp",
Expected: func() component.Config {
c := factory.CreateDefaultConfig().(*Config)
c.Schedule.Interval = time.Hour
c.Exec.Command = "check_ntp_time"
c.Exec.Arguments = []string{"-H", "time.nist.gov"}
c.Exec.Timeout = time.Second * 8
eventCfg := c.Output.Builder.(*event.EventConfig)
require.NotNil(t, eventCfg)
eventCfg.IncludeCommandName = false
eventCfg.IncludeCommandStatus = false
eventCfg.IncludeDuration = false
eventCfg.MaxBodySize = 32 << 10
return c
},
},
}
for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
actual := factory.CreateDefaultConfig()
expected := tc.Expected()
sub, err := cm.Sub(component.NewIDWithName("monitoringjob", tc.Name).String())
require.NoError(t, err)
require.NoError(t, sub.Unmarshal(&actual, confmap.WithIgnoreUnused()))
//require.NoError(t, component.UnmarshalConfig(sub, actual))
assert.Equal(t, expected, actual)
})
}
}