forked from open-telemetry/opentelemetry-collector-contrib
/
config_test.go
68 lines (56 loc) · 1.92 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package instanaexporter
import (
"testing"
"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configtls"
)
func TestConfigValidate(t *testing.T) {
t.Run("Empty configuration", func(t *testing.T) {
c := &Config{}
err := c.Validate()
assert.Error(t, err)
})
t.Run("Valid configuration", func(t *testing.T) {
c := &Config{Endpoint: "https://example.com/", AgentKey: "key1"}
err := c.Validate()
assert.NoError(t, err)
assert.Equal(t, "https://example.com/", c.Endpoint, "no Instana endpoint set")
assert.Equal(t, "", c.TLSSetting.CAFile, "optional ca_file property not set")
})
t.Run("Valid configuration with ca_file", func(t *testing.T) {
c := &Config{Endpoint: "https://example.com/", AgentKey: "key1", ClientConfig: confighttp.ClientConfig{
TLSSetting: configtls.ClientConfig{
TLSSetting: configtls.Config{
CAFile: "ca.crt",
},
},
}}
err := c.Validate()
assert.NoError(t, err)
assert.Equal(t, "https://example.com/", c.Endpoint, "no Instana endpoint set")
assert.Equal(t, "ca.crt", c.TLSSetting.CAFile, "optional ca_file property set")
})
t.Run("Invalid Endpoint Invalid URL", func(t *testing.T) {
c := &Config{Endpoint: "https://example.}~", AgentKey: "key1"}
err := c.Validate()
assert.Error(t, err)
})
t.Run("Invalid Endpoint No Protocol", func(t *testing.T) {
c := &Config{Endpoint: "example.com", AgentKey: "key1"}
err := c.Validate()
assert.Error(t, err)
})
t.Run("Invalid Endpoint No https:// Protocol", func(t *testing.T) {
c := &Config{Endpoint: "http://example.com", AgentKey: "key1"}
err := c.Validate()
assert.Error(t, err, "endpoint must start with https://")
})
t.Run("No Agent key", func(t *testing.T) {
c := &Config{Endpoint: "https://example.com/"}
err := c.Validate()
assert.Error(t, err)
})
}