Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
在这个PR中,我使用xgo替换了gomonkey。
xgo相对于gomonkey具有如下优点:
defer patch.Reset()
等代码c.Method
的形式,而不需要通过字符串指定方法名,更加健壮xgo的项目地址: https://github.com/xhd2015/xgo
使用xgo进行单测的步骤:
注: 由于我只替换了一部分用例,所以这里只运行受影响的那一部分函数。如果仓库作者觉得可行,我可以将它们全部替换掉
测试结果:
在这个PR中我只对部分函数进行了替换,主要是为了提升单测的可维护性。如果这个PR被认为可接受的话,我可以将所有剩余的mock全部替换为xgo,方便后面进行维护。