Closed godolatry closed 4 years ago
Hey @godolatry would you mind making a small repo that reproduces this?
I reported this error more than three years ago. It would have been a whole lot easier to do what you’re asking back then.
Having given up with mock I found another Go mocking framework and used that. I found a couple of less important issues with that and the maintainer fixed them within about a day. If you want people to use this package, you need to react a tad faster.
If I can find the time I will look through my bug report and try to figure out what I did to provoke the error. It looks pretty self explanatory.
Regards
Simon
On Saturday, October 12, 2019, Cody Oss notifications@github.com wrote:
Hey @godolatry https://github.com/godolatry would you mind making a small repo that reproduces this?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/golang/mock/issues/49?email_source=notifications&email_token=ACD5L37AQZWE7H7WPU6XOB3QOIVHZA5CNFSM4CLKIV3KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBCHL3A#issuecomment-541357548, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACD5L35MJ7KZW6BMYYAGNK3QOIVHZANCNFSM4CLKIV3A .
Sorry that it has taken so long. I have just started to takeover maintaining this package this week and I am trying to triage all open issues and PRs no matter how old.
If you have the time I would appreciate it, but if not I understand and will close this out in a couple of weeks as it does not seem to have too many upvotes and I wonder if it might have been fixed since you last used the package. Thanks.
I'm having a problem with the -import mechanism in mockgen. I'm trying to set the name of a package which the mock is importing. I can't figure out how to do it.
When I create a mock with mockgen, it contains this import:
person "github.com/goblimey/films/models/person"
and the mock contains a method with a syntax error:
func (_m *MockDAO) Create(person person.Person) (person.Person, error) { ret := _m.ctrl.Call(m, "Create", person) ret0, := ret[0].(person.Person) // syntax error here ret1, _ := ret[1].(error) return ret0, ret1 }
The syntax error is
./MockDAO.go:76: person.Person undefined (type person.Person has no field or method Person)
This is caused by confusion between the variable person and the package person. I need the import line to be something like:
import ( personModel "github.com/goblimey/films/models/person"
So the import is called personModel, not person.
It looks as if I can fix this problem using -import when I run mockgen. However, when I do that, I still get the import line that provokes the error. In this example, I run the command and display the first ten lines that it produces:
$ mockgen -package mocks -source ../daos/people/DAO.go \ -imports 'personModel=github.com/goblimey/films/models/person' | head -10 // Automatically generated by MockGen. DO NOT EDIT! // Source: ../daos/people/DAO.go
package mocks
import ( person "github.com/goblimey/films/models/person" dbsession "github.com/goblimey/films/utilities/dbsession" gomock "github.com/golang/mock/gomock" )