forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_test.go
127 lines (118 loc) · 3.1 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package sumologicexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sumologicexporter"
import (
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
)
func TestInitExporterInvalidConfiguration(t *testing.T) {
testcases := []struct {
name string
cfg *Config
expectedError error
}{
{
name: "unexpected log format",
expectedError: errors.New("unexpected log format: test_format"),
cfg: &Config{
LogFormat: "test_format",
MetricFormat: "otlp",
ClientConfig: confighttp.ClientConfig{
Timeout: defaultTimeout,
Endpoint: "test_endpoint",
},
},
},
{
name: "unexpected metric format",
expectedError: errors.New("unexpected metric format: test_format"),
cfg: &Config{
LogFormat: "json",
MetricFormat: "test_format",
ClientConfig: confighttp.ClientConfig{
Timeout: defaultTimeout,
Endpoint: "test_endpoint",
Compression: "gzip",
},
},
},
{
name: "unsupported Carbon2 metrics format",
expectedError: errors.New("support for the carbon2 metric format was removed, please use prometheus or otlp instead"),
cfg: &Config{
LogFormat: "json",
MetricFormat: "carbon2",
ClientConfig: confighttp.ClientConfig{
Timeout: defaultTimeout,
Endpoint: "test_endpoint",
Compression: "gzip",
},
},
},
{
name: "unsupported Graphite metrics format",
expectedError: errors.New("support for the graphite metric format was removed, please use prometheus or otlp instead"),
cfg: &Config{
LogFormat: "json",
MetricFormat: "graphite",
ClientConfig: confighttp.ClientConfig{
Timeout: defaultTimeout,
Endpoint: "test_endpoint",
Compression: "gzip",
},
},
},
}
for _, tc := range testcases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := component.ValidateConfig(tc.cfg)
if tc.expectedError != nil {
assert.EqualError(t, err, tc.expectedError.Error())
} else {
assert.NoError(t, err)
}
})
}
}
func TestConfigInvalidTimeout(t *testing.T) {
testcases := []struct {
name string
expectedError error
cfg *Config
}{
{
name: "over the limit timeout",
expectedError: errors.New("timeout must be between 1 and 55 seconds, got 56s"),
cfg: &Config{
ClientConfig: confighttp.ClientConfig{
Timeout: 56 * time.Second,
},
},
},
{
name: "less than 1 timeout",
expectedError: errors.New("timeout must be between 1 and 55 seconds, got 0s"),
cfg: &Config{
ClientConfig: confighttp.ClientConfig{
Timeout: 0 * time.Second,
},
},
},
}
for _, tc := range testcases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := tc.cfg.Validate()
if tc.expectedError != nil {
assert.EqualError(t, err, tc.expectedError.Error())
} else {
assert.NoError(t, err)
}
})
}
}