Skip to content

[quality] Add comprehensive tests for workloads/cluster_groups.go (16 tests)#19155

Closed
clubanderson wants to merge 1 commit into
mainfrom
quality/test-cluster-groups-19118
Closed

[quality] Add comprehensive tests for workloads/cluster_groups.go (16 tests)#19155
clubanderson wants to merge 1 commit into
mainfrom
quality/test-cluster-groups-19118

Conversation

@clubanderson

Copy link
Copy Markdown
Collaborator

Fixes #19118

Test Improvement

Replaces the placeholder test file with 16 comprehensive test functions covering all previously-untested paths in pkg/api/handlers/workloads/cluster_groups.go:

Tests Added

Test Coverage Target
TestCreateClusterGroup_ValidationErrors 4 validation branches (empty name, reserved name, no clusters, bad JSON)
TestCreateClusterGroup_DynamicGroupNoCluster Dynamic group creation without clusters
TestCreateClusterGroup_NoK8sClient Group creation without k8s client
TestUpdateClusterGroup_BuiltInProtection Cannot modify built-in group
TestUpdateClusterGroup_InvalidBody Malformed request body rejection
TestDeleteClusterGroup_BuiltInProtection Cannot delete built-in group
TestDeleteClusterGroup_NonExistent Idempotent delete
TestSyncClusterGroups_Success Bulk sync replaces old groups
TestSyncClusterGroups_ReservedNameFiltered Reserved name skipped during sync
TestSyncClusterGroups_InvalidBody Invalid JSON rejected
TestSyncClusterGroups_OversizedPayload 1MB payload limit enforced
TestSyncClusterGroups_PersistenceDeletesStale Stale groups removed from memory
TestListClusterGroups_NoK8sClient Built-in group with empty clusters
TestLoadPersistedClusterGroups_Success Store → memory round-trip
TestLoadPersistedClusterGroups_NilStore Nil store early return
TestLoadPersistedClusterGroups_UnmarshalError Invalid JSON skipped
TestStartStopCacheRefresh Goroutine lifecycle + idempotent stop
TestPersistClusterGroup_NilStore No-op when store nil
TestDeletePersistedClusterGroup_NilStore No-op when store nil

Key Paths Now Covered

  • All CRUD validation error branches
  • Built-in group protection for update + delete
  • SyncClusterGroups endpoint (all branches)
  • Persistence layer nil-store guards
  • Cache refresh goroutine start/stop lifecycle
  • LoadPersistedClusterGroups error handling

Filed by quality agent (ACMM L4/L6 — full mode)

Replaces the placeholder test with 16 test functions covering all
previously-untested paths in pkg/api/handlers/workloads/cluster_groups.go:

- Validation error branches (empty name, reserved name, no clusters, bad JSON)
- Dynamic group creation without clusters
- Built-in group protection (update/delete rejected)
- Idempotent delete of non-existent groups
- SyncClusterGroups (success, reserved name filtering, invalid body, oversized payload)
- ListClusterGroups without k8s client
- LoadPersistedClusterGroups (success, nil store, unmarshal errors)
- StartCacheRefresh / StopCacheRefresh lifecycle
- Persistence nil-store no-op paths

Fixes #19118

Signed-off-by: kubestellar-hive[bot] <kubestellar-hive[bot]@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 18, 2026 23:16
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Jun 18, 2026
@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 eeshaansa 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

@netlify

netlify Bot commented Jun 18, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellarconsole canceled.

Name Link
🔨 Latest commit 54b332a
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a347c42aaa63400084c4eb6

@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.

@github-actions github-actions Bot added the ai-generated Pull request generated by AI label Jun 18, 2026
@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.

@kubestellar-prow kubestellar-prow Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jun 18, 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 test with a substantial suite of unit/integration-style tests exercising the cluster group CRUD/sync/persistence/cache-refresh behaviors implemented in pkg/api/handlers/workloads/cluster_groups.go.

Changes:

  • Adds multiple Fiber handler tests covering create/update/delete/sync validation and built-in group protections.
  • Adds tests for persistence loading behavior (LoadPersistedClusterGroups) and cache refresh lifecycle (StartCacheRefresh / StopCacheRefresh).
  • Adds nil-store guard tests for persistence helper methods.

Comment on lines +50 to +52
env := setupTestEnv(t)
handler := NewWorkloadHandlers(env.K8sClient, env.Hub, env.Store)
env.App.Post("/api/cluster-groups", handler.CreateClusterGroup)
Comment on lines +344 to +346
mockStore.On("ListClusterGroups", mock.Anything).Return(map[string][]byte{
"persisted-group": data,
}, nil).Once()
Comment on lines +378 to +380
mockStore.On("ListClusterGroups", mock.Anything).Return(map[string][]byte{
"bad-group": []byte("not-valid-json{{{"),
}, nil).Once()
Comment on lines +396 to +398
mockStore := new(test.MockStore)
mockStore.On("ListClusterGroups", mock.Anything).Return(map[string][]byte{}, nil).Maybe()

Comment on lines +304 to +306
// Fiber may reject oversized bodies with 413 or our handler returns 413
assert.True(t, resp.StatusCode == 413 || resp.StatusCode == 400,
"expected 413 or 400, got %d", resp.StatusCode)
Comment on lines +103 to +108
var result ClusterGroup
body, _ := io.ReadAll(resp.Body)
json.Unmarshal(body, &result)
assert.Equal(t, "dynamic-group", result.Name)
assert.Equal(t, "dynamic", result.Kind)
}
Comment on lines +408 to +410
// Give it a tiny bit of time to start the goroutine
time.Sleep(50 * time.Millisecond)

Comment on lines +51 to +52
handler := NewWorkloadHandlers(env.K8sClient, env.Hub, env.Store)
env.App.Post("/api/cluster-groups", handler.CreateClusterGroup)
@clubanderson clubanderson deleted the quality/test-cluster-groups-19118 branch June 19, 2026 03:04
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: 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