withmock icon indicating copy to clipboard operation
withmock copied to clipboard

Issues with mocking packages that have mix of ref and copy funcs

Open joesustaric opened this issue 10 years ago • 0 comments

To reproduce this try the following.

File Testpack\testpack.go:

package testpack

type TPStruct struct {}
//func (t TPStruct) Method() {}  //Uncomment this line to produce error
func (t *TPStruct) PointerMethod() 

file wmscratch\wmscratch.go:

package wmscratch

import "testpack"

func PointerFunction(t *testpack.TPStruct) {
    t.PointerMethod()
}

Test file Wmscratch\wmscratch_test.go:

package wmscratch

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

func TestSumSqrt(t *testing.T) {
    ctrl := gomock.NewController(t)
    defer ctrl.Finish()

    testpack.MOCK().SetController(ctrl)

    tp := testpack.TPStruct{}
    tp_ptr := &tp

    tp_ptr.EXPECT().PointerMethod()
    PointerFunction(tp_ptr)

}

Uncommenting the func (t TPStruct) Method() {} in the TPStruct package:

controller.go:113: no matching expected call: *testpack.TPStruct.PointerMethod([])
controller.go:158: missing call(s) to testpack.TPStruct.PointerMethod()

joesustaric avatar Oct 20 '15 22:10 joesustaric