Repository navigation
test: unit tests for controller reconcilers (#40, #41, #42, #43) - #47
Merged
Merged
Conversation
- utils/testfakes: shared fakeManager/fakeCluster (embedded interface trick) and NewRequest helper for multicluster reconcile.Request construction - LifecycleReconciler: 5 cases (not found, no heartbeat, fresh/stale heartbeat, already disconnected — no spurious status write) - RBACReconciler: 5 cases (not found, token pending requeue, token populated → kubeconfig+status, idempotent, owner ref adoption) plus rulesEqual/slicesEqual pure function tests - MountReconciler: 1 production change — workspaceEnsureFn injection field for testability; 5 cases (not found, not ready, ready first reconcile, URL already correct, workspace error propagation) plus toUnstructured test - scheduler.Reconciler: 6 cases (not found, no match, placements created, idempotent, stale placement deleted, singleton strategy) - status.Reconciler: 4 cases (not found, no placements, all running, mixed) plus mapPlacementToVW table test All 28 new tests pass locally with no cluster or envtest required. Co-authored-by: Mangirdas Judeikis <[email protected]>
This was referenced Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #40, #41, #42, #43
Adds unit tests for all four controller reconcilers that previously had zero coverage. Tests run in-process with no cluster or envtest required —
go test ./pkg/hub/controllers/...completes in ~0.3s.Shared infrastructure
utils/testfakes/— new package, focused on controller testing fakes:Manager— minimalmcmanager.Managerfake (embedded interface, onlyGetClusterimplemented)FakeCluster— minimalcluster.Clusterfake (onlyGetClientimplemented)NewRequest— buildsmcreconcile.Requestcorrectly (embedded struct syntax)Issue #40 — LifecycleReconciler (
lifecycle_reconciler_test.go)5 cases: not found, no heartbeat, fresh heartbeat (phase unchanged), stale heartbeat (phase→Disconnected + TunnelConnected=false), already disconnected (no spurious status write detected via ResourceVersion).
Issue #41 — RBACReconciler (
rbac_reconciler_test.go)5 reconcile cases: not found, first reconcile with token pending (NS+SA+CR+CRB+TokenSecret created, requeue 2s), token populated (kubeconfig secret created, CredentialsSecretRef set), idempotent (no duplicate create errors), missing owner ref adoption.
Pure function tests:
TestRulesEqual,TestSlicesEqual.Issue #42 — MountReconciler (
mount_reconciler_test.go)Production change: added
workspaceEnsureFninjection field toMountReconciler(defaults tor.ensureMountWorkspaceinSetupMountWithManager; no behaviour change).5 cases: not found, not-ready site (route map not polluted), ready first reconcile (route registered + URL set + ensurer called), URL already correct (no status write), workspace ensurer error propagated.
Plus
TestToUnstructuredround-trip test.Issue #43 — scheduler + status Reconcilers
scheduler (
reconciler_test.go): 6 cases — not found, no matching sites, placements created (2 prod sites, 1 staging site → 2 placements), idempotent (second reconcile no dup creates), stale placement deleted, singleton strategy (3 matched → 1 placement).status (
reconciler_test.go): 4 cases — not found, no placements→Pending+0 replicas, all Running→Running phase, mixed→Pending. PlusTestMapPlacementToVWtable test (label present / label missing).Checklist
go test ./pkg/hub/controllers/...— all pass locallymake lint— 0 issuesgo build ./...— clean