Skip to content

[scanner] fix: add comprehensive unit tests for workloads/cluster_groups.go#19223

Merged
clubanderson merged 2 commits into
mainfrom
scanner/fix-19118
Jun 19, 2026
Merged

[scanner] fix: add comprehensive unit tests for workloads/cluster_groups.go#19223
clubanderson merged 2 commits into
mainfrom
scanner/fix-19118

Conversation

@clubanderson

Copy link
Copy Markdown
Collaborator

Fixes #19118

Replaces the placeholder test file with comprehensive table-driven tests covering all 10 CRUD functions in workloads/cluster_groups.go:

Persistence layer:

  • LoadPersistedClusterGroups — success, nil store, store error, invalid JSON
  • persistClusterGroup — success, nil store, store error
  • deletePersistedClusterGroup — success, nil store, store error

HTTP handlers:

  • ListClusterGroups — includes built-in all-healthy-clusters group
  • CreateClusterGroup — success, missing name, reserved name, static with no clusters, dynamic with no clusters (allowed), invalid body
  • UpdateClusterGroup — success, built-in reject, invalid body
  • DeleteClusterGroup — success, built-in reject
  • SyncClusterGroups — success, filters reserved name, invalid JSON, body too large

Lifecycle & safety:

  • StopCacheRefresh — idempotent (multiple calls safe)
  • Concurrent read/write access — no data races

…ups.go

Replaces the placeholder test with full coverage of all CRUD functions:

- LoadPersistedClusterGroups: success, nil store, store error, invalid JSON
- persistClusterGroup: success, nil store, store error
- deletePersistedClusterGroup: success, nil store, store error
- ListClusterGroups: includes built-in group
- CreateClusterGroup: success, missing name, reserved name, no clusters,
  dynamic with no clusters, invalid body
- UpdateClusterGroup: success, built-in reject, invalid body
- DeleteClusterGroup: success, built-in reject
- SyncClusterGroups: success, filters reserved name, invalid JSON, body too large
- StopCacheRefresh: idempotent (multiple calls safe)
- Concurrent access: race condition safety

Signed-off-by: Andy Anderson <andy@clubanderson.com>
Copilot AI review requested due to automatic review settings June 19, 2026 17:53
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Jun 19, 2026
@netlify

netlify Bot commented Jun 19, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellarconsole canceled.

Name Link
🔨 Latest commit 74c138d
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a35872fc00885000877c9df

@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 assign mikespreitzer for approval. 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

@github-actions

Copy link
Copy Markdown
Contributor

🐝 Hi @clubanderson! I'm kubestellar-hive[bot], an automation bot for this repo.

Trusted users — org members and contributors with write access — can mention @kubestellar-hive in a comment to trigger repo automation.
On issues, that mention queues an automated fix attempt. On pull requests, it records extra context for existing automation.
This is not an interactive Q&A bot, so mentions should be treated as requests for automation rather than a conversation.

Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @clubanderson — 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.

@kubestellar-prow kubestellar-prow Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jun 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 replaces the previous placeholder cluster_groups_test.go with a broad set of unit tests intended to cover the persistence helpers and HTTP handlers in pkg/api/handlers/workloads/cluster_groups.go, including edge cases (invalid input, reserved names, oversized sync payloads) and concurrency safety.

Changes:

  • Adds table-style tests for loading/persisting/deleting cluster groups via the store.
  • Adds HTTP handler tests for List/Create/Update/Delete/Sync cluster groups and basic validation cases.
  • Adds tests for StopCacheRefresh idempotency and concurrent access patterns.

Comment on lines +32 to +35
mockStore.On("GetUser", mock.Anything).Return(nil, nil).Maybe()

h := NewWorkloadHandlers(env.K8sClient, mockStore, env.Hub)

Comment on lines +12 to +16
"github.com/gofiber/fiber/v2"
"github.com/kubestellar/console/pkg/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Comment on lines +204 to +207
func TestCreateClusterGroup_Success(t *testing.T) {
env := setupTestEnv(t)
h := NewWorkloadHandlers(env.K8sClient, env.Store, env.Hub)
env.App.Post("/api/cluster-groups", h.CreateClusterGroup)
Comment on lines +447 to +448
// Should be 413 or 400 depending on whether Fiber or the handler catches it
assert.True(t, resp.StatusCode == 413 || resp.StatusCode == 400)
Comment on lines +19 to +24
// ---------- LoadPersistedClusterGroups ----------

func TestLoadPersistedClusterGroups_Success(t *testing.T) {
env := setupTestEnv(t)
mockStore := env.Store.(*test.MockStore)

Comment on lines +174 to +177
func TestListClusterGroups_IncludesBuiltIn(t *testing.T) {
env := setupTestEnv(t)
h := NewWorkloadHandlers(env.K8sClient, env.Store, env.Hub)
env.App.Get("/api/cluster-groups", h.ListClusterGroups)
Comment on lines +203 to +208

func TestCreateClusterGroup_Success(t *testing.T) {
env := setupTestEnv(t)
h := NewWorkloadHandlers(env.K8sClient, env.Store, env.Hub)
env.App.Post("/api/cluster-groups", h.CreateClusterGroup)

@clubanderson clubanderson merged commit d8953e7 into main Jun 19, 2026
23 of 28 checks passed
@kubestellar-prow kubestellar-prow Bot deleted the scanner/fix-19118 branch June 19, 2026 18:15
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

@github-actions

Copy link
Copy Markdown
Contributor

❌ Post-Merge Verification: failed

Commit: d8953e78d95fd4120dd7023d9a87f395593423aa
Specs run: smoke.spec.ts
Report: https://github.com/kubestellar/console/actions/runs/27841787447

@github-actions

Copy link
Copy Markdown
Contributor

Post-merge build verification passed

Both Go and frontend builds compiled successfully against merge commit d8953e78d95fd4120dd7023d9a87f395593423aa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/XL Denotes a PR that changes 500-999 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