[quality] Add comprehensive tests for workloads/cluster_groups.go (16 tests)#19155
[quality] Add comprehensive tests for workloads/cluster_groups.go (16 tests)#19155clubanderson wants to merge 1 commit into
Conversation
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>
|
[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 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.
| env := setupTestEnv(t) | ||
| handler := NewWorkloadHandlers(env.K8sClient, env.Hub, env.Store) | ||
| env.App.Post("/api/cluster-groups", handler.CreateClusterGroup) |
| mockStore.On("ListClusterGroups", mock.Anything).Return(map[string][]byte{ | ||
| "persisted-group": data, | ||
| }, nil).Once() |
| mockStore.On("ListClusterGroups", mock.Anything).Return(map[string][]byte{ | ||
| "bad-group": []byte("not-valid-json{{{"), | ||
| }, nil).Once() |
| mockStore := new(test.MockStore) | ||
| mockStore.On("ListClusterGroups", mock.Anything).Return(map[string][]byte{}, nil).Maybe() | ||
|
|
| // 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) |
| 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) | ||
| } |
| // Give it a tiny bit of time to start the goroutine | ||
| time.Sleep(50 * time.Millisecond) | ||
|
|
| handler := NewWorkloadHandlers(env.K8sClient, env.Hub, env.Store) | ||
| env.App.Post("/api/cluster-groups", handler.CreateClusterGroup) |
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
TestCreateClusterGroup_ValidationErrorsTestCreateClusterGroup_DynamicGroupNoClusterTestCreateClusterGroup_NoK8sClientTestUpdateClusterGroup_BuiltInProtectionTestUpdateClusterGroup_InvalidBodyTestDeleteClusterGroup_BuiltInProtectionTestDeleteClusterGroup_NonExistentTestSyncClusterGroups_SuccessTestSyncClusterGroups_ReservedNameFilteredTestSyncClusterGroups_InvalidBodyTestSyncClusterGroups_OversizedPayloadTestSyncClusterGroups_PersistenceDeletesStaleTestListClusterGroups_NoK8sClientTestLoadPersistedClusterGroups_SuccessTestLoadPersistedClusterGroups_NilStoreTestLoadPersistedClusterGroups_UnmarshalErrorTestStartStopCacheRefreshTestPersistClusterGroup_NilStoreTestDeletePersistedClusterGroup_NilStoreKey Paths Now Covered
SyncClusterGroupsendpoint (all branches)LoadPersistedClusterGroupserror handlingFiled by quality agent (ACMM L4/L6 — full mode)