[scanner] fix: add comprehensive unit tests for workloads/cluster_groups.go#19223
Conversation
…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>
✅ Deploy Preview for kubestellarconsole canceled.
|
|
[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 |
|
🐝 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. |
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
There was a problem hiding this comment.
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.
| mockStore.On("GetUser", mock.Anything).Return(nil, nil).Maybe() | ||
|
|
||
| h := NewWorkloadHandlers(env.K8sClient, mockStore, env.Hub) | ||
|
|
| "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" |
| 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) |
| // Should be 413 or 400 depending on whether Fiber or the handler catches it | ||
| assert.True(t, resp.StatusCode == 413 || resp.StatusCode == 400) |
| // ---------- LoadPersistedClusterGroups ---------- | ||
|
|
||
| func TestLoadPersistedClusterGroups_Success(t *testing.T) { | ||
| env := setupTestEnv(t) | ||
| mockStore := env.Store.(*test.MockStore) | ||
|
|
| 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) |
|
|
||
| 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) | ||
|
|
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
❌ Post-Merge Verification: failedCommit: |
|
Post-merge build verification passed ✅ Both Go and frontend builds compiled successfully against merge commit |
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 JSONpersistClusterGroup— success, nil store, store errordeletePersistedClusterGroup— success, nil store, store errorHTTP handlers:
ListClusterGroups— includes built-in all-healthy-clusters groupCreateClusterGroup— success, missing name, reserved name, static with no clusters, dynamic with no clusters (allowed), invalid bodyUpdateClusterGroup— success, built-in reject, invalid bodyDeleteClusterGroup— success, built-in rejectSyncClusterGroups— success, filters reserved name, invalid JSON, body too largeLifecycle & safety:
StopCacheRefresh— idempotent (multiple calls safe)