Skip to content

test(internal/librarian/java): check error messages in TestCollectModules_Error#4965

Open
perashanid wants to merge 2 commits intogoogleapis:mainfrom
perashanid:fix/java-test-error-check-4962
Open

test(internal/librarian/java): check error messages in TestCollectModules_Error#4965
perashanid wants to merge 2 commits intogoogleapis:mainfrom
perashanid:fix/java-test-error-check-4962

Conversation

@perashanid
Copy link
Copy Markdown
Contributor

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:

  1. Invalid distribution name: Verifies error contains "invalid distribution name"
  2. Failed to find api config: Verifies error contains "failed to find api config"

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

@perashanid perashanid requested a review from a team as a code owner March 31, 2026 21:50
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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
@perashanid perashanid requested a review from julieqiu April 1, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

java: update TestCollectModules_Error to check error

2 participants