[testify-expert] Improve Test Quality: pkg/workflow/safe_outputs_config_helpers_test.go

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

Maintainer thường phản hồi trong vòng 1 ngày

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

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
73/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
github-actions, go
Lĩnh vực
testing

Hướng nghiên cứu

Đọc pkg/workflow/safe_outputs_config_helpers_test.go cùng với pkg/workflow/safe_outputs_config_helpers.go; bắt đầu bằng cách thêm các trường hợp trực tiếp cho buildNormalizedSortedJSON và các trường hợp dạng bảng cho buildCustomSafeOutputJobsJSON. Chuyển TestUsesPatchesAndCheckouts sang safe_outputs_runtime_test.go theo yêu cầu. Hoàn tất khi các mục trong checklist được bao phủ và make test-unit chạy thành công.

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

Mô tả

automated-analysis code-quality cookie testing
Current State
  • Test file: pkg/workflow/safe_outputs_config_helpers_test.go (178 LOC, 3 test functions)
  • Source pair: pkg/workflow/safe_outputs_config_helpers.go (61 LOC; buildNormalizedSortedJSON, buildCustomSafeOutputJobsJSON)
  • Note: TestUsesPatchesAndCheckouts targets usesPatchesAndCheckouts in safe_outputs_runtime.go, not this file's source.
Strengths
  • Good table-driven TestUsesPatchesAndCheckouts covering nil, staged (global and per-handler), and mixed cases.
  • Uses require for preconditions and assert.JSONEq for JSON comparison.
Prioritized Improvements
1. Missing high-value tests
  • buildNormalizedSortedJSON has no direct test. Add table-driven cases: empty/nil names; name normalization (e.g. "my-job" → my_job); duplicate names that normalize to the same key (collapse to one); valueFn receiving the normalized name; deterministic output across repeated calls.
  • buildCustomSafeOutputJobsJSON: add a case for a single job, a job name with uppercase or special characters, and a nil Jobs map vs an empty map.
  • Move TestUsesPatchesAndCheckouts into safe_outputs_runtime_test.go to match its source file.
2. Testify assertion upgrades
Details
  • In TestBuildCustomSafeOutputJobsJSON, the trailing json.Unmarshal + assert.Empty(result[...]) is redundant with assert.JSONEq. Replace it with assert.Len(t, result, 2) or drop it. assert.Empty on a missing key also passes, so it proves nothing.
  • TestBuildCustomSafeOutputJobsJSONEmpty: use assert.Equal(t, "", ...) with messages, or make it table-driven.
  • Add messages to assertions that lack them.
3. Table-driven refactors
Details

Before:

assert.Empty(t, buildCustomSafeOutputJobsJSON(&WorkflowData{SafeOutputs: &SafeOutputsConfig{}}))
assert.Empty(t, buildCustomSafeOutputJobsJSON(&WorkflowData{SafeOutputs: nil}))

After:

tests := []struct{ name string; data *WorkflowData; want string }{
  {"nil safe outputs", &WorkflowData{}, ""},
  {"empty jobs", &WorkflowData{SafeOutputs: &SafeOutputsConfig{}}, ""},
  {"two jobs", &WorkflowData{SafeOutputs: &SafeOutputsConfig{Jobs: map[string]*SafeJobConfig{"z-job": {}, "a-job": {}}}}, `{"a_job":"","z_job":""}`},
}

Merge TestBuildCustomSafeOutputJobsJSON and ...Empty into one table with t.Run.

4. Organization/readability
Details
  • Split file by source (runtime vs config helpers).
  • Consider a small helper to build a staged BaseSafeOutputConfig to cut repeated templatableBoolPtr("true") literals.
Acceptance Checklist
  • Add direct tests for buildNormalizedSortedJSON
  • Merge the two buildCustomSafeOutputJobsJSON tests into one table
  • Remove redundant unmarshal assertions
  • Move TestUsesPatchesAndCheckouts next to its source
  • make test-unit passes

Generated by 🧪 Daily Testify Uber Super Expert · copilot · auto (Claude Sonnet 5.5) · ~15 AIC · ⌖ ~1 AIC · ⊞ 9.5K · ◷

  • expires on Nov 8, 2026, 10:05 AM UTC-08:00
Ngôn ngữ chính
Go
Star
5.6k
Fork
615
Merge trung bình
5 giờ 51 phút
Pull request đã merge (30 ngày)
793

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

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.

Issue khác của github/gh-aw

Tất cả issue của github/gh-aw

Issue tương tự

Thêm issue về Go

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.