Improve test quality in format_preservation_test.go with testify assertions and table-driven tests #10552
+384
−59
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.
The test file used manual error checking (
if err != nil { t.Fatalf() }) instead of testify assertions, lacked edge case coverage, and tested only a single scenario.Changes
require.NoError()andassert.Contains()with descriptive messagesTestFormatPreservationSubtestsgrouping assertions by concern (comments, whitespace, indentation, source field, content structure)fmt.Printfstatements for clean test executionExample
Before:
After:
Impact: 1 scenario → 16 test cases with comprehensive edge case coverage and clear failure messages.
Original prompt
This section details on the original issue you should resolve
<issue_title>[testify-expert] Improve Test Quality: pkg/cli/format_preservation_test.go</issue_title>
<issue_description>## Overview
The test file
pkg/cli/format_preservation_test.gohas been selected for quality improvement by the Testify Uber Super Expert. This issue provides specific, actionable recommendations to enhance test quality, coverage, and maintainability using testify best practices. The file currently uses manual error checking instead of testify assertions and would benefit from table-driven tests and better organization.Current State
pkg/cli/format_preservation_test.gopkg/cli/add_command.go(961 lines)TestFormatPreservationManual)addSourceToWorkflow(content, source string) (string, error)Test Quality Analysis
Strengths ✅
Areas for Improvement 🎯
1. Testify Assertions
Current Issues:
if err != nil { t.Fatalf() }instead ofrequire.NoError(t, err)if !strings.Contains() { t.Error() }instead ofassert.Contains(t, result, expected)Recommended Changes:
Why this matters: Testify provides clearer error messages, better test output, and is the standard used throughout this codebase (see
specs/testing.md). Theassert.Containsmethod will show the actual vs expected content on failure.Example from codebase: See
pkg/cli/actions_build_command_test.go:16for good testify usage:2. Table-Driven Tests
Current Issues:
Recommended Changes: