Skip to content

ApplyPrivateMethod return interface is invalid in 1.16 #118

Open
@maodou1990

Description

@maodou1990

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions