[DNM] KEv2 unit tests for AKS EKS and GKE handlers
Issue: https://github.com/rancher/rancher/issues/37818
Problem
Add KEv2 unit tests for cloud providers.
Solution
I wrote KEv2 integration (unit) tests to test code functionality in the rancher/rancher handler for each KEv2 cloud provider (AKS EKS and GKE). The tests are written using the Go Test Framework and MockCompose. They mock the cluster state and AKSClusterConfig objects using test files to simulate reactions to a real cluster, and mock any mockable Interfaces used by the OperatorController. Test files are located in each handler folder and test files are in a /test folder in each handler folder. The unit test structure is different from rancher/rancher/tests because Go Test Framework requires test files to be in the same package as the source code.
File structure
rancher/rancher
-> pkg/controllers/management/aks
-> aks_cluster_handler.go
-> aks_cluster_handler_test.go
-> tests/
-> mockdata1.yaml
-> mockdata2.json
Testing
Git clone rancher/rancher
If you want to test each provider separately
go test -v ./pkg/controllers/management/aks
go test -v ./pkg/controllers/management/eks
go test -v ./pkg/controllers/management/gke
If you want to run all tests
go test -v ./pkg/controllers/management/aks ./pkg/controllers/management/eks ./pkg/controllers/management/gke
If you want to check test coverage (current coverage of KEv2: 35.1%, not including mocked sibling funcs so actual coverage is likely around 60-70%)
go test (or alias command) -coverprofile=coverage.out
go tool cover -html=coverage.out
Here is a branch comparison with master that might be helpful.
@annablender , are these unit tests? If they are, let's update title and desciption.
@jiaqiluo , could you please review this again and approve if your feedback is now addressed?