Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

mockgen: does not handle types if mocks are in test package #247

Closed
poy opened this issue Dec 5, 2018 · 1 comment · Fixed by #248
Closed

mockgen: does not handle types if mocks are in test package #247

poy opened this issue Dec 5, 2018 · 1 comment · Fixed by #248

Comments

@poy
Copy link
Collaborator

poy commented Dec 5, 2018

It looks like mockgen doesn't attach the package name to a type if the package is set (via --package).

Example:

Notice in mock_test.go any usage of User does not have the package name users.

user.go

package users

type User struct {
	Name string
}

type Finder interface {
	FindUser(name string) User
}
mockgen --source=user.go --destination=mock_test.go --package=users_test

mock_test

// Code generated by MockGen. DO NOT EDIT.
// Source: user.go

// Package users_test is a generated GoMock package.
package users_test

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

// MockFinder is a mock of Finder interface
type MockFinder struct {
	ctrl     *gomock.Controller
	recorder *MockFinderMockRecorder
}

// MockFinderMockRecorder is the mock recorder for MockFinder
type MockFinderMockRecorder struct {
	mock *MockFinder
}

// NewMockFinder creates a new mock instance
func NewMockFinder(ctrl *gomock.Controller) *MockFinder {
	mock := &MockFinder{ctrl: ctrl}
	mock.recorder = &MockFinderMockRecorder{mock}
	return mock
}

// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockFinder) EXPECT() *MockFinderMockRecorder {
	return m.recorder
}

// FindUser mocks base method
func (m *MockFinder) FindUser(name string) User {
	ret := m.ctrl.Call(m, "FindUser", name)
	ret0, _ := ret[0].(User)
	return ret0
}

// FindUser indicates an expected call of FindUser
func (mr *MockFinderMockRecorder) FindUser(name interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FindUser", reflect.TypeOf((*MockFinder)(nil).FindUser), name)
}
@poy
Copy link
Collaborator Author

poy commented Dec 5, 2018

Related #207

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant