[test-improver] Improve tests for config/validation_schema package#3380
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[test-improver] Improve tests for config/validation_schema package#3380github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
Replace manual t.Errorf patterns with idiomatic testify assertions: - Use require.Error instead of assert.Error for critical nil-check before calling err.Error() (prevents nil dereference if assertion is ignored) - Use assert.Contains instead of manual strings.Contains + t.Errorf - Use assert.Same for pointer equality check instead of manual if comparison - Remove now-unused 'strings' import; add 'require' import Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_schema_test.goFile Analyzed
internal/config/validation_schema_test.gointernal/configImprovements Made
1. Better Testify Usage
assert.Error+ manualt.Errorfwithrequire.Error— stops the subtest immediately iferris nil, preventing a nil-pointer dereference on the subsequenterr.Error()callif !strings.Contains(err.Error(), tt.errorMsg) { t.Errorf(...) }withassert.Contains(t, err.Error(), tt.errorMsg)— idiomatic testify with automatic descriptive failure messagesif schema1 != schema2 { t.Error(...) }withassert.Same(t, schema1, schema2, ...)— testify's pointer-equality helper2. Cleaner Code
"strings"import"github.com/stretchr/testify/require"importif tt.errorMsg != "" && err != nil && !strings.Contains(...)simplified toif tt.errorMsg != "" { assert.Contains(...) }— theerr != nilguard is now handled by the precedingrequire.Error3. More Consistent Pattern
Affected test functions:
TestValidateJSONSchema(error-message loop)TestValidateStringPatterns(error-message loop)TestEnhancedErrorMessages(multiple expected-strings loop)TestSchemaCaching(pointer equality assertion)Why These Changes?
The file used
testify/assertfor most assertions but fell back to manualstrings.Contains+t.Errorffor checking error message content — a mixed pattern that's harder to read and produces less informative failure output. Testify'sassert.Containsautomatically prints both the haystack and needle on failure, making it much easier to diagnose test failures without adding extra format strings.The switch from
assert.Errortorequire.Erroris a correctness improvement: iferris unexpectedlynil, the old code would continue and panic onerr.Error(), whereasrequire.Errorstops the subtest immediately with a clear message.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests