0

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.

Mike
  • 860
  • 14
  • 24
  • What does "it will not fail i pass wrong FilterFilter opt" mean? You're passing a mock, what would a "wrong" mock be? – Adrian Sep 28 '22 at 21:15
  • I'm not passing mock. I'm passing opt to some method, which is mock in unittest – Mike Sep 29 '22 at 06:34

0 Answers0