[test-improver] Improve tests for config/rules package #381
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.
Test Improvements: rules_test.go
File Analyzed
internal/config/rules/rules_test.gointernal/config/rulesImprovements Made
1. Better Testing Patterns
✅ Converted manual error checking to testify assertions
t.Errorf()andifchecks with idiomatic testify assertionsrequire.NotNil()for critical error checks that should stop the testassert.Contains(),assert.Equal(),assert.NotEmpty()for clearer assertions✅ Added testify/require import
requirefor error existence checks - test should stop if no error when expectedassertfor field validation - test can continue checking other fields✅ Improved assertion clarity
assert.NotEmpty()instead of checking== "")2. Code Reduction & Clarity
Before:
ifstatementsAfter:
Improvement: -76 lines (-12%), significantly more concise and readable
3. Specific Improvements by Test
TestPortRange
require.NotNil()for error existence (stops test early if no error)assert.Contains()for error message validationassert.Equal()for JSONPath validationTestTimeoutPositive
require.NotNil()for error existenceassert.Contains()for error message validationassert.Equal()for JSONPath and Field validationTestMountFormat
require.NotNil()for error existenceassert.Contains()for error message validationassert.Equal()for JSONPath pattern validationTestValidationError_Error
assert.Contains()for substring checksTestUnsupportedType
assert.Equal()for exact field matchingassert.Contains()for partial string matchingTestUndefinedVariable
assert.Equal()for field validationassert.Contains()for message and suggestion checksTestMissingRequired
assert.Equal()for all exact matchesassert.Contains()for message validationTestUnsupportedField
assert.Equal()for all field comparisonsassert.Contains()for substring validationTestAppendConfigDocsFooter
assert.Contains()for substring checksTestDocumentationURLConstants
assert.NotEmpty()instead of manual empty checksassert.True()with clear boolean expressionsTest Execution
All tests maintain the same behavior with improved assertions:
go test -v ./internal/config/rules/...Statistics:
Why These Changes?
This test file was selected because:
ifstatements with similar patternsThe improvements make tests:
Before/After Example
Before
After
Generated by Test Improver Workflow
Focuses on better testify patterns, reduced code, and cleaner assertions