forked from segmentio/kafka-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsul_test.go
49 lines (40 loc) · 923 Bytes
/
consul_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
package kafka
import (
"context"
"testing"
"time"
"github.com/google/uuid"
)
func TestConsul(t *testing.T) {
tests := []struct {
scenario string
test func(*testing.T, context.Context, GroupConfig)
}{
{
"should acquire a lock",
acquireLock,
},
}
for _, test := range tests {
t.Run(test.scenario, func(t *testing.T) {
t.Parallel()
config := GroupConfig{
Name: uuid.New().String(),
Addr: "http://localhost:8500",
Brokers: []string{"localhost:9092"},
Topic: "test",
Partitions: 1,
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
test.test(t, ctx, config)
})
}
}
func acquireLock(t *testing.T, ctx context.Context, config GroupConfig) {
reader, err := NewGroupReader(ctx, config)
if err != nil {
t.Fatalf("failed to acquire a lock on the reader: %s", err.Error())
}
reader.Close()
}