matryer / moq

Interface mocking tool for go generate
http://bit.ly/meetmoq
MIT License
2k stars 127 forks source link

Ignored method parameters cause errors on generation #70

Closed heedson closed 4 years ago

heedson commented 6 years ago

When a parameter is _ *FooStruct then the generation of the mock creates invalid callInfo struct.

Take the example of some gRPC service parameters that could look like:

Foo(ctx context.Context, _ *types.Empty)

This will generate a callInfo that looks like:

    callInfo := struct {
        Ctx context.Context
        _   *types.Empty
    }{
        Ctx: ctx,
        _:   _,
    }

It also will then try to call the mock.FooFunc(ctx, _) which is also invalid.

What the desired result is to have any _ parameters ignore in the callInfo initialization stage (_: _, is invalid) and to replace the _ in the FooFunc call with a nil.

If this is to support it for other types too, it may get more complex when trying to assign it to the default value of the incoming type.

sudo-suhas commented 4 years ago

This has been fixed via #131 and Moq now correctly handles the scenario where one of the parameters is using the blank identifier.