forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
93 lines (72 loc) · 2.04 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
package shim
import (
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/influxdata/telegraf"
cfg "github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/inputs"
"github.com/influxdata/telegraf/plugins/processors"
)
func TestLoadConfig(t *testing.T) {
t.Setenv("SECRET_TOKEN", "xxxxxxxxxx")
t.Setenv("SECRET_VALUE", `test"\test`)
inputs.Add("test", func() telegraf.Input {
return &serviceInput{}
})
c := "./testdata/plugin.conf"
conf, err := LoadConfig(&c)
require.NoError(t, err)
inp := conf.Input.(*serviceInput)
require.Equal(t, "awesome name", inp.ServiceName)
require.Equal(t, "xxxxxxxxxx", inp.SecretToken)
require.Equal(t, `test"\test`, inp.SecretValue)
}
func TestLoadingSpecialTypes(t *testing.T) {
inputs.Add("test", func() telegraf.Input {
return &testDurationInput{}
})
c := "./testdata/special.conf"
conf, err := LoadConfig(&c)
require.NoError(t, err)
inp := conf.Input.(*testDurationInput)
require.EqualValues(t, 3*time.Second, inp.Duration)
require.EqualValues(t, 3*1000*1000, inp.Size)
require.EqualValues(t, 52, inp.Hex)
}
func TestLoadingProcessorWithConfig(t *testing.T) {
proc := &testConfigProcessor{}
processors.Add("test_config_load", func() telegraf.Processor {
return proc
})
c := "./testdata/processor.conf"
_, err := LoadConfig(&c)
require.NoError(t, err)
require.EqualValues(t, "yep", proc.Loaded)
}
type testDurationInput struct {
Duration cfg.Duration `toml:"duration"`
Size cfg.Size `toml:"size"`
Hex int64 `toml:"hex"`
}
func (i *testDurationInput) SampleConfig() string {
return ""
}
func (i *testDurationInput) Description() string {
return ""
}
func (i *testDurationInput) Gather(_ telegraf.Accumulator) error {
return nil
}
type testConfigProcessor struct {
Loaded string `toml:"loaded"`
}
func (p *testConfigProcessor) SampleConfig() string {
return ""
}
func (p *testConfigProcessor) Description() string {
return ""
}
func (p *testConfigProcessor) Apply(metrics ...telegraf.Metric) []telegraf.Metric {
return metrics
}