Skip to content

test(adminapi): expand coverage for trust marks, stats, and subordinate flows#73

Open
hmffa wants to merge 22 commits into
go-oidfed:mainfrom
hmffa:tests/admin-api-extra-coverage
Open

test(adminapi): expand coverage for trust marks, stats, and subordinate flows#73
hmffa wants to merge 22 commits into
go-oidfed:mainfrom
hmffa:tests/admin-api-extra-coverage

Conversation

@hmffa
Copy link
Copy Markdown
Contributor

@hmffa hmffa commented May 12, 2026

Summary

This PR expands admin API test coverage across additional handler surfaces and edge cases, with a focus on trust mark management, stats endpoints, subordinate behavior, and storage-backed persistence flows.

Highlights:

  • add tests for entity trust marks CRUD and real storage persistence
  • add coverage for stats summary, top breakdowns, time series, latency/daily views, and export endpoints
  • add tests for subordinate event helpers, duplicate claims and critical extensions, constraint edge cases, and statement lifetime default/error fallback behavior
  • strengthen trust mark type coverage for duplicate and not found cases
  • add real storage persistence tests for trust mark issuance specs and subjects
  • refactor existing user and trust mark tests to use more consistent request handling, error assertions, and non-parallel execution where state is shared

hmffa added 8 commits May 7, 2026 10:50
- Implement tests for entity trust marks including listing, creating, updating, patching, and deleting trust marks.
- Add tests for the stats API covering summary, top endpoints, top breakdowns, time series, and export functionalities.
- Introduce tests for subordinate events with options for creating events and handling store errors.
…ding

- Replaced the doJSONRequest helper function with newJSONRequest to streamline request creation.
- Removed redundant response decoding functions and integrated JSON unmarshalling directly in test cases.
- Updated all test cases to utilize the new request and response handling methods.
- Ensured proper error handling for JSON decoding in tests.
- Updated tests in trustmark_types_test.go to replace assertStatus with assertErrorResponse for better error handling.
- Added JSON unmarshalling of response body in DELETE tests to verify empty issuers list.
- Ensured consistent error response checks across all handler tests for improved clarity and maintainability.
@deepsource-io
Copy link
Copy Markdown
Contributor

deepsource-io Bot commented May 12, 2026

DeepSource Code Review

We reviewed changes in 63a511f...a982b34 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Go May 16, 2026 5:34p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@hmffa hmffa force-pushed the tests/admin-api-extra-coverage branch from 6d37b8b to 177c92e Compare May 16, 2026 14:21
@hmffa hmffa marked this pull request as ready for review May 16, 2026 16:51
Copilot AI review requested due to automatic review settings May 16, 2026 16:51
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR expands and refactors the api/adminapi test suite to cover additional Admin API handler surfaces (trust marks, stats, subordinate flows) while standardizing request execution and error assertions across tests.

Changes:

  • Added new test suites for stats endpoints, entity trust mark CRUD/persistence, authority hints CRUD, cache invalidation middleware, and subordinate event helpers.
  • Expanded subordinate-related tests (statement/metadata/policies/constraints/additional-claims) to cover more edge cases and stricter assertions.
  • Refactored existing tests to use shared request helpers (doRequest), consistent status helpers (requireStatus), and a new assertErrorResponse contract check.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
api/adminapi/users_test.go Refactors user handler tests to use doRequest/newJSONRequest and consistent status checks.
api/adminapi/trustmark_types_test.go Expands trust mark type/issuer/owner handler coverage and standardizes error assertions.
api/adminapi/trustmark_owners_issuers_test.go Updates trust mark owner/issuer tests to use consistent helper patterns and stronger response validation.
api/adminapi/test_helpers_test.go Adds assertErrorResponse helper for validating standardized error bodies.
api/adminapi/subordinates_statement_test.go Adds statement tests for critical extensions and lifetime default/error fallback behavior.
api/adminapi/subordinates_metadata_test.go Tightens not-found expectations and strengthens “untouched data” assertions.
api/adminapi/subordinates_metadata_policies_test.go Tightens not-found expectations; adds /metadata-policy-crit and operator-filtering tests.
api/adminapi/subordinates_lifetime_test.go Switches to requireStatus usage for clearer lifetime test assertions.
api/adminapi/subordinates_keys_test.go Tightens not-found expectations for subordinate JWKS-related endpoints.
api/adminapi/subordinates_events_test.go Adds tests for subordinate event option helpers and RecordEvent behavior.
api/adminapi/subordinates_constraints_test.go Adds POST-copy-from-general tests and constraint edge case coverage.
api/adminapi/subordinates_base_test.go Standardizes error assertions and strengthens subordinate history response parsing.
api/adminapi/subordinates_additional_claims_test.go Adds duplicate/not-found coverage for additional claims POST/PUT flows.
api/adminapi/stats_test.go Adds comprehensive stats API tests (summary, top breakdowns, time series, latency, daily, export).
api/adminapi/router_test.go Parallelizes table-driven tests safely (loop var capture fix).
api/adminapi/keys_test.go Makes pending-change timestamp relative; normalizes HTTP status constants usage.
api/adminapi/entity_trustmarks_test.go Adds entity trust mark CRUD tests + real-storage persistence tests for self-issuance specs.
api/adminapi/entity_configuration_test.go Adds real-store persistence tests for object-valued additional claims; improves response validation.
api/adminapi/cache_middlewares_test.go Adds tests for cache invalidation middleware behaviors (entity config + subordinate statements).
api/adminapi/authority_hints_test.go Adds CRUD tests for authority hints, including cache invalidation behavior on success/failure.
api/adminapi/auth_test.go Normalizes HTTP status constant usage (net/http).
api/adminapi/actor_test.go Updates actor middleware test app setup to accept *testing.T and use t.Helper().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/adminapi/test_helpers_test.go
- Updated `requireStatus` and `assertStatus` functions to accept response body as an argument for better error reporting.
- Modified various test cases across multiple files to utilize the updated assertion functions, ensuring that the response body is included in failure messages for easier debugging.
- This change enhances the clarity of test failures by providing context on the response body when status codes do not match expected values.
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.

2 participants