golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.3k stars 611 forks source link

v1.0.1 introduces breaking changes #166

Closed JeremyLoy closed 6 years ago

JeremyLoy commented 6 years ago

The latest release of v1.0.1 broke our CI builds. It seems that Mockgen no longer honors the vendor folder, and instead only looks in your GOROOT and GOPATH.

Usage (go generate command at the top of a source file):

//go:generate mockgen -source=file.go -package mypackage -destination file_mock.go

file.go imports bcrypt

Example error message (bcrypt exists in the vendor folder):

2018/04/04 10:35:52 failed to import package by path golang.org/x/crypto/bcrypt: cannot find package "golang.org/x/crypto/bcrypt" in any of:
        /usr/local/opt/go/libexec/src/golang.org/x/crypto/bcrypt (from $GOROOT)
        /Users/me/.go/src/golang.org/x/crypto/bcrypt (from $GOPATH) - fallback to import path suffix

Rolling back to v1.0.0 resolves the issue (using something like retool or manually checking out and building mockgen from source)

Here is a diff of v1.0.0 to v1.0.1. It seems like a lot more was done than just a 'patch' according to semantic versioning as new features were added.

v1.0.1 should really be v1.1.0.

If no longer honoring the vendor folder is intentional v1.0.0 should be marked v2.0.0.

dgoodwin commented 6 years ago

Hitting this as well in another project as a result of picking up the new version of gomock, appears to be the same situation, not finding vendored code.

balshetzer commented 6 years ago

You're right: v1.0.1 should have been v1.1.0. Also, the regression is not intentional. I'll look into it right away. It would help if someone could show me a full test case.

I'm also a little confused by the error output. You're saying that mockgen runs successfully but then the output doesn't compile? Can you show me what the old and new imports in the mock look like? Also, what is the directory structure like?

JeremyLoy commented 6 years ago

@balshetzer Using the exact same checkout of our project code:

The directory structure is the standard project layout

balshetzer commented 6 years ago

OK, I've been able to replicate the issue. It looks like what's broken is mocking interfaces with vendored packages using "source mode" in mockgen. We only had a test for "reflect mode". I've added the test for source mode and will check it in as soon as I have a fix.

dgoodwin commented 6 years ago

Thanks @balshetzer !

balshetzer commented 6 years ago

I've narrowed down the breaking change to: https://github.com/golang/mock/commit/bdab6673987ac44bb2e2d2ab121f7c6d46640bc4

JeremyLoy commented 6 years ago

@balshetzer that was incredibly fast, thank you for your work! Our builds are now succeeding with the new v1.1.0.