This repository was archived by the owner on Jun 27, 2023. It is now read-only.
This repository was 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
Description
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)
}