Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ApplyPrivateMethod return interface is invalid in 1.16 #118

Open
maodou1990 opened this issue Jan 17, 2023 · 0 comments
Open

ApplyPrivateMethod return interface is invalid in 1.16 #118

maodou1990 opened this issue Jan 17, 2023 · 0 comments

Comments

@maodou1990
Copy link

maodou1990 commented Jan 17, 2023

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

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

No branches or pull requests

1 participant