tests: add 98% coverage unit, integration, and e2e tests#9
Draft
wicked-wix wants to merge 2 commits intomasterfrom
Draft
tests: add 98% coverage unit, integration, and e2e tests#9wicked-wix wants to merge 2 commits intomasterfrom
wicked-wix wants to merge 2 commits intomasterfrom
Conversation
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>
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
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 —nodeGroupNamesdynamic discovery, label value updates, nodes with nil labels, finalization of both labels+taints in sequence, mixedmembers+nodeGroupNames, and empty NodeGroups.controllers/reconciler_errors_test.go: 7 fake-client error-injection tests usingcontroller-runtime/pkg/client/fakeandinterceptor.Funcsto cover the remaining error handling branches inReconcileandfindNodeGroupsForMember.test/e2e/: End-to-end test suite for a kind cluster. Connects viaKUBECONFIG, skips gracefully if the CRD is not installed. Tests labels, taints, re-application after manual removal,nodeGroupNamesdiscovery, and full finalizer lifecycle.test/e2e/kind-config.yaml: Kind cluster config with 1 control-plane + 2 workers.make testnow excludes the e2e package; new targetskind-create,kind-delete,kind-load-and-deploy,test-e2e, ande2e-fullfor the full kind workflow.controllers/suite_test.go: Fixed the test manager to use port0for metrics and health probe so tests work on machines where port 8080 is already in use.Total coverage: 98.4% (all helper functions and
findNodeGroupsForMemberat 100%,Reconcileat 98.3%, only theSetupWithManagerIndexFielderror path remains uncovered as it requires mocking the full manager interface).Test plan
make testpasses (unit + integration, no cluster needed)make kind-create && make kind-load-and-deploy && make test-e2e && make kind-deleteruns the full e2e lifecycle🤖 Generated with Claude Code