Skip to content

test: 补齐核心包与 cmd 纯函数单测,新增无依赖 test CI - #10

Merged
kugouming merged 1 commit into
mainfrom
test/coverage-unit-tests
Sep 10, 2026
Merged

test: 补齐核心包与 cmd 纯函数单测,新增无依赖 test CI#10
kugouming merged 1 commit into
mainfrom
test/coverage-unit-tests

Conversation

@kugouming

@kugouming kugouming commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • 新增 13 个测试文件、扩充 3 个,测试代码 794 → 2387 行,零外部依赖(纯函数 + 接口 mock + t.TempDir()),让 go test ./... 成为可信回归网
  • 核心包覆盖:internal/s3path 100%config 89.5%(补 Resolve 全分支:默认 profile 回退/env 展开与覆盖/path-style 强制 true/缺 key 报错)、uploader 82.1%client 52.8%view 纯函数全覆盖
  • cmd 覆盖 syncNeed 同步决策、matchFind 四类过滤、deriveDstKey、buildTree、headLinesFromReader、parseS3、humanBytes 等
  • 新增 CI .github/workflows/test.yml:每次 push/PR 自动 go vet + go test ./...(stable/oldstable);此前唯一 CI 仅 release.yml 发布用、不跑任何测试

最小生产代码重构(行为不变)

  • internal/uploader:Uploader.s3 字段由 *s3.Client 改为 manager.UploadAPIClient 接口以支持 mock;抽出 buildKey 纯函数

Test plan

  • make test(go vet + go test ./...)全部通过
  • go test -race 通过
  • CI test.yml 于 push 后自动执行

Closes #9

新增 13 个测试文件、扩充 3 个,测试代码 794 → 2387 行,零外部依赖
(纯函数 + 接口 mock + t.TempDir),为 go test ./... 建立可信回归网:
- internal/s3path 达 100% 覆盖;config 补 Resolve 全分支(默认 profile
  回退/env 展开与覆盖/path-style 强制 true/缺 key 报错)
- internal/view 覆盖格式探测、suffix Range、内容嗅探不丢字节、readBounded
- internal/uploader 覆盖上传路径(s3 字段改 manager.UploadAPIClient 接口
  以便 mock,抽 buildKey 纯函数),连同 client.xmlTimeNormalizer(aws.HTTPClient
  stub)覆盖全部规范化分支
- cmd 覆盖 syncNeed 决策、matchFind 过滤、deriveDstKey、buildTree、
  headLinesFromReader、parseS3、humanBytes 等

修复 uploader 中 partSize 常量未被引用等既有警告问题一并纳入。
新增 .github/workflows/test.yml:每次 push/PR 自动 go vet + go test(stable/
oldstable),此前唯一 CI 仅 release.yml 发布用、不跑任何测试。
@kugouming
kugouming force-pushed the test/coverage-unit-tests branch from f75492d to ddc71b7 Compare September 10, 2026 00:46
@kugouming
kugouming merged commit a864c41 into main Sep 10, 2026
2 checks passed
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.

补齐核心包与 cmd 纯函数单元测试覆盖

1 participant