Open maodou1990 opened 1 year ago
PrivateMethodStruct add two private methods:
func (this *PrivateMethodStruct) lastError() error{ return nil } func (this *PrivateMethodStruct) LastError() error{ return this.lastError() }
TestApplyPrivateMethod add test below:
Convey("patch private method return interface", func() { f := new(fake.PrivateMethodStruct) var s *fake.PrivateMethodStruct pErr := errors.New("error") patches := ApplyPrivateMethod(s, "lastError", func() error { return pErr }) defer patches.Reset() result := f.LastError() So(result, ShouldEqual, pErr) })
we got a panic: invalid memory address or nil pointer dereference
PrivateMethodStruct add two private methods:
TestApplyPrivateMethod add test below:
we got a panic: invalid memory address or nil pointer dereference