Opencode refine#9
Open
doombeaker wants to merge 2 commits into
Open
Conversation
…t 2. 清理重复验证 + Argument 解耦
This file contains hidden or 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
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.
添加测试用例 & 重构架构以提升可扩展性
背景
项目此前零测试覆盖,且
lib/层与 CLI 框架(urfave/cli)紧耦合,导致后续增加新功能(如 API 调用入口、SDK 接入)困难。变更内容
1. 添加测试用例(68 个测试,核心模块全覆盖)
新增测试文件覆盖纯函数、验证逻辑、YAML 配置解析,以及基于
httptest的 HTTP Client 模拟测试:lib/version_test.golib/errors_test.golib/format/bytes_test.golib/validation_test.golib/client_test.goconfig/yaml_config_test.go新增
make test目标。2. 解耦
lib/与 CLI 框架(P0)lib/client.go:22 处cli.Exit()→ 纯fmt.Errorf()/meta.ErrNolib/folder.go:7 处cli.Exit()→ 纯fmt.Errorf()lib/和config/不再 importurfave/clicmd/层3. 提取
BizyAPI接口 + 共享http.Client(P1)lib/client.go新增BizyAPI接口(16 个方法),Client自动满足该接口Client结构体改用共享http.Client,带连接池(此前每次请求新建http.Transport)lib/actions/接受BizyAPI接口而非具体*Client,支持注入 mock 进行单元测试UploadOptions.Client和UploadCover参数从*Client改为BizyAPI4. 清理重复验证 + Argument 解耦(P2)
lib/validate/包(与lib/validation.go重复)EnsureAbsPath()合并到lib/validation.goArgument.Parse()从config/移至cmd/args.go,移除config/对urfave/cli的依赖影响范围
28 个文件变更:+1,454 行,−317 行
验证
go build ./...编译通过go test ./lib/... ./config/...— 68 个测试全部 PASSlib/和config/不再依赖urfave/cli