-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathconfig_test.go
113 lines (98 loc) · 2.79 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
package goneli
import (
"fmt"
"testing"
"github.com/obsidiandynamics/libstdgo/check"
"github.com/obsidiandynamics/libstdgo/scribe"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDefaultKafkaConsumerProvider(t *testing.T) {
c := Config{}
c.SetDefaults()
cons, err := c.KafkaConsumerProvider(&KafkaConfigMap{
"session.timeout.ms": 1000,
})
assert.Nil(t, cons)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "Required property")
}
}
func TestDefaultKafkaProducerProvider(t *testing.T) {
c := Config{}
c.SetDefaults()
prod, err := c.KafkaProducerProvider(&KafkaConfigMap{
"foo": "bar",
})
assert.Nil(t, prod)
if assert.NotNil(t, err) {
assert.Contains(t, err.Error(), "No such configuration property")
}
}
func TestGetString(t *testing.T) {
assert.Equal(t, "some-default", getString("some-default", func() (string, error) { return "", check.ErrSimulated }))
assert.Equal(t, "some-string", getString("some-default", func() (string, error) { return "some-string", nil }))
}
func TestConfigString(t *testing.T) {
cfg := Config{}
cfg.SetDefaults()
assert.Contains(t, cfg.String(), "Config[")
}
func TestValidateConfig_valid(t *testing.T) {
cfg := Config{
KafkaConfig: KafkaConfigMap{},
LeaderTopic: "leader-topic",
LeaderGroupID: "leader-group-d",
KafkaConsumerProvider: StandardKafkaConsumerProvider(),
Scribe: scribe.New(scribe.StandardBinding()),
Name: "name",
}
cfg.SetDefaults()
assert.Nil(t, cfg.Validate())
}
func TestValidateConfig_invalidLimits(t *testing.T) {
cfg := Config{
KafkaConfig: KafkaConfigMap{},
LeaderTopic: "leader-topic",
LeaderGroupID: "leader-group-id",
KafkaConsumerProvider: StandardKafkaConsumerProvider(),
Scribe: scribe.New(scribe.StandardBinding()),
Name: "name",
MinPollInterval: Duration(0),
}
cfg.SetDefaults()
assert.NotNil(t, cfg.Validate())
}
func TestValidateConfig_invalidName(t *testing.T) {
cfg := Config{
Name: "some%thing",
}
cfg.SetDefaults()
err := cfg.Validate()
require.NotNil(t, err)
require.Equal(t, "Name: must be in a valid format.", err.Error())
}
func TestValidateConfig_invalidLeaderTopic(t *testing.T) {
cfg := Config{
LeaderTopic: "topic$#",
}
cfg.SetDefaults()
fmt.Println(cfg)
err := cfg.Validate()
require.NotNil(t, err)
require.Equal(t, "LeaderTopic: must be in a valid format.", err.Error())
}
func TestSanitiseName(t *testing.T) {
cfg := Config{
Name: "some%thing",
}
cfg.SetDefaults()
err := cfg.Validate()
require.NotNil(t, err)
require.Equal(t, err.Error(), "Name: must be in a valid format.")
}
func TestValidateConfig_default(t *testing.T) {
cfg := Config{}
cfg.SetDefaults()
assert.Nil(t, cfg.Validate())
}