-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
config_test.go
77 lines (63 loc) · 3 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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package azureeventhubreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/azureeventhubreceiver"
import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/otelcol/otelcoltest"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/azureeventhubreceiver/internal/metadata"
)
func TestLoadConfig(t *testing.T) {
factories, err := otelcoltest.NopFactories()
assert.NoError(t, err)
factory := NewFactory()
factories.Receivers[metadata.Type] = factory
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33594
// nolint:staticcheck
cfg, err := otelcoltest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories)
require.NoError(t, err)
require.NotNil(t, cfg)
assert.Len(t, cfg.Receivers, 2)
r0 := cfg.Receivers[component.NewID(metadata.Type)]
assert.Equal(t, "Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=superSecret1234=;EntityPath=hubName", r0.(*Config).Connection)
assert.Equal(t, "", r0.(*Config).Offset)
assert.Equal(t, "", r0.(*Config).Partition)
assert.Equal(t, defaultLogFormat, logFormat(r0.(*Config).Format))
assert.False(t, r0.(*Config).ApplySemanticConventions)
r1 := cfg.Receivers[component.NewIDWithName(metadata.Type, "all")]
assert.Equal(t, "Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=superSecret1234=;EntityPath=hubName", r1.(*Config).Connection)
assert.Equal(t, "1234-5566", r1.(*Config).Offset)
assert.Equal(t, "foo", r1.(*Config).Partition)
assert.Equal(t, rawLogFormat, logFormat(r1.(*Config).Format))
assert.True(t, r1.(*Config).ApplySemanticConventions)
}
func TestMissingConnection(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
err := component.ValidateConfig(cfg)
assert.EqualError(t, err, "missing connection")
}
func TestInvalidConnectionString(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
cfg.(*Config).Connection = "foo"
err := component.ValidateConfig(cfg)
assert.EqualError(t, err, "failed parsing connection string due to unmatched key value separated by '='")
}
func TestIsValidFormat(t *testing.T) {
for _, format := range []logFormat{defaultLogFormat, rawLogFormat, azureLogFormat} {
assert.True(t, isValidFormat(string(format)))
}
assert.False(t, isValidFormat("invalid-format"))
}
func TestInvalidFormat(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
cfg.(*Config).Connection = "Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=superSecret1234=;EntityPath=hubName"
cfg.(*Config).Format = "invalid"
err := component.ValidateConfig(cfg)
assert.ErrorContains(t, err, "invalid format; must be one of")
}