-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtesting.go
112 lines (101 loc) · 2.06 KB
/
testing.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
package kafka_exporter
import (
"context"
"github.com/adambabik/kafka_exporter/pkg/types"
)
type mockKafkaClient struct {
brokers []types.Broker
topics []types.Topic
offsets []types.Offset
groups []types.ConsumerGroup
groupsOffsets []types.Offset
}
func newMockKafkaClient(mods ...func(client *mockKafkaClient)) *mockKafkaClient {
c := &mockKafkaClient{
brokers: []types.Broker{
{
ID: 1,
Host: "127.0.0.1",
Port: 9100,
},
},
topics: []types.Topic{
{
Name: "topic-1",
Partitions: []types.Partition{
{
ID: 0,
Leader: 1,
Replicas: []int{1},
Isrs: []int{1},
},
},
},
{
Name: "topic-2",
Partitions: []types.Partition{
{
ID: 0,
Leader: 1,
Replicas: []int{1},
Isrs: []int{1},
},
{
ID: 1,
Leader: 1,
Replicas: []int{1},
Isrs: []int{1},
},
},
},
},
offsets: []types.Offset{
{
Topic: "topic-1",
Partitions: map[int]types.LowHighOffset{
0: {Low: 0, High: 10},
},
},
{
Topic: "topic-2",
Partitions: map[int]types.LowHighOffset{
0: {Low: 0, High: 10},
1: {Low: 0, High: 20},
},
},
},
groups: []types.ConsumerGroup{
{
Name: "group-1",
},
},
groupsOffsets: []types.Offset{
{
Topic: "topic-1",
Group: "group-1",
Partitions: map[int]types.LowHighOffset{
0: {Low: 0, High: 5},
},
},
},
}
for _, mod := range mods {
mod(c)
}
return c
}
func (c mockKafkaClient) Brokers(context.Context) ([]types.Broker, error) {
return c.brokers, nil
}
func (c mockKafkaClient) Topics(context.Context) ([]types.Topic, error) {
return c.topics, nil
}
func (c mockKafkaClient) Offsets(context.Context) ([]types.Offset, error) {
return c.offsets, nil
}
func (c mockKafkaClient) ConsumerGroups(context.Context) ([]types.ConsumerGroup, error) {
return c.groups, nil
}
func (c mockKafkaClient) OffsetsForConsumerGroups(context.Context) ([]types.Offset, error) {
return c.groupsOffsets, nil
}