Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extracts a generic PickOne helper function to refactor test code and eliminate direct dependencies on math/rand in test files. The refactoring replaces all occurrences of the pattern list[rand.Intn(len(list))] with calls to test.PickOne(list), improving test readability and reducing the risk of accidental double-access slips to collections.
Changes:
- Introduces a generic
PickOnefunction in the test package that encapsulates random element selection - Refactors 12 database test files to use the new helper function instead of inline
rand.Intncalls - Modifies receiver types in
entity.gofrom pointer to value receivers forAs*conversion methods to accommodate the return value semantics of thePickOnefunction
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/database/mariadb/test/common.go | Adds the generic PickOne function and imports math/rand into the test package |
| internal/database/mariadb/user_test.go | Replaces 6 instances of rand.Intn with test.PickOne and removes unused import |
| internal/database/mariadb/support_group_test.go | Replaces 4 instances of rand.Intn with test.PickOne and removes unused import |
| internal/database/mariadb/service_test.go | Replaces 10 instances of rand.Intn with test.PickOne and removes unused import |
| internal/database/mariadb/remediation_test.go | Replaces 10 instances of rand.Intn with test.PickOne and removes unused import |
| internal/database/mariadb/patch_test.go | Replaces 6 instances of rand.Intn with test.PickOne and removes unused import |
| internal/database/mariadb/issue_variant_test.go | Replaces 10 instances of rand.Intn with test.PickOne and removes unused import |
| internal/database/mariadb/issue_test.go | Replaces 15 instances of rand.Intn with test.PickOne and removes unused import |
| internal/database/mariadb/issue_repository_test.go | Replaces 3 instances of rand.Intn with test.PickOne and removes unused import |
| internal/database/mariadb/issue_match_test.go | Replaces 16 instances of rand.Intn with test.PickOne and removes unused import |
| internal/database/mariadb/component_version_test.go | Replaces 10 instances of rand.Intn with test.PickOne |
| internal/database/mariadb/component_test.go | Replaces 2 instances of rand.Intn with test.PickOne and removes unused import |
| internal/database/mariadb/component_instance_test.go | Replaces 5 instances of rand.Intn with test.PickOne and removes unused import |
| internal/database/mariadb/entity.go | Changes receiver types from pointer to value for 16 As* conversion methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
89bfd20 to
162ff1d
Compare
Extract function PickOne to minimize errors with double access to list On-behalf-of: SAP Michal Krzyz <michal.krzyz@sap.com> Signed-off-by: Michal Krzyz <michalkrzyz@gmail.com>
162ff1d to
e5dcff6
Compare
MR2011
approved these changes
Apr 10, 2026
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.
Extract test helper function PickOne to minimize slips with double access to list. This refactor also increase test readability and removes test direct random dependency.
On-behalf-of: SAP Michal Krzyz michal.krzyz@sap.com
Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.
What type of PR is this? (check all applicable)
Related Tickets & Documents
Added tests?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Added to documentation?
Checklist