I'm having a problem with the -import mechanism in mockgen. I opened an
issue on the gomock github page five days ago, but nobody has responded.
I'm using gomock to generate static mocks. One of my generated mocks is
throwing a syntax error. To fix this, 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 my mock with mockgen, it contains this import:
person "github.com/goblimey/films/models/person"
The mock includes this method. The syntax error is on the line that I've
marked with a comment:
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 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.
According to the documentation 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"
)
Does anybody know how to make the -import flag of gomock do what I need?
(For the benefit of IDE lovers: the first line iin the example s a command
that I type into a terminal window. The rest is the response.)
(For the benefit of MS Windows users, this is a UNIX command. I'm using
the head command to take the output from gomock and display only the first
few lines.)
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.