-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
refactor(util/gconv): refactor code unit testing #3591
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
oldme-git
requested review from
gqcn,
huangqian1985,
houseme,
hailaz and
wln32
and removed request for
gqcn and
huangqian1985
May 19, 2024 07:15
wln32
approved these changes
May 19, 2024
gqcn
changed the title
util/gconv: refactor code unit testing
refactor(util/gconv): refactor code unit testing
Jun 26, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Dear review:
gconv
是一个相当重要和强大的组件,但是其单测质量较差,这也是整个框架的弊病。本次PR
重构了gconv
的单元测试,使用更优雅更有趣的代码风格,且codecov
覆盖率提高约2%
,达到87.86%
。此外,在重构单测时发现
gconv
组件“年久失修”,不仅仅代码质量差,其中的一些设计也不够优雅,风格也不统一。比如gconv.Map
的调用链是Map->doMapConvert
,而gconv
的调用链是gconv.Struct ->gconv.Scan -> gconv.doStruct
。私以为,他们应该有着统一的调用链,比如gconv.Map->gconv.doMap
,gconv.Struct ->gconv.doStruct
,而gconv.Scan
应该只作用一次类型断言,根据dstPointer
将请求转发到doMap
或者doStruct
,不应该承担其他更多的逻辑。代码逻辑混乱也是单测覆盖率难以提高到90%
以上的重要原因。单测的重构也为gconv
的日后改进提供了重要的基础。原来的单测:
重构后: