Skip to content

fix: 修复 config 测试因读取本机配置文件导致断言失败#62

Merged
riba2534 merged 1 commit intoriba2534:mainfrom
azbh111:fix/config-test-isolation
Mar 29, 2026
Merged

fix: 修复 config 测试因读取本机配置文件导致断言失败#62
riba2534 merged 1 commit intoriba2534:mainfrom
azbh111:fix/config-test-isolation

Conversation

@azbh111
Copy link
Copy Markdown
Contributor

@azbh111 azbh111 commented Mar 28, 2026

Summary

  • 修复 TestInit_DefaultValues 因读取本机配置文件导致断言失败

Background

本地环境有配置文件,运行测试用例时,会读取到配置文件的值,干扰用例结果。
TestInit_DefaultValues 测试默认配置值,但未隔离 HOME 目录。当开发者本机存在 ~/.feishu-cli/config.yaml 时,viper 会加载真实配置覆盖默认值,导致 BaseURL 等字段断言失败。测试结果取决于运行环境,不可复现。

Changes

文件 改动说明
internal/config/config_test.go 将 HOME 环境变量临时替换为 t.TempDir(),测试结束后恢复

Test Plan

常规检查

  • go build ./... 编译通过
  • go vet ./... 静态检查通过
  • go clean -testcache && go test ./... 全部测试通过(含此前失败的 TestInit_DefaultValues

变更用例

用例 变更说明
TestInit_DefaultValues 新增 HOME 隔离逻辑(+6 行),确保不读取真实配置文件,测试结果不依赖运行环境

TestInit_DefaultValues reads ~/.feishu-cli/config.yaml if it exists,
causing assertion failures on machines with a local config file.
Set HOME to a temp dir so the test is environment-independent.
@riba2534 riba2534 merged commit b513e28 into riba2534:main Mar 29, 2026
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.

2 participants