forked from mostafa/xk6-kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopic_test.go
51 lines (41 loc) · 1.79 KB
/
topic_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
package kafka
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestGetKafkaControllerConnection tests whether a connection can be established to a kafka broker
func TestGetKafkaControllerConnection(t *testing.T) {
test := GetTestModuleInstance(t)
connection, xk6KafkaError := test.module.Kafka.GetKafkaControllerConnection(
"localhost:9092", SASLConfig{}, TLSConfig{})
assert.Nil(t, xk6KafkaError)
assert.NotNil(t, connection)
}
// TestGetKafkaControllerConnectionFails tests whether a connection can be established to a kafka broker
// and fails if the given broker is not reachable.
func TestGetKafkaControllerConnectionFails(t *testing.T) {
test := GetTestModuleInstance(t)
connection, xk6KafkaError := test.module.Kafka.GetKafkaControllerConnection(
"localhost:9094", SASLConfig{}, TLSConfig{})
assert.Nil(t, connection)
assert.NotNil(t, xk6KafkaError)
assert.Contains(t, xk6KafkaError.Unwrap().Error(), "failed to dial: failed to open connection to localhost:9094")
assert.Equal(t, xk6KafkaError.Code, dialerError)
}
// TestTopics tests various functions to create, delete and list topics.
func TestTopics(t *testing.T) {
test := GetTestModuleInstance(t)
require.NoError(t, test.moveToVUCode())
err := test.module.Kafka.CreateTopic(
"localhost:9092", "test-topic", 1, 1, "", SASLConfig{}, TLSConfig{})
assert.Nil(t, err)
topics, err := test.module.Kafka.ListTopics("localhost:9092", SASLConfig{}, TLSConfig{})
assert.Nil(t, err)
assert.Contains(t, topics, "test-topic")
err = test.module.Kafka.DeleteTopic("localhost:9092", "test-topic", SASLConfig{}, TLSConfig{})
assert.Nil(t, err)
topics, err = test.module.Kafka.ListTopics("localhost:9092", SASLConfig{}, TLSConfig{})
assert.Nil(t, err)
assert.NotContains(t, topics, "test-topic")
}