forked from SumoLogic/sumologic-otel-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
126 lines (121 loc) · 3.36 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
package sumologicexporter
import (
"errors"
"testing"
"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",
CompressEncoding: "gzip",
TraceFormat: "otlp",
HTTPClientSettings: confighttp.HTTPClientSettings{
Timeout: defaultTimeout,
Endpoint: "test_endpoint",
},
},
},
{
name: "unexpected metric format",
expectedError: errors.New("unexpected metric format: test_format"),
cfg: &Config{
LogFormat: "json",
MetricFormat: "test_format",
HTTPClientSettings: confighttp.HTTPClientSettings{
Timeout: defaultTimeout,
Endpoint: "test_endpoint",
},
CompressEncoding: "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",
HTTPClientSettings: confighttp.HTTPClientSettings{
Timeout: defaultTimeout,
Endpoint: "test_endpoint",
},
CompressEncoding: "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",
HTTPClientSettings: confighttp.HTTPClientSettings{
Timeout: defaultTimeout,
Endpoint: "test_endpoint",
},
CompressEncoding: "gzip",
},
},
{
name: "unexpected trace format",
expectedError: errors.New("unexpected trace format: text"),
cfg: &Config{
LogFormat: "json",
MetricFormat: "otlp",
TraceFormat: "text",
HTTPClientSettings: confighttp.HTTPClientSettings{
Timeout: defaultTimeout,
Endpoint: "test_endpoint",
},
CompressEncoding: "gzip",
},
},
{
name: "unexpected compression encoding",
expectedError: errors.New("invalid compression encoding type: test_format; invalid compression encoding type: test_format"),
cfg: &Config{
LogFormat: "json",
MetricFormat: "otlp",
CompressEncoding: "test_format",
TraceFormat: "otlp",
HTTPClientSettings: confighttp.HTTPClientSettings{
Timeout: defaultTimeout,
Endpoint: "test_endpoint",
},
},
},
{
name: "no endpoint and no auth extension specified",
expectedError: errors.New("no endpoint and no auth extension specified"),
cfg: &Config{
LogFormat: "json",
MetricFormat: "otlp",
CompressEncoding: "gzip",
TraceFormat: "otlp",
HTTPClientSettings: confighttp.HTTPClientSettings{
Timeout: defaultTimeout,
},
},
},
}
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)
}
})
}
}