[quality] test: add 35 unit tests for MCP custom resources helpers#19561
[quality] test: add 35 unit tests for MCP custom resources helpers#19561clubanderson wants to merge 1 commit into
Conversation
…\n[quality] test: add 35 unit tests for MCP custom resources helpers\n\nAdds comprehensive unit tests for 6 pure helper functions in the MCP\ncustom resources handler that had zero test coverage. The package is\nat 15.8% coverage — these tests target the pagination, parsing, and\nvalidation functions:\n\n- parseCustomResourceLimit: 3 tests (default, valid values, invalid)\n- parseCustomResourceContinueToken: 3 tests (empty, valid, invalid)\n- parsePositiveIntQuery: 4 tests (range, below min, above max, non-int)\n- paginateCustomResourceItems: 6 tests (basic, second page, past end,\n empty, exact boundary, partial last page)\n- parseCRItem: 4 tests (complete, minimal, empty, non-string labels)\n- minCustomResourceInt: 5 tests (all comparison cases)\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>"
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellarconsole canceled.
|
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
|
🐝 Hi @clubanderson! I'm Trusted users — org members and contributors with write access — can mention Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies. |
There was a problem hiding this comment.
Pull request overview
This PR improves the reliability of the MCP custom-resources handler helpers by adding unit test coverage for previously untested, pure helper functions in pkg/api/handlers/mcp/custom_resources.go, addressing the low coverage called out in #19560.
Changes:
- Added unit tests for query parsing helpers (
parseCustomResourceLimit,parseCustomResourceContinueToken,parsePositiveIntQuery) including defaulting, bounds, and invalid inputs. - Added unit tests for pagination (
paginateCustomResourceItems) covering boundary and empty/nil input scenarios. - Added unit tests for unstructured CR parsing (
parseCRItem) and comparison helper (minCustomResourceInt) across representative inputs.
Test Improvement
Adds 35 unit tests for 6 pure helper functions in
pkg/api/handlers/mcp/custom_resources.gothat had zero test coverage. The MCP package is at 15.8% coverage — the lowest non-cmd package in the Go codebase.Tests added:
parseCustomResourceLimitparseCustomResourceContinueTokenparsePositiveIntQuerypaginateCustomResourceItemsparseCRItemminCustomResourceIntWhy this matters:
parseCRItemprocesses arbitrary K8s CRD data for the MCP interface used by external AI tools — bugs cause silent data losspaginateCustomResourceItemscontrols fan-out pagination across clusters — off-by-one errors lead to duplicated or missing itemsparsePositiveIntQueryvalidates user input — bypass could allow unbounded K8s list queriesFixes #19560
Filed by quality agent (hold-gated mode). Human review required.