-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration_test.go
83 lines (77 loc) · 2.64 KB
/
configuration_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
package kafkauniverse
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func createValidKafkaClusterRepresentation() KafkaClusterRepresentation {
return KafkaClusterRepresentation{
ID: ptrString("cluster-id"),
Enabled: ptrBool(true),
Version: ptrString("3.1.0"),
TLSEnabled: ptrBool(false),
SaramaLogEnabled: ptrBool(false),
Brokers: []string{"kafka1", "kafka2"},
Security: &KafkaSecurityRepresentation{
ClientID: ptrString("client-id"),
ClientSecret: ptrString("client-secret"),
TokenURL: ptrString("https://token/path"),
},
Producers: []KafkaProducerRepresentation{
{
ID: ptrString("producer-1"),
Enabled: ptrBool(true),
Topic: ptrString("topic-producer-1"),
},
},
Consumers: []KafkaConsumerRepresentation{
{
ID: ptrString("consumer-1"),
Enabled: ptrBool(true),
Topic: ptrString("topic-consumer-1"),
ConsumerGroupName: ptrString("consumer-group"),
FailureProducer: ptrString("producer-1"),
},
},
}
}
func TestValidateCluster(t *testing.T) {
var cluster = createValidKafkaClusterRepresentation()
assert.Nil(t, cluster.Validate())
var emptyString = ptrString("")
var invalidCases []KafkaClusterRepresentation
for i := 0; i < 25; i++ {
invalidCases = append(invalidCases, createValidKafkaClusterRepresentation())
}
invalidCases[0].ID = nil
invalidCases[1].ID = emptyString
invalidCases[2].Version = nil
invalidCases[3].Version = emptyString
invalidCases[4].Brokers = nil
invalidCases[5].Brokers = []string{""}
invalidCases[6].Security = nil
invalidCases[7].Security.ClientID = nil
invalidCases[8].Security.ClientID = emptyString
invalidCases[9].Security.ClientSecret = nil
invalidCases[10].Security.ClientSecret = emptyString
invalidCases[11].Security.TokenURL = nil
invalidCases[12].Security.TokenURL = emptyString
invalidCases[13].Producers = nil
invalidCases[13].Consumers = nil
invalidCases[14].Producers[0].ID = nil
invalidCases[15].Producers[0].ID = emptyString
invalidCases[16].Producers[0].Topic = nil
invalidCases[17].Producers[0].Topic = emptyString
invalidCases[18].Consumers[0].ID = nil
invalidCases[19].Consumers[0].ID = emptyString
invalidCases[20].Consumers[0].Topic = nil
invalidCases[21].Consumers[0].Topic = emptyString
invalidCases[22].Consumers[0].ConsumerGroupName = nil
invalidCases[23].Consumers[0].ConsumerGroupName = emptyString
invalidCases[24].Consumers[0].FailureProducer = emptyString
for idx, value := range invalidCases {
t.Run(fmt.Sprintf("Invalid case #%d", idx), func(t *testing.T) {
assert.NotNil(t, value.Validate())
})
}
}