Skip to content

Add comprehensive tests for workload cluster group handlers#19199

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-cluster-groups-test-coverage
Closed

Add comprehensive tests for workload cluster group handlers#19199
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-cluster-groups-test-coverage

Conversation

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Adding or modifying a card/dashboard? Read the Card Development Guide first — it covers required patterns, common pitfalls, and the full file checklist.

New CNCF project card? New cards go in kubestellar/console-marketplace, not this repo. PRs adding new cards here will be redirected.

Use a coding agent. This repo is primarily developed with Claude Code (Opus 4.5/4.6). It knows all codebase patterns (isDemoData, useCardLoadingState, locale strings, DCO). Manual PRs that miss required patterns will be sent back.

📌 Fixes

Issue linking is handled automatically by the system.


📝 Summary of Changes

pkg/api/handlers/workloads/cluster_groups.go previously had placeholder-only coverage in cluster_groups_test.go. This PR replaces the placeholder with focused handler/lifecycle tests covering CRUD, sync behavior, RBAC/validation guards, and persistence/cache-refresh paths.

  • Handler coverage expansion
    • Added concrete tests for ListClusterGroups, CreateClusterGroup, UpdateClusterGroup, DeleteClusterGroup, and SyncClusterGroups.
  • Validation/RBAC/reserved-name behavior
    • Added cases for malformed payloads, required field checks, admin enforcement, reserved-name protection, and sync payload size rejection.
  • Persistence + lifecycle
    • Added tests for LoadPersistedClusterGroups, persistClusterGroup, deletePersistedClusterGroup, and StartCacheRefresh/StopCacheRefresh.
  • Test isolation
    • Added shared reset helpers to prevent clusterGroups global state leakage across tests.
const syncMaxBodyBytes = 1 << 20
oversizedBody := bytes.Repeat([]byte("a"), syncMaxBodyBytes+1)
req := httptest.NewRequest(http.MethodPost, "/api/cluster-groups/sync", bytes.NewReader(oversizedBody))

Changes Made

  • Updated pkg/api/handlers/workloads/cluster_groups_test.go to replace placeholder coverage with real handler tests
  • Refactored test utilities for deterministic shared-state reset and mock call filtering
  • Fixed coverage gaps for reserved-name protections, RBAC rejection paths, and oversized sync payload handling
  • Added tests for CRUD handlers, sync semantics, persistence restoration/helpers, and cache refresh lifecycle

Checklist

Please ensure the following before submitting your PR:

  • I used a coding agent (Claude Code, Copilot, Gemini, or Codex) to generate/review this code
  • I have reviewed the project's contribution guidelines
  • New cards target console-marketplace, not this repo
  • isDemoData is wired correctly (cards show Demo badge when using demo data)
  • I have written unit tests for the changes (if applicable)
  • I have tested the changes locally and ensured they work as expected
  • All commits are signed with DCO (git commit -s)

Screenshots or Logs (if applicable)

N/A (test-only change in Go handler package).


👀 Reviewer Notes

  • Scope is intentionally constrained to pkg/api/handlers/workloads/cluster_groups_test.go.
  • No production handler logic was changed; this PR is coverage-focused.
Original prompt

Fixes #19118

Problem

pkg/api/handlers/workloads/cluster_groups.go has 0% test coverage. The file contains 10 CRUD handlers for cluster group management.

Solution

Add comprehensive test file pkg/api/handlers/workloads/cluster_groups_test.go covering all 10 handlers:

  1. ListClusterGroups — returns built-in + user groups, populates healthy cluster counts
  2. CreateClusterGroup — success path, validation errors, reserved name rejection ("all-clusters", "ungrouped"), RBAC checks
  3. UpdateClusterGroup — success path, reserved name protection
  4. DeleteClusterGroup — success path, reserved name protection
  5. SyncClusterGroups — success, reserved name filtering, oversized payload rejection
  6. LoadPersistedClusterGroups — persistence restoration from store
  7. StartCacheRefresh / StopCacheRefresh — lifecycle management
  8. Persistence helper verification

Testing Patterns

  • Use fiber.New() + httptest.NewRequest for handler testing (follow existing patterns in pkg/api/handlers/)
  • Use the mock store from pkg/test/mock_store.go for database mocking
  • Use testify/assert and testify/require
  • Table-driven tests with descriptive case names
  • Test both success and error paths

Key Details

  • Reserved group names: "all-clusters", "ungrouped" — these cannot be created/updated/deleted
  • Built-in groups are auto-populated with healthy cluster counts from k8s data
  • SyncClusterGroups has a payload size limit

Important

  • Do NOT run npm run build or npm run lint — CI validates on the PR
  • Run go build ./pkg/api/handlers/workloads/... and go test ./pkg/api/handlers/workloads/... -count=1 -timeout 120s to verify
  • Sign the commit with -s flag for DCO

@kubestellar-prow kubestellar-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. dco-signoff: no Indicates the PR's author has not signed the DCO. labels Jun 19, 2026
@netlify

netlify Bot commented Jun 19, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellarconsole canceled.

Name Link
🔨 Latest commit bb8865b
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a34e99e84e43f0008abcbb4

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @Copilot — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@github-actions github-actions Bot added the ai-generated Pull request generated by AI label Jun 19, 2026
@kubestellar-prow kubestellar-prow Bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jun 19, 2026
Signed-off-by: GitHub <noreply@github.com>
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from clubanderson. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow

Copy link
Copy Markdown
Contributor

Thanks for your pull request. Before we can look at it, you'll need to add a 'DCO signoff' to your commits.

📝 Please follow instructions in the contributing guide to update your commits with the DCO

Full details of the Developer Certificate of Origin can be found at developercertificate.org.

The list of commits missing DCO signoff:

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@kubestellar-prow kubestellar-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jun 19, 2026
Copilot AI changed the title [WIP] Add tests for cluster group handlers in cluster_groups_test.go Add comprehensive tests for workload cluster group handlers Jun 19, 2026
Copilot AI requested a review from clubanderson June 19, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated Pull request generated by AI dco-signoff: no Indicates the PR's author has not signed the DCO. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tier/1-lightweight

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[quality] workloads/cluster_groups.go at 0% coverage — 10 CRUD+cache handlers untested

2 participants