forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_test.go
71 lines (66 loc) · 1.48 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package syslogexporter
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestValidate(t *testing.T) {
tests := []struct {
name string
cfg *Config
err string
}{
{
name: "invalid Port",
cfg: &Config{
Port: 515444,
Endpoint: "host.domain.com",
Protocol: "rfc542",
Network: "udp",
},
err: "unsupported port: port is required, must be in the range 1-65535" + "\n" +
"unsupported protocol: Only rfc5424 and rfc3164 supported",
},
{
name: "invalid Endpoint",
cfg: &Config{
Port: 514,
Endpoint: "",
Protocol: "rfc5424",
Network: "udp",
},
err: "invalid endpoint: endpoint is required but it is not configured",
},
{
name: "unsupported Network",
cfg: &Config{
Port: 514,
Endpoint: "host.domain.com",
Protocol: "rfc5424",
Network: "ftp",
},
err: "unsupported network: network is required, only tcp/udp supported",
},
{
name: "Unsupported Protocol",
cfg: &Config{
Port: 514,
Endpoint: "host.domain.com",
Network: "udp",
Protocol: "rfc",
},
err: "unsupported protocol: Only rfc5424 and rfc3164 supported",
},
}
for _, testInstance := range tests {
t.Run(testInstance.name, func(t *testing.T) {
err := testInstance.cfg.Validate()
if testInstance.err != "" {
assert.EqualError(t, err, testInstance.err)
} else {
assert.NoError(t, err)
}
})
}
}