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

util/gconv: refactor code unit testing #3591

Merged
merged 47 commits into from
May 20, 2024

Conversation

oldme-git
Copy link
Member

@oldme-git oldme-git commented May 19, 2024

Dear review:
gconv 是一个相当重要和强大的组件,但是其单测质量较差,这也是整个框架的弊病。本次 PR 重构了 gconv 的单元测试,使用更优雅更有趣的代码风格,且 codecov 覆盖率提高约 2%,达到 87.86%

此外,在重构单测时发现 gconv 组件“年久失修”,不仅仅代码质量差,其中的一些设计也不够优雅,风格也不统一。比如 gconv.Map 的调用链是 Map->doMapConvert,而 gconv 的调用链是 gconv.Struct ->gconv.Scan -> gconv.doStruct。私以为,他们应该有着统一的调用链,比如 gconv.Map->gconv.doMapgconv.Struct ->gconv.doStruct,而 gconv.Scan 应该只作用一次类型断言,根据 dstPointer 将请求转发到 doMap 或者 doStruct,不应该承担其他更多的逻辑。代码逻辑混乱也是单测覆盖率难以提高到 90% 以上的重要原因。单测的重构也为 gconv 的日后改进提供了重要的基础。

原来的单测:
image
image

重构后:
image
image

@oldme-git oldme-git requested review from gqcn, huangqian1985, houseme, hailaz and wln32 and removed request for gqcn and huangqian1985 May 19, 2024 07:15
@gqcn gqcn merged commit a9a0785 into gogf:master May 20, 2024
23 checks passed
@oldme-git oldme-git deleted the enhance/unittest/gconv branch May 20, 2024 13:01
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

Successfully merging this pull request may close these issues.

None yet

3 participants