golang / mock

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

Mockgen imports not working #13

Closed gudladona closed 8 years ago

gudladona commented 8 years ago

mockgen with Imports flag does not generate the mocked file correctly.

mockgen -source ../iam/types/apis.go -destination cmd/iam_mock.go -package iam -imports iamTypes=git.nexgen.neustar.biz/IAS/iam/types

// Automatically generated by MockGen. DO NOT EDIT! // Source: ../iam/types/apis.go

package iam

import ( gomock "github.com/golang/mock/gomock" )

// Mock of UserApi interface type MockUserApi struct { ctrl gomock.Controller recorder _MockUserApiRecorder }

// Recorder for MockUserApi (not exported) type _MockUserApiRecorder struct { mock *MockUserApi }

func NewMockUserApi(ctrl gomock.Controller) MockUserApi { mock := &MockUserApi{ctrl: ctrl} mock.recorder = &_MockUserApiRecorder{mock} return mock }

func (_m MockUserApi) EXPECT() _MockUserApiRecorder { return _m.recorder }

func (_m *MockUserApi) CreateUser(user IAMUser) (IAMUser, error) { ret := _m.ctrl.Call(m, "CreateUser", user) ret0, := ret[0].(IAMUser) ret1, _ := ret[1].(error) return ret0, ret1 }

func (_mr _MockUserApiRecorder) CreateUser(arg0 interface{}) gomock.Call { return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateUser", arg0) }

// Mock of OrganizationApi interface type MockOrganizationApi struct { ctrl gomock.Controller recorder _MockOrganizationApiRecorder }

// Recorder for MockOrganizationApi (not exported) type _MockOrganizationApiRecorder struct { mock *MockOrganizationApi }

func NewMockOrganizationApi(ctrl gomock.Controller) MockOrganizationApi { mock := &MockOrganizationApi{ctrl: ctrl} mock.recorder = &_MockOrganizationApiRecorder{mock} return mock }

func (_m MockOrganizationApi) EXPECT() _MockOrganizationApiRecorder { return _m.recorder }

func (_m *MockOrganizationApi) CreateOrganization(org IAMOrganization) (IAMOrganization, error) { ret := _m.ctrl.Call(m, "CreateOrganization", org) ret0, := ret[0].(IAMOrganization) ret1, _ := ret[1].(error) return ret0, ret1 }

func (_mr _MockOrganizationApiRecorder) CreateOrganization(arg0 interface{}) gomock.Call { return _mr.mock.ctrl.RecordCall(_mr.mock, "CreateOrganization", arg0) }

dsymonds commented 8 years ago

Can you be more specific? What's generated incorrectly?

Does it work better in "reflect mode"? (run mockgen -help)

gudladona commented 8 years ago

Even after i specify the "-imports iamTypes=git.nexgen.neustar.biz/IAS/iam/types" in import flag it does not generate/include the import. I did not understand the usage of "reflect mode". Could you please give me an example of the usage ?

gudladona commented 8 years ago

Understood the usage of reflect mode. Mocks are generated correctly. Closing the issue.

Example Usage for my case:

mockgen -package=cmd -destination=cmd/iam_mock.go git.nexgen.neustar.biz/IAS/iam/types UserApi,OrganizationApi