forked from mostafa/xk6-kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration_test.go
91 lines (78 loc) · 2.41 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
84
85
86
87
88
89
90
91
package kafka
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
var configuration Configuration = Configuration{
Consumer: ConsumerConfiguration{
KeyDeserializer: StringDeserializer,
ValueDeserializer: StringDeserializer,
},
Producer: ProducerConfiguration{
KeySerializer: StringSerializer,
ValueSerializer: StringSerializer,
},
SchemaRegistry: SchemaRegistryConfiguration{
Url: "http://localhost:8081",
BasicAuth: BasicAuth{
Username: "username",
Password: "password",
},
UseLatest: true,
},
}
// TestUnmarshalConfiguration tests unmarshalling of a given configuration
func TestUnmarshalConfiguration(t *testing.T) {
configJson, _ := json.Marshal(configuration)
config, err := UnmarshalConfiguration(string(configJson))
assert.Nil(t, err)
assert.Equal(t, configuration, config)
}
// TestUnmarshalConfigurationsFails tests unmarshalling of a given configuration and fails
// on invalid JSON.
func TestUnmarshalConfigurationsFails(t *testing.T) {
configJson := `{"}`
_, err := UnmarshalConfiguration(configJson)
assert.NotNil(t, err)
assert.Equal(t, "Cannot unmarshal configuration.", err.Message)
}
// TestValidateConfiguration tests the validation of a given configuration.
func TestValidateConfiguration(t *testing.T) {
err := ValidateConfiguration(configuration)
assert.Nil(t, err)
}
// TestValidateConfigurationFallbackToDefaults tests the validation of a given configuration
// and falls back to default on invalid configuration.
func TestValidateConfigurationFallbackToDefaults(t *testing.T) {
configuration := Configuration{}
err := ValidateConfiguration(configuration)
assert.Nil(t, err)
}
// TestGivenCredentials tests the validation of a given credentials.
func TestGivenCredentials(t *testing.T) {
configuration := Configuration{
SchemaRegistry: SchemaRegistryConfiguration{
Url: "http://localhost:8081",
BasicAuth: BasicAuth{
Username: "username",
Password: "password",
},
UseLatest: true,
},
}
valid := GivenCredentials(configuration)
assert.True(t, valid)
}
// TestGivenCredentialsFails tests if credentials are given in Schema Registry config
// and fails on no auth creds.
func TestGivenCredentialsFails(t *testing.T) {
configuration := Configuration{
SchemaRegistry: SchemaRegistryConfiguration{
Url: "http://localhost:8081",
UseLatest: true,
},
}
valid := GivenCredentials(configuration)
assert.False(t, valid)
}