// Code generated by mockery v1.0.0. DO NOT EDIT.

package mocks

import (
	kafka "github.com/confluentinc/confluent-kafka-go/kafka"

	mock "github.com/stretchr/testify/mock"

	time "time"
)

// KafkaConsumer is an autogenerated mock type for the KafkaConsumer type
type KafkaConsumer struct {
	mock.Mock
}

// Commit provides a mock function with given fields:
func (_m KafkaConsumer) Commit() ([]kafka.TopicPartition, error) {
	ret := _m.Called()

	var r0 []kafka.TopicPartition
	if rf, ok := ret.Get(0).(func() []kafka.TopicPartition); ok {
		r0 = rf()
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]kafka.TopicPartition)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func() error); ok {
		r1 = rf()
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}

// ReadMessage provides a mock function with given fields: timeout
func (_m KafkaConsumer) ReadMessage(timeout time.Duration) (*kafka.Message, error) {
	ret := _m.Called(timeout)

	var r0 *kafka.Message
	if rf, ok := ret.Get(0).(func(time.Duration) *kafka.Message); ok {
		r0 = rf(timeout)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(*kafka.Message)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(time.Duration) error); ok {
		r1 = rf(timeout)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}

// Subscribe provides a mock function with given fields: topic
func (_m KafkaConsumer) Subscribe(topic string) error {
	ret := _m.Called(topic)

	var r0 error
	if rf, ok := ret.Get(0).(func(string) error); ok {
		r0 = rf(topic)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
