microcks / microcks/microcks-cli

TestDeleteContext fails when cmd/testdata directory is missing

Đang mở Phù hợp với người mới
#321 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Go
Star
52
Fork
68
Merge trung bình
6 giờ 54 phút
Pull request đã merge (30 ngày)
10

Mô tả

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.

Image
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?
  1. Clone the repository fresh: git clone https://github.com/microcks/microcks-cli.git
  2. Change into the directory: cd microcks-cli
  3. Run the test suite: go test ./...
  4. Observe the failure in cmd/context_test.go at TestDeleteContext.
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().

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong cmd/context_test.go tại TestDeleteContext và kiểm tra cách testConfigFilePath được sử dụng. Chạy go test ./... để tái hiện lỗi do thiếu cmd/testdata, sau đó xác minh rằng test sử dụng một vị trí tạm thời biệt lập và chạy thành công trên một checkout mới không có các thư mục cục bộ của repository.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
go
Lĩnh vực
cli, testing
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
84/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.