Skip to content

Instantly share code, notes, and snippets.

@rgarcia
Created March 14, 2016 21:21
Show Gist options
  • Save rgarcia/cf553169c4832543a0a9 to your computer and use it in GitHub Desktop.
Save rgarcia/cf553169c4832543a0a9 to your computer and use it in GitHub Desktop.
mocking a vendored dependency
// $GOPATH/src/a/vendor/b/b.go
package b
import "log"
type Type int
type Interface interface {
InterfaceMethod(Type)
}
type Implementation struct {
}
func (b Implementation) InterfaceMethod(Type) {
log.Println("in b implementation")
}
// Automatically generated by MockGen. DO NOT EDIT!
// Source: b (interfaces: Interface)
package mock_b
import (
b "b"
gomock "github.com/golang/mock/gomock"
)
// Mock of Interface interface
type MockInterface struct {
ctrl *gomock.Controller
recorder *_MockInterfaceRecorder
}
// Recorder for MockInterface (not exported)
type _MockInterfaceRecorder struct {
mock *MockInterface
}
func NewMockInterface(ctrl *gomock.Controller) *MockInterface {
mock := &MockInterface{ctrl: ctrl}
mock.recorder = &_MockInterfaceRecorder{mock}
return mock
}
func (_m *MockInterface) EXPECT() *_MockInterfaceRecorder {
return _m.recorder
}
func (_m *MockInterface) InterfaceMethod(_param0 b.Type) {
_m.ctrl.Call(_m, "InterfaceMethod", _param0)
}
func (_mr *_MockInterfaceRecorder) InterfaceMethod(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "InterfaceMethod", arg0)
}
// $GOPATH/src/a/main.go
package main
import "b"
func main() {
bobj := b.Implementation{}
var btyp b.Type
bobj.InterfaceMethod(btyp)
}
@rgarcia
Copy link
Author

rgarcia commented Mar 14, 2016

bmocks.go generated by mockgen -destination bmocks.go b Interface from this PR golang/mock#28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment