[test-improver] Improve tests for config package #413
Merged
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: validation_test.go
File Analyzed
internal/config/validation_test.gointernal/configImprovements Made
1. Better Testing Patterns ✅
strings.Contains()error checks withassert.ErrorContains()os.Setenv()/defer os.Unsetenv()tot.Setenv()for automatic cleanupassert.Equal()setupStdinTest()helper function to reduce boilerplate from ~10 lines to 1-2 lines per teststringsimport after refactoringrequire.Error()for critical assertions2. Increased Coverage ✅
/path/${VAR1}/subdir/${VAR2}LoadFromStdin()mcpServersmapcontainerfield (TestLoadFromStdin_VariableExpansionInContainer)Coverage Improvement:
3. Cleaner & More Stable Tests ✅
setupStdinTest()helpert.Helper()for better test failure reportingdefert.Setenv()(Go 1.17+)defer os.Unsetenv()callsrequire.Error()for critical checks (stops test on failure)assert.ErrorContains()for error message validationassert.Equal()for value comparisonsCode Quality Metrics
Before:
After:
Test Execution
All improvements maintain 100% backward compatibility with existing tests. The changes are focused on:
Why These Changes?
This test file was selected based on analysis showing:
strings.Contains()patternsThe improvements make the test suite:
Generated by Test Improver Workflow
Focuses on better testify patterns, increased coverage, and more stable tests