Closed preslavmihaylov closed 4 years ago
@preslavmihaylov I just tried to reproduce this in https://github.com/codyoss/bar No error for me. Can you provide more details?
# reinstall latest mockgen version
rm -rf $GOPATH/bin/mockgen
go install github.com/golang/mock/mockgen
# make new go modules project
cd playground
go mod init github.com/preslavmihaylov/playground
# run mockgen
mockgen -destination=mockhttp.go -package=mockhttp net/http RoundTripper
@preslavmihaylov I also tried your steps and no error for me. Just worked. Can you give me your go version
and go env
go version:
go version go1.13 darwin/amd64
go env:
Unfortunately, mockgen doesn't output any version information, but I ran the commands listed in the issue description.
I am sorry I am still on able to reproduce this. I will leave it open though to see if anyone else can. Only thing I can think of is if the version of mockgen is actually older and not actually located in $GOPATH/bin/mockgen
. If you do a which mockgen
is it actually found at $GOPATH/bin/mockgen
? You could also try got get -u
to make sure you are pulling in the latest. I wonder if install will just re-pull the old installed version in module land. The module wiki suggests a global mod to keep track of installed tools and versions.
To make sure I'm using latest version I tried git cloning `https://github.com/golang/mock', and manually building mockgen from there:
go build ./mockgen/mockgen.go ./mockgen/parse.go ./mockgen/reflect.go
It still outputs the same error.
In the error, there is a line open /usr/local/Cellar/go/1.13/libexec...
.
Perhaps this has something to do with go being installed via brew or Mac installer?
Maybe, my installation is from golang.org/dl. If I clone master, use the same build command, it works for me.
I was able to reproduce this after I installed go via brew... will try to look in further later. I assume so env var needs to be properly set to make this all happy, but I am not sure.
My best advice here is to install Go from https://golang.org/dl/ instead on Homebrew. This seems like an issue related to how Homebrew links some dirs on install or improperly setting environment variables. After I reinstalled from the link above everything just works. Closing as I don't think this is a problem with the actual project.
How to reproduce:
mockgen -destination=mockhttp.go -package=mockhttp net/http RoundTripper
Detailed steps:
Result:
The output file is still generated and looks correct, though.
mockhttp.go
``` // Code generated by MockGen. DO NOT EDIT. // Source: net/http (interfaces: RoundTripper) // Package mockhttp is a generated GoMock package. package mockhttp import ( gomock "github.com/golang/mock/gomock" http "net/http" reflect "reflect" ) // MockRoundTripper is a mock of RoundTripper interface type MockRoundTripper struct { ctrl *gomock.Controller recorder *MockRoundTripperMockRecorder } // MockRoundTripperMockRecorder is the mock recorder for MockRoundTripper type MockRoundTripperMockRecorder struct { mock *MockRoundTripper } // NewMockRoundTripper creates a new mock instance func NewMockRoundTripper(ctrl *gomock.Controller) *MockRoundTripper { mock := &MockRoundTripper{ctrl: ctrl} mock.recorder = &MockRoundTripperMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use func (m *MockRoundTripper) EXPECT() *MockRoundTripperMockRecorder { return m.recorder } // RoundTrip mocks base method func (m *MockRoundTripper) RoundTrip(arg0 *http.Request) (*http.Response, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RoundTrip", arg0) ret0, _ := ret[0].(*http.Response) ret1, _ := ret[1].(error) return ret0, ret1 } // RoundTrip indicates an expected call of RoundTrip func (mr *MockRoundTripperMockRecorder) RoundTrip(arg0 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RoundTrip", reflect.TypeOf((*MockRoundTripper)(nil).RoundTrip), arg0) } ```
If the executed command is:
There is no error and the output file is the same
Reproduced with latest released
v1.3.1