gojuno / minimock

Powerful mock generation tool for Go programming language
MIT License
577 stars 38 forks source link

Generated invalid mock file when return type is channel #41

Closed massanchik closed 4 years ago

massanchik commented 4 years ago

Hi! I have interface like this

type Consumer interface {
    GetDone() chan error
        ...
}

And when generated mock file with minimock -i .Consumer

Inside it have funcGetDone func() (ch1 error) func (mmGetDone *mConsumerMockGetDone) Return(ch1 error) *ConsumerMock func (mmGetDone *mConsumerMockGetDone) Set(f func() (ch1 error)) *ConsumerMock func (mmGetDone *ConsumerMock) GetDone() (ch1 error)

Which breaks interface requirements

As a temporary workaround, you can break method into two like this:

GetDoneWrite() chan<- error
GetDoneRead() <-chan error

Then it can generate right signatures funcGetDoneRead func() (ch1 <-chan error) funcGetDoneWrite func() (ch1 chan<- error)

hexdigest commented 4 years ago

Hi @massanchik

Thanks for posting the bug! Please check out the latest v3.0.2 release and see if it works for you.

sieuwerts commented 4 years ago

I'm using v3.0.6 and this bug is still active.

Trying to generate mock for method with return arguments (chan MyType, error) will result in a generated method returning (MyType, error)

beono commented 4 years ago

Hi,

As @sieuwerts mentioned it wasn't fixed. Some of my colleges also faced this issue and I hope I got the solution here https://github.com/hexdigest/gowrap/pull/25