|
| 1 | +/* |
| 2 | +Copyright 2024 The Dapr Authors |
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +Unless required by applicable law or agreed to in writing, software |
| 8 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +See the License for the specific language governing permissions and |
| 11 | +limitations under the License. |
| 12 | +*/ |
| 13 | + |
| 14 | +package mocks |
| 15 | + |
| 16 | +import ( |
| 17 | + "context" |
| 18 | + |
| 19 | + "github.com/IBM/sarama" |
| 20 | +) |
| 21 | + |
| 22 | +type FakeConsumerGroup struct { |
| 23 | + consumerFn func(context.Context, []string, sarama.ConsumerGroupHandler) error |
| 24 | + errorsFn func() <-chan error |
| 25 | + closeFn func() error |
| 26 | + pauseFn func(map[string][]int32) |
| 27 | + resumeFn func(map[string][]int32) |
| 28 | + pauseAllFn func() |
| 29 | + resumeAllFn func() |
| 30 | +} |
| 31 | + |
| 32 | +func NewConsumerGroup() *FakeConsumerGroup { |
| 33 | + return &FakeConsumerGroup{ |
| 34 | + consumerFn: func(context.Context, []string, sarama.ConsumerGroupHandler) error { |
| 35 | + return nil |
| 36 | + }, |
| 37 | + errorsFn: func() <-chan error { |
| 38 | + return nil |
| 39 | + }, |
| 40 | + closeFn: func() error { |
| 41 | + return nil |
| 42 | + }, |
| 43 | + pauseFn: func(map[string][]int32) { |
| 44 | + }, |
| 45 | + resumeFn: func(map[string][]int32) { |
| 46 | + }, |
| 47 | + pauseAllFn: func() { |
| 48 | + }, |
| 49 | + resumeAllFn: func() { |
| 50 | + }, |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +func (f *FakeConsumerGroup) WithConsumeFn(fn func(context.Context, []string, sarama.ConsumerGroupHandler) error) *FakeConsumerGroup { |
| 55 | + f.consumerFn = fn |
| 56 | + return f |
| 57 | +} |
| 58 | + |
| 59 | +func (f *FakeConsumerGroup) WithErrorsFn(fn func() <-chan error) *FakeConsumerGroup { |
| 60 | + f.errorsFn = fn |
| 61 | + return f |
| 62 | +} |
| 63 | + |
| 64 | +func (f *FakeConsumerGroup) WithCloseFn(fn func() error) *FakeConsumerGroup { |
| 65 | + f.closeFn = fn |
| 66 | + return f |
| 67 | +} |
| 68 | + |
| 69 | +func (f *FakeConsumerGroup) WithPauseFn(fn func(map[string][]int32)) *FakeConsumerGroup { |
| 70 | + f.pauseFn = fn |
| 71 | + return f |
| 72 | +} |
| 73 | + |
| 74 | +func (f *FakeConsumerGroup) WithResumeFn(fn func(map[string][]int32)) *FakeConsumerGroup { |
| 75 | + f.resumeFn = fn |
| 76 | + return f |
| 77 | +} |
| 78 | + |
| 79 | +func (f *FakeConsumerGroup) WithPauseAllFn(fn func()) *FakeConsumerGroup { |
| 80 | + f.pauseAllFn = fn |
| 81 | + return f |
| 82 | +} |
| 83 | + |
| 84 | +func (f *FakeConsumerGroup) WithResumeAllFn(fn func()) *FakeConsumerGroup { |
| 85 | + f.resumeAllFn = fn |
| 86 | + return f |
| 87 | +} |
| 88 | + |
| 89 | +func (f *FakeConsumerGroup) Consume(ctx context.Context, topics []string, handler sarama.ConsumerGroupHandler) error { |
| 90 | + return f.consumerFn(ctx, topics, handler) |
| 91 | +} |
| 92 | + |
| 93 | +func (f *FakeConsumerGroup) Errors() <-chan error { |
| 94 | + return f.errorsFn() |
| 95 | +} |
| 96 | + |
| 97 | +func (f *FakeConsumerGroup) Close() error { |
| 98 | + return f.closeFn() |
| 99 | +} |
| 100 | + |
| 101 | +func (f *FakeConsumerGroup) Pause(partitions map[string][]int32) { |
| 102 | + f.pauseFn(partitions) |
| 103 | +} |
| 104 | + |
| 105 | +func (f *FakeConsumerGroup) Resume(partitions map[string][]int32) { |
| 106 | + f.resumeFn(partitions) |
| 107 | +} |
| 108 | + |
| 109 | +func (f *FakeConsumerGroup) PauseAll() { |
| 110 | + f.pauseAllFn() |
| 111 | +} |
| 112 | + |
| 113 | +func (f *FakeConsumerGroup) ResumeAll() { |
| 114 | + f.resumeAllFn() |
| 115 | +} |
0 commit comments