Closed mkumatag closed 2 years ago
/assign @Amulyam24 /cc @Prajyot-Parab
Findings -
cluster-api is using Gomega based approach for unit testing purposes. capi-ibmcloud should follow the same approach to be in sync with the capi project.
This might lead to major refactoring work in capi-ibmcloud to achieve the same. Also need to explore on helper methods available in capi for reusability purpose or write new ones mainly dealing with test env creation and deletion.
@Amulyam24 Please add if anything is missing
After a discussion with @Prajyot-Parab, we have decided to follow the unit test framework of cluster-api by avoiding ginkgo.
This would require modifying the current flow of bootstrapping the test environment by implementing helper methods, something similar to https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/test/helpers/envtest.go
Once the framework is in place, we can proceed with adding the unit test cases thereby improving the coverage
Files targeted for UT coverage (divided into 2 groups PowerVS and VPC)
Functions to be mocked -
1. powervs_cluster.go / powervs_machine.go
/ powervs_image.go -> NewPowerVSClusterScope -> authenticator.GetAuthenticator()
2. powervs_cluster.go / powervs_machine.go
/ powervs_image.go -> NewPowerVSClusterScope -> servicesutils.GetAccount(auth)
Note - will update the list incase of further mocking required for any other functions.
PowerVS
Cloud/Scope
- powervs_cluster.go
- powervs_machine.go
- powervs_image.go
controllers
- ibmpowervscluster_controller.go
- ibmpowervsmachine_controller.go
- ibmpowervsimage_controller.go
VPC
Cloud/Scope
- cluster.go
- machine.go
controllers
- ibmvpccluster_controller.go
- ibmvpcmachine_controller.go
Note - WIP: compiling list of scenarios to be covered in each of the targeted file, will update soon.
WIP list of the scenarios to be covered in IBMPowerVSCluster controller tests :
[x] Reconcile IBMPowerVSCluster successfully:
[x] Reconcile IBMPowerVSCluster failures:
[x] Test Reconcile IBMPowerVSCluster func:
WIP test scenarios for IBMPowerVS machine controller:
[x] Reconcile IBMPowerVSMachine
Should reconcile successfully if IBMPowerVSMachine is not found
Should not reconcile if owner reference is not set
Should not reconcile if IBMPowerVSCluster is not found
Should not reconcile if IBMPowerVSImage is not found
Should reconcile IBMPowerVSMachine with requeue
Should requeue if Cluster infrastructure status is not ready
Should requeue if IBMPowerVSImage status is not ready
Should requeue if boostrap data secret reference is not found
Should fail to create IBMPowerVSMachine
Should fail to get the PowerVS instance
Should test IBMPowerVSMachine based on state
Should fail reconcile if error in fetching IBMPowerVSMachine
Should fail to fetch cluster details from IBMPowerVSMachine metadata
Should fail reconcile if Owner machine not found
[x] Reconcile Delete IBMPowerVSMachine
Should not delete IBMPowerVSMachine if instance ID not found
Should fail to delete IBMPowerVSMachine
Should delete IBMPowerVSMachine successfully
PRs related to this work-item:
Can be closed. /close
@Prajyot-Parab: Closing this issue.
/kind feature /area provider/ibmcloud
Describe the solution you'd like Here is the present unit test coverage as on 5th May 2022 which is really low, needs improvement
Anything else you would like to add: [Miscellaneous information that will assist in solving the issue.]