I have some code, for instance:
type FileFilter func(*models.File) bool
func ByExtension(ext string) FileFilter {
return func(file *models.File) bool {
// it's just an example do not blame here :)
return true
}
}
type FileManager interface {
ReadAllBy(ctx context.Context, path models.Path, filters ...FileFilter) ([]*models.File, error)
}
func Service() {
// do smth (get struct which implements FileManager interface)
fileManger.ReadAllBy(ctx, path", ByExtension("log"))
// do smth
}
And I want to test Service
function.
I use testify
lib and mockery
for generate mocks.
Is it possible to check that I pass correct filters in ReadAllBy
method?
This is a piece of my unittest:
fileManagerMock.EXPECT().
ReadAllBy(params.ctx, path, mock.AnythingOfType("FileFilter")).Return(files, nil)
This test works, but it will not fail i pass wrong FilterFilter
opt.