test(internal/librarian/java): check error messages in TestCollectModules_Error#4965
Open
perashanid wants to merge 2 commits intogoogleapis:mainfrom
Open
test(internal/librarian/java): check error messages in TestCollectModules_Error#4965perashanid wants to merge 2 commits intogoogleapis:mainfrom
perashanid wants to merge 2 commits intogoogleapis:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the TestCollectModules_Error function in pom_test.go to include specific error message verification and improves error reporting by using t.Fatal. A review comment suggests using errors.Is with sentinel errors instead of strings.Contains to align with better error handling practices and avoid fragile string-based checks.
julieqiu
reviewed
Apr 1, 2026
julieqiu
requested changes
Apr 1, 2026
Address review feedback from PR googleapis#4965 by replacing string-based error checking with sentinel errors following the project's Go style guide. Changes: - Add ErrInvalidDistributionName and ErrAPIConfigNotFound sentinel errors - Wrap sentinel errors in collectModules error returns using %w - Update TestCollectModules_Error to use errors.Is instead of strings.Contains - Remove unused strings import from test file This makes error checking more robust and maintainable by avoiding fragile string comparisons that can break when error messages change. Fixes googleapis#4962
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.
This PR improves the TestCollectModules_Error test by adding proper error message validation. Previously, the test only checked that an error was returned but didn't verify the error content. Now it checks that the error messages contain the expected text for each failure scenario.
Changes Made:
Added wantErrText field to test cases to specify expected error message content
Updated test logic to verify error messages using strings.Contains
Added strings import to support error message checking
Changed from t.Error to t.Fatal for nil error case to stop execution immediately
Added descriptive error message when error text doesn't match expectations
Technical Implementation:
The test now validates two error scenarios:
This ensures that collectModules returns the correct error for each failure case, making the test more robust and easier to debug when failures occur.
Testing:
TestCollectModules_Error passes with proper error validation
All pom-related tests pass (TestSyncPoms_Golden, TestIsPomMissing, etc.)
No linting or diagnostic issues
Fixes #4962