sigs.k8s.io/cluster-api-provider-aws@v1.5.5/docs/book/src/development/conventions.md (about) 1 # Coding Conventions 2 3 Below is a collection of conventions, guidlines and general tips for writing code for this project. 4 5 ## API Definitions 6 7 ### Don't Expose 3rd Party Package Types 8 9 When adding new or modifying API types don't expose 3rd party package types/enums via the CAPA API definitions. Instead create our own versions and where provide mapping functions. 10 11 For example: 12 13 - AWS SDK [InstaneState](https://docs.aws.amazon.com/sdk-for-go/api/service/ec2/) 14 - CAPA [InstanceState](https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/api/v1beta1/types.go#L560:L581) 15 16 ### Don't use struct pointer slices 17 18 When adding new fields to an API type don't use a slice of struct pointers. This can cause issues with the code generator for the conversion functions. Instead use struct slices. 19 20 For example: 21 22 Instead of this 23 24 ```go 25 // Configuration options for the non root storage volumes. 26 // +optional 27 NonRootVolumes []*Volume `json:"nonRootVolumes,omitempty"` 28 ``` 29 30 use 31 32 ```go 33 // Configuration options for the non root storage volumes. 34 // +optional 35 NonRootVolumes []Volume `json:"nonRootVolumes,omitempty"` 36 ``` 37 38 And then within the code you can check the length or range over the slice. 39 40 ## Tests 41 42 There are three types of tests written for CAPA controllers in this repo: 43 * Unit tests 44 * Integration tests 45 * E2E tests 46 47 In these tests, we use [fakeclient](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/client/fake), [envtest](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/envtest) and [gomock](https://pkg.go.dev/github.com/golang/mock/gomock) libraries based on the requirements of individual test types. 48 49 If any new unit, integration or E2E tests has to be added in this repo,we should follow the below conventions. 50 51 ### Unit tests 52 These tests are meant to verify the functions inside the same controller file where we perform sanity checks, functionality checks etc. 53 These tests go into the file with suffix *_unit_test.go. 54 55 ### Integration tests 56 These tests are meant to verify the overall flow of the reconcile calls in the controllers to test the flows for all the services/subcomponents of controllers as a whole. 57 These tests go into the file with suffix *_test.go. 58 59 ### E2E tests 60 These tests are meant to verify the proper functioning of a CAPA cluster in an environment that resembles a real production environment. For details, refer [here](https://cluster-api-aws.sigs.k8s.io/development/e2e.html).