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

Doc: list all APIs equivalent between gomonkey and xgo #27

Open
xhd2015 opened this issue Apr 2, 2024 · 3 comments
Open

Doc: list all APIs equivalent between gomonkey and xgo #27

xhd2015 opened this issue Apr 2, 2024 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@xhd2015
Copy link
Owner

xhd2015 commented Apr 2, 2024

Since we are helping open projects migrating from gomonkey to xgo, see #18.
We need to draft a migration document.

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 2, 2024

Dot import : . "github.com/agiledragon/gomonkey/v2"
Can be removed

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 2, 2024

Patch reset:

p := gomonkey.NewPatches()
defer p.Reset()

Migration: Can be removed.

This is usually a clean up. Since xgo isolates mocks among different goroutines, and automatically clears when goroutine exit, there is no need to do this.

@xhd2015
Copy link
Owner Author

xhd2015 commented Apr 2, 2024

ApplyFuncReturn:

p = p.ApplyFuncReturn(prometheustimer.New, nil, errors.New(t.Name()))

Can be rewritten as:

mock.Mock(prometheustimer.New, func(ctx context.Context, fn *core.FuncInfo, args, results core.Object) error {
	return errors.New(t.Name())
})

Though seems longer, but the signature will not change. it's more obvious.

@xhd2015 xhd2015 changed the title Doc: list all APIs equivalent between gomonkey to xgo Doc: list all APIs equivalent between gomonkey and xgo Apr 2, 2024
@xhd2015 xhd2015 added the documentation Improvements or additions to documentation label May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant