rancher icon indicating copy to clipboard operation
rancher copied to clipboard

[DNM] KEv2 unit tests for AKS EKS and GKE handlers

Open a-blender opened this issue 3 years ago • 3 comments

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

a-blender avatar Aug 08 '22 23:08 a-blender

Here is a branch comparison with master that might be helpful.

a-blender avatar Aug 23 '22 16:08 a-blender

@annablender , are these unit tests? If they are, let's update title and desciption.

snasovich avatar Aug 23 '22 19:08 snasovich

@jiaqiluo , could you please review this again and approve if your feedback is now addressed?

snasovich avatar Oct 19 '22 17:10 snasovich

Closing this PR because the KEv2 unit tests have already been merged into rancher release/v2.7 here then back ported to release/v2.6 here as part of the branching strategy for moving to the next minor release of Rancher 2. This PR is just a duplicate at this point.

a-blender avatar Nov 07 '22 18:11 a-blender