Skip to content

test: expand unit test coverage for untested controllers#312

Open
dviejokfs wants to merge 7 commits intomainfrom
feat/expand-test-coverage
Open

test: expand unit test coverage for untested controllers#312
dviejokfs wants to merge 7 commits intomainfrom
feat/expand-test-coverage

Conversation

@dviejokfs
Copy link
Copy Markdown
Contributor

Summary

  • Add 54 new test cases across 7 files for controllers that previously had zero or minimal test coverage
  • No changes to controller logic except a minor refactor to extract ConfigValidator in the mainchannel controller (same pattern used by CA, peer, and ordnode controllers)

New test files

Controller File Tests Cases
FollowerChannel followerchannel_controller_test.go TestValidateFollowerChannelConfig 6
Console console_controller_test.go TestValidateConsoleConfig, TestGetConfig 10
Chaincode Install chaincode_install_controller_test.go TestGenerateChaincodePackage, TestGenerateChaincodePackageEdgeCases 3
Chaincode Deploy chaincode_deploy_controller_test.go TestResourceNaming, TestResourceNamingConsistency, etc. 8
MainChannel mainchannel_controller_test.go TestValidateMainChannelConfig 10

Extended test files

Controller File Tests Cases Regression
CA ca_dns_ip_test.go TestGetDNSNames, TestGetIPAddresses, TestDoesCertNeedsToBeRenewed 17 Issue #214

Issue coverage

Test plan

  • go test ./controllers/... -short -count=1 — all unit tests pass
  • go vet ./controllers/... — clean
  • CI lint + test + security scan

Add unit tests for controllers that previously had zero test coverage:
- followerchannel: validation tests (6 cases)
- console: validation + GetConfig mapping tests (10 cases)
- chaincode/install: CCAAS package generation tests (3 cases)
- chaincode/deploy: resource naming tests (8 cases)
- mainchannel: validation tests (10 cases) with ConfigValidator refactor

Extend existing CA controller tests with regression tests for issue #214:
- TestGetDNSNames: DNS name extraction from mixed host/IP lists (6 cases)
- TestGetIPAddresses: IP extraction with localhost always included (5 cases)
- TestDoesCertNeedsToBeRenewed: certificate renewal detection (6 cases)

Total: 54 new test cases across 7 files. All tests pass with
`go test ./controllers/... -short`.

Signed-off-by: David Viejo <dviejo@kungfusoftware.es>
@dviejokfs dviejokfs force-pushed the feat/expand-test-coverage branch from 6184890 to cd1bd43 Compare March 30, 2026 06:49
…n suite

Add defer GinkgoRecover() to the manager start goroutine so Ginkgo
reports the actual error instead of panicking the entire test process.

Disable the metrics server in tests (BindAddress: "0") to prevent port
8080 conflicts when another process is already listening.

Signed-off-by: David Viejo <dviejo@kungfusoftware.es>
Signed-off-by: David Viejo <dviejo@kungfusoftware.es>
…lowerchannel

Register mainchannel, followerchannel, and chaincode (install/approve/commit)
reconcilers in the integration test suite so they are active during CI runs.

Add a full channel lifecycle integration test that:
1. Creates two CAs (orderer org + peer org)
2. Enrolls admin identities and stores them in Kubernetes Secrets
3. Creates an orderer node and a peer, waits for RunningStatus
4. Creates a FabricMainChannel with etcdraft consensus
5. Creates a FabricFollowerChannel to join the peer to the channel
6. Verifies the peer has joined the channel via Fabric SDK

Signed-off-by: David Viejo <dviejo@kungfusoftware.es>
…cle test

The mainchannel controller expects identity secrets to contain
YAML-encoded structs with nested cert.pem and key.pem fields, not raw
PEM values at the secret key level.

Signed-off-by: David Viejo <dviejo@kungfusoftware.es>
…work)

The channel lifecycle test fails because the mainchannel controller
connects to the orderer admin port via NodePort from the test process.
In the CI KIND cluster, this connection is refused because the orderer
admin service isn't reachable via NodePort from the host.

Keep the reconciler registrations in suite_test.go so the controllers
are active during existing integration tests.

The unit tests for mainchannel/followerchannel validation remain.

Signed-off-by: David Viejo <dviejo@kungfusoftware.es>
Add the channel lifecycle integration test back with fixes:
- Use TLSCACert (root CA) instead of TlsCert (leaf) for peer org
- Use YAML-encoded identity struct format for admin secrets
- Full lifecycle: CA → Orderer + Peer → MainChannel → FollowerChannel

Locally validated on k3d: existing CA/peer/orderer tests pass when
run inside Docker on the k3d network. The channel lifecycle test
needs a clean cluster without stale Helm releases.

Signed-off-by: David Viejo <dviejo@kungfusoftware.es>
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