petergtz / pegomock

Pegomock is a powerful, yet simple mocking framework for the Go programming language
Apache License 2.0
254 stars 28 forks source link

chan direction being switched #79

Closed lkysow closed 5 years ago

lkysow commented 5 years ago

If I have an interface:

type MyInt interface{
     MyFunc() (<-chan string, <-chan error)
}

My mock ends up with:

func (mock *MockMyInt) MyFunc(l) (chan<- string, chan<- error) {
    if mock == nil {
        panic("mock must not be nil. Use myMock := NewMockClient().")
    }
    params := []pegomock.Param{log, path, args, v, workspace}
    result := pegomock.GetGenericMockFrom(mock).Invoke("RunCommandAsync", params, []reflect.Type{reflect.TypeOf((*chan<- string)(nil)).Elem(), reflect.TypeOf((*chan<- error)(nil)).Elem()})
    var ret0 chan<- string
    var ret1 chan<- error
    if len(result) != 0 {
        if result[0] != nil {
            ret0 = result[0].(chan<- string)
        }
        if result[1] != nil {
            ret1 = result[1].(chan<- error)
        }
    }
    return ret0, ret1
}

Which causes errors:

        have MyFunc() (chan<- string, chan<- error)
        want MyFunc() (<-chan string, <-chan error)
petergtz commented 5 years ago

@lkysow Looks like an ugly bug, yes. And you can tell that I'm not using channels very often ;-). Will check when I can work on this. Presumably sometime in the next 2 weeks. Meanwhile, feel free to provide a PR if you need it earlier. I'm happy to merge this.

Thanks for reporting this!

petergtz commented 5 years ago

@lkysow Okay, so you actually made me curious why this is not working :-D. And so I've fixed it right away. Can you please try the develop branch to see if it fixes your issues. If so, I'll make a new release on master with the change. Thanks.

lkysow commented 5 years ago

👍 haha thanks! I'll check it out and get back to you.

lkysow commented 5 years ago

I've confirmed that develop has the bug fixed.

petergtz commented 5 years ago

Cool. Thanks for confirming. Will release it on master over the next few days (no time right now :-( ).

lkysow commented 5 years ago

No rush, I have a workaround in place.

On Thu, Feb 28, 2019, 5:11 PM Peter Götz notifications@github.com wrote:

Cool. Thanks for confirming. Will release it on master over the next few days (no time right now :-( ).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/petergtz/pegomock/issues/79#issuecomment-468459468, or mute the thread https://github.com/notifications/unsubscribe-auth/AA_IvbLjonCFw5efbbGJmXZ9E6eZZ0SKks5vSFQggaJpZM4bS_vn .

petergtz commented 5 years ago

Released in v2.1.0. Closing.