TestDeleteContext fails when cmd/testdata directory is missing
まだ誰も着手していません。
評価
調査の方向性
cmd/context_test.go の TestDeleteContext から始め、testConfigFilePath がどのように使われているかを確認します。go test ./... を実行して、cmd/testdata が存在しないことによる失敗を再現し、その後、テストが分離された一時的な場所を使用し、リポジトリ固有のディレクトリがない新しい checkout で成功することを確認します。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
While running the test suite with go test ./..., the TestDeleteContext test fails because it tries to write/read a config file at ./testdata/local.config. However, the cmd/testdata directory does not exist in a fresh clone, causing the test to fail with:
open ./testdata/local.config: no such file or directory
This makes the test dependent on a manually existing local directory instead of being fully self-contained.
Expected behavior
go test ./... should pass on a fresh clone without requiring the cmd/testdata directory to already exist. The test should create any temporary files or directories it needs during execution.
Actual behavior
The test suite fails in TestDeleteContext:
--- FAIL: TestDeleteContext (0.00s)
context_test.go:44:
Error: Received unexpected error:
open ./testdata/local.config: no such file or directory
How to Reproduce?
- Clone the repository fresh:
git clone https://github.com/microcks/microcks-cli.git - Change into the directory:
cd microcks-cli - Run the test suite:
go test ./... - Observe the failure in
cmd/context_test.goatTestDeleteContext.
Microcks version or git rev
No response
Install method (docker-compose, helm chart, operator, docker-desktop extension,...)
No response
Additional information
Root cause. cmd/context_test.go declares a hardcoded path:
const testConfigFilePath = "./testdata/local.config"
and then calls os.WriteFile(testConfigFilePath, ...). os.WriteFile does not create parent directories, and .gitignore excludes **/testdata/**, so the cmd/testdata/ directory does not exist on a clean clone.
Proposed fix. Use Go's t.TempDir() so the test creates an isolated, auto-cleaned temporary directory on every run:
testConfigFilePath := filepath.Join(t.TempDir(), "local.config")
This makes the test self-contained, removes the dependency on repository-local folders, and prevents state leakage between consecutive runs.
I would like to work on this issue if the maintainers agree with the proposed approach. I can send a small PR that updates the test to use t.TempDir().
- 主要言語
- Go
- スター
- 52
- フォーク
- 67
- 平均マージ
- 1日 1時間
- マージ済み PR(30日)
- 13
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microcks/microcks-cli のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
microcks/microcks-cli#536 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
microcks/microcks-cli#535 ·
-
component/cli keep-open kind/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
microcks/microcks-cli#534 · コメント 2 件 · リアクション 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
microcks/microcks-cli#511 ·
-
component/cli kind/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
microcks/microcks-cli#503 · コメント 4 件 ·
microcks/microcks-cli の issue をすべて見る
似ている issue
-
kind/bug needs-triage
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
matrixorigin/matrixone#29223 ·
-
needs-acceptance wg/data-plane-networking
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
vllm-project/semantic-router#4024 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
alexgorbatchev/dotfiles#107 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 84/100