// Code generated by mockery v0.0.0-dev. DO NOT EDIT.

package mocks

import (
	context "context"
	fs "io/fs"

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

	testing "testing"
)

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

// Close provides a mock function with given fields: ctx
func (_m *File) Close(ctx context.Context) error {
	ret := _m.Called(ctx)

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

	return r0
}

// Read provides a mock function with given fields: ctx, buf
func (_m *File) Read(ctx context.Context, buf []byte) (int, error) {
	ret := _m.Called(ctx, buf)

	var r0 int
	if rf, ok := ret.Get(0).(func(context.Context, []byte) int); ok {
		r0 = rf(ctx, buf)
	} else {
		r0 = ret.Get(0).(int)
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(context.Context, []byte) error); ok {
		r1 = rf(ctx, buf)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}

// ReadDir provides a mock function with given fields: ctx, n
func (_m *File) ReadDir(ctx context.Context, n int) ([]fs.FileInfo, error) {
	ret := _m.Called(ctx, n)

	var r0 []fs.FileInfo
	if rf, ok := ret.Get(0).(func(context.Context, int) []fs.FileInfo); ok {
		r0 = rf(ctx, n)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).([]fs.FileInfo)
		}
	}

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

	return r0, r1
}

// Stat provides a mock function with given fields: ctx
func (_m *File) Stat(ctx context.Context) (fs.FileInfo, error) {
	ret := _m.Called(ctx)

	var r0 fs.FileInfo
	if rf, ok := ret.Get(0).(func(context.Context) fs.FileInfo); ok {
		r0 = rf(ctx)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(fs.FileInfo)
		}
	}

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

	return r0, r1
}

// NewFile creates a new instance of File. It also registers a cleanup function to assert the mocks expectations.
func NewFile(t testing.TB) *File {
	mock := &File{}

	t.Cleanup(func() { mock.AssertExpectations(t) })

	return mock
}
