mockery
mockery copied to clipboard
How to mock ... args ?
Hello, I want to setup and assert of ... parameters
in function.
for example, we have below interface and generated mock
// my interface
//go:generate mockery
type Member interface {
GetMembers(name ...string)
}
// in test, where Mock is generated from above interface
Mock.On("GetMembers", mock.AnythingOfType("????"))
then, is it possible to use mock.Anything or others regardless of argument numbers?
You'll have to know the exact number of expected arguments.
Matching is done like this:
// expected call
member.GetMembers("one")
// mock
memberMock.On("GetMembers", "one")
// With several arguments
members.GetMembers("one", "two")
// you have to provide the same number of arguments
memberMock.On("GetMembers", "one", mock.AnythingOfType("string"))
@zacscoding you could try my fork https://github.com/Laisky/mockery
I add .Catch
to catch by name with any arguments
How to handle this is described in https://vektra.github.io/mockery/notes/#variadic-arguments
Closing this ticket, but feel free to open another one (or just comment back here) if something is not clear.