Skip to content

test: unit tests for controller reconcilers (#40, #41, #42, #43) - #47

Merged
mjudeikis-bot merged 2 commits into
mainfrom
test/unit-controller-tests
Feb 22, 2026
Merged

mjudeikis-bot merged 2 commits into
mainfrom
test/unit-controller-tests

Conversation

@mjudeikis-bot

Copy link
Copy Markdown
Collaborator

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 — minimal mcmanager.Manager fake (embedded interface, only GetCluster implemented)
  • FakeCluster — minimal cluster.Cluster fake (only GetClient implemented)
  • NewRequest — builds mcreconcile.Request correctly (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 workspaceEnsureFn injection field to MountReconciler (defaults to r.ensureMountWorkspace in SetupMountWithManager; 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 TestToUnstructured round-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. Plus TestMapPlacementToVW table test (label present / label missing).

Checklist

  • go test ./pkg/hub/controllers/... — all pass locally
  • make lint — 0 issues
  • go build ./... — clean

Mangirdas Judeikis and others added 2 commits February 22, 2026 17:59
- 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: unit tests for LifecycleReconciler (site heartbeat stale detection)

1 participant