Skip to content

refactor(policy): refactor listNamespaces sort tests#3263

Merged
dsm20 merged 3 commits intomainfrom
test/DSPX-2681-retrofit-listnamespaces-sort-tests
Apr 7, 2026
Merged

refactor(policy): refactor listNamespaces sort tests#3263
dsm20 merged 3 commits intomainfrom
test/DSPX-2681-retrofit-listnamespaces-sort-tests

Conversation

@dsm20
Copy link
Copy Markdown
Contributor

@dsm20 dsm20 commented Apr 7, 2026

Proposed Changes

As per integration tests in listAttribute, this PR does some refactoring of existing tests to use helpers, adds fuller test coverage, and protovalidate tests.

Exact changes were as follows:

  • Refactor ListNamespaces integration sort tests to use reusable helpers (createSortTestNamespaces, createNamedSortTestNamespaces), matching the pattern established in ListAttributes
  • Add missing sort direction tests for full coverage: created_at DESC, fqn DESC, updated_at ASC
  • Add API-level protovalidate test for ListNamespacesRequest.Sort (validates max_items = 1 constraint)

Checklist

  • I have added or updated unit tests
  • I have added or updated integration tests (if appropriate)
  • I have added or updated documentation

Testing Instructions

Summary by CodeRabbit

  • Tests
    • Refactored namespace sorting tests with reusable helpers for deterministic setup and simpler assertions.
    • Added coverage for missing ascending and descending sort orders (created_at, fqn, updated_at) and ensured fallback behavior remains correct.
    • Added validator tests for list request sort parameters to confirm single-sort acceptance and reject multiple-sort inputs.

dsm20 added 2 commits April 6, 2026 20:49
added new helpers createSortTestNamespaces() and
createNamedSortTestNamespaces() (timebased and name based applications
respectively), and refactored existing tests to use the new helpers.
Also added 3 new tests for true full test coverage
added Test_ListNamespacesRequest_Sort in namespaces_test.go. This test
validates the proto message via its protovalidate restrictions. No sort,
one item, and 2 items are tested.
@dsm20 dsm20 requested review from a team as code owners April 7, 2026 01:05
@github-actions github-actions bot added comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) size/xs labels Apr 7, 2026
@dsm20 dsm20 changed the title test(policy): refactor listNamespaces sort tests refactor(policy): refactor listNamespaces sort tests Apr 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 202.845218ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 89.480303ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 391.464936ms
Throughput 255.45 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 40.73226413s
Average Latency 405.734166ms
Throughput 122.75 requests/second

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves the testing suite for the ListNamespaces functionality. By introducing helper methods for test data generation, the codebase becomes cleaner and more modular. Additionally, the PR enhances test coverage for various sorting scenarios and adds necessary API-level validation to ensure request constraints are correctly enforced.

Highlights

  • Test Refactoring: Refactored ListNamespaces integration tests to utilize reusable helper functions, improving maintainability and consistency.
  • Expanded Test Coverage: Added missing sort direction tests for created_at, fqn, and updated_at fields to ensure comprehensive validation.
  • API Validation: Implemented a new protovalidate test to enforce the constraint that ListNamespacesRequest.Sort allows a maximum of one item.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.


The tests were long and hard to read, With helpers now, they take the lead. Sorting logic, clear and bright, Ensures the code is running right.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 refactors the namespace integration tests by introducing helper methods for namespace creation, which reduces code duplication across sorting tests. It also adds new test cases to verify sorting by creation date (DESC), FQN (DESC), and update date (ASC), along with validation logic for the sort request parameters. Feedback is provided regarding the use of Go 1.22 features and the architectural placement of test helper methods to avoid the use of lint suppressions.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d94bcd73-2009-4794-9fef-1ef459b232bc

📥 Commits

Reviewing files that changed from the base of the PR and between 5426c98 and 106ab7d.

📒 Files selected for processing (1)
  • service/integration/namespaces_test.go

📝 Walkthrough

Walkthrough

Refactors namespace sorting integration tests by introducing helper methods for deterministic namespace creation, adds tests for additional sort directions (ASC/DESC) and updated_at behavior, and adds a validator unit test for ListNamespacesRequest.Sort cardinality.

Changes

Cohort / File(s) Summary
Integration Test Refactor & Coverage
service/integration/namespaces_test.go
Added helper methods createSortTestNamespaces and createNamedSortTestNamespaces; replaced inline namespace setup with helpers; updated existing sort tests to use helper-returned IDs; added tests for created_at DESC, fqn DESC, and updated_at ASC; adjusted unspecified-field fallback test.
Sort Validation Unit Test
service/policy/namespaces/namespaces_test.go
Imported policy sort direction enum and added Test_ListNamespacesRequest_Sort validating that Sort accepts zero or one item and rejects multiple items with an error mentioning "sort".

Sequence Diagram(s)

(omitted — changes are test additions/refactors without new multi-component control flow)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

size/m

Suggested reviewers

  • alkalescent
  • c-r33d

Poem

🐰 I hopped through tests with nimble paws,

helpers planted tidy stringed laws.
ASC and DESC, the order clear,
Updated timestamps hop near.
Tests now bound — a rabbit's cheer! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main refactoring work: consolidating sort test setup with reusable helpers and adding missing test coverage for ListNamespaces sort functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/DSPX-2681-retrofit-listnamespaces-sort-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

hardcoded 3 instead. createSortTestNamespaces wont be used outside of this API so it doesnt need to have a count param
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

Benchmark results, click to expand

Benchmark authorization.GetDecisions Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 195.190527ms

Benchmark authorization.v2.GetMultiResourceDecision Results:

Metric Value
Approved Decision Requests 1000
Denied Decision Requests 0
Total Time 99.230629ms

Benchmark Statistics

Name № Requests Avg Duration Min Duration Max Duration

Bulk Benchmark Results

Metric Value
Total Decrypts 100
Successful Decrypts 100
Failed Decrypts 0
Total Time 430.540254ms
Throughput 232.27 requests/second

TDF3 Benchmark Results:

Metric Value
Total Requests 5000
Successful Requests 5000
Failed Requests 0
Concurrent Requests 50
Total Time 40.227469534s
Average Latency 400.857397ms
Throughput 124.29 requests/second

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

⚠️ Govulncheck found vulnerabilities ⚠️

The following modules have known vulnerabilities:

  • service
  • tests-bdd

See the workflow run for details.

@dsm20 dsm20 added this pull request to the merge queue Apr 7, 2026
Merged via the queue into main with commit ea5f66e Apr 7, 2026
39 checks passed
@dsm20 dsm20 deleted the test/DSPX-2681-retrofit-listnamespaces-sort-tests branch April 7, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) size/xs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants