Skip to content

tests: add 98% coverage unit, integration, and e2e tests#9

Draft
wicked-wix wants to merge 2 commits intomasterfrom
tests/add-coverage
Draft

tests: add 98% coverage unit, integration, and e2e tests#9
wicked-wix wants to merge 2 commits intomasterfrom
tests/add-coverage

Conversation

@wicked-wix
Copy link
Copy Markdown
Contributor

Summary

  • controllers/helpers_test.go: 38 table-driven unit tests for every pure helper function (stringIn, taintPos, hasTaint, finalizeNodeLabels, reconcileNodeLabels, finalizeNodeTaints, reconcileNodeTaints). All branches covered, including nil-labels and label-value-update paths.
  • controllers/nodegroup_extra_test.go: 9 additional Ginkgo integration tests covering gaps in the existing suite — nodeGroupNames dynamic discovery, label value updates, nodes with nil labels, finalization of both labels+taints in sequence, mixed members+nodeGroupNames, and empty NodeGroups.
  • controllers/reconciler_errors_test.go: 7 fake-client error-injection tests using controller-runtime/pkg/client/fake and interceptor.Funcs to cover the remaining error handling branches in Reconcile and findNodeGroupsForMember.
  • test/e2e/: End-to-end test suite for a kind cluster. Connects via KUBECONFIG, skips gracefully if the CRD is not installed. Tests labels, taints, re-application after manual removal, nodeGroupNames discovery, and full finalizer lifecycle.
  • test/e2e/kind-config.yaml: Kind cluster config with 1 control-plane + 2 workers.
  • Makefile: make test now excludes the e2e package; new targets kind-create, kind-delete, kind-load-and-deploy, test-e2e, and e2e-full for the full kind workflow.
  • controllers/suite_test.go: Fixed the test manager to use port 0 for metrics and health probe so tests work on machines where port 8080 is already in use.

Total coverage: 98.4% (all helper functions and findNodeGroupsForMember at 100%, Reconcile at 98.3%, only the SetupWithManager IndexField error path remains uncovered as it requires mocking the full manager interface).

Test plan

  • make test passes (unit + integration, no cluster needed)
  • make kind-create && make kind-load-and-deploy && make test-e2e && make kind-delete runs the full e2e lifecycle
  • No existing test behaviour changed

🤖 Generated with Claude Code

wicked-wix and others added 2 commits April 23, 2026 09:01
Rewrites README.md with a full project overview, installation steps,
usage examples, and architecture description. Adds a docs/ directory
with an API reference, operations guide, and development guide.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Unit tests (controllers/helpers_test.go):
- Table-driven tests for all pure functions: stringIn, taintPos, hasTaint,
  finalizeNodeLabels, reconcileNodeLabels, finalizeNodeTaints, reconcileNodeTaints
- 38 test cases covering every branch including nil-label and value-update paths

Integration tests (controllers/nodegroup_extra_test.go):
- nodeGroupNames dynamic node discovery
- Label value update (existing label overwritten)
- Node with nil labels map (nil-branch in reconcileNodeLabels)
- Finalization preserves pre-existing labels not managed by the NodeGroup
- Finalization of both labels and taints in sequence
- Mixed spec.members + spec.nodeGroupNames
- Empty NodeGroup (no members, no labels)

Error-path tests (controllers/reconciler_errors_test.go):
- Fake-client injection for: NodeGroup Get error, Node list error,
  finalizer Update error, findNodeGroupsForMember list error,
  finalization node label/taint update errors, finalizer removal error

E2E tests (test/e2e/):
- Suite connects to a real cluster via KUBECONFIG, skips gracefully if
  the CRD is not installed or no nodes are available
- Labels applied, persisted, and cleaned up via spec.members
- Taints applied, persisted, and cleaned up
- nodeGroupNames dynamic discovery
- Finalizer lifecycle (added and removed on deletion)

Infrastructure:
- suite_test.go: disable metrics/health ports in test manager to avoid
  port conflicts on development machines
- Makefile: exclude e2e package from `make test`, add kind-create,
  kind-delete, kind-load-and-deploy, test-e2e, and e2e-full targets
- test/e2e/kind-config.yaml: 1 control-plane + 2 workers

Coverage: 98.4% of statements (was ~0% for helpers, 100% on all helpers,
findNodeGroupsForMember, and most of Reconcile)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant