diff --git a/dev/vscode-example-configuration/settings.json b/dev/vscode-example-configuration/settings.json new file mode 100644 index 000000000000..bbade3fe7cd0 --- /dev/null +++ b/dev/vscode-example-configuration/settings.json @@ -0,0 +1,3 @@ +{ + "go.testEnvFile": "${workspaceFolder}/.vscode/test.env" +} \ No newline at end of file diff --git a/dev/vscode-example-configuration/tasks.json b/dev/vscode-example-configuration/tasks.json new file mode 100644 index 000000000000..4629a886b51f --- /dev/null +++ b/dev/vscode-example-configuration/tasks.json @@ -0,0 +1,32 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "type": "shell", + "label": "sigs.k8s.io/cluster-api: Prepare vscode to run envtest-based tests", + "detail": "Install envtest and configure the vscode-go test environment.", + "group": { + "kind": "test", + "isDefault": true + }, + "command": [ + "echo $(make setup-envtest) > ${workspaceFolder}/.vscode/test.env", + ], + "presentation": { + "echo": true, + "reveal": "silent", + "focus": true, + "panel": "shared", + "showReuseMessage": true, + "clear": false + }, + "runOptions": { + "runOn": "folderOpen", + "instanceLimit": 1, + }, + "promptOnClose": true, + } + ] +} \ No newline at end of file diff --git a/dev/vscode-example-configuration/test.env b/dev/vscode-example-configuration/test.env new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docs/book/src/developer/repository-layout.md b/docs/book/src/developer/repository-layout.md index dc918cef3051..bc6936fd314c 100644 --- a/docs/book/src/developer/repository-layout.md +++ b/docs/book/src/developer/repository-layout.md @@ -12,6 +12,7 @@ cluster-api └───config └───controllers └───controlplane +└───dev └───docs └───errors └───exp @@ -115,6 +116,10 @@ This folder has scripts used for building, testing and developer workflow. This folder consists of CI scripts related to setup, build and e2e tests. These are mostly called by CI jobs. +[~/dev](https://github.com/kubernetes-sigs/cluster-api/tree/main/dev) + +This folder has example configuration for integrating Cluster API development with tools like IDEs. + ### Util, Feature and Errors [~/util](https://github.com/kubernetes-sigs/cluster-api/tree/main/util) diff --git a/docs/book/src/developer/testing.md b/docs/book/src/developer/testing.md index 91bc5673b2c0..1d60fec1cdf2 100644 --- a/docs/book/src/developer/testing.md +++ b/docs/book/src/developer/testing.md @@ -95,6 +95,8 @@ but in this case the distinctive value of the two layers of testing is determine Run `make test` to execute all unit and integration tests. +Integration tests use the [envtest](https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/envtest/doc.go) test framework. The tests need to know the location of the executables called by the framework. The `make test` target installs these executables, and passes this location to the tests as an environment variable. + +### Test execution via IDE + +Your IDE needs to know the location of the executables called by the framework, so that it can pass the location to the tests as an environment variable. + + + +#### VSCode + +The `dev/vscode-example-configuration` directory in the repository contains an example configuration that integrates VSCode with the envtest framework. + +To use the example configuration, copy the files to the `.vscode` directory in the repository, and restart VSCode. + +The configuration works as follows: Whenever the project is opened in VSCode, a VSCode task runs that installs the executables, and writes the location to a file. A setting tells [vscode-go] to initialize the environment from this file. + ## End-to-end tests The end-to-end tests are meant to verify the proper functioning of a Cluster API management cluster @@ -536,3 +562,5 @@ In Cluster API Unit and integration test MUST use [go test]. [envtest]: https://github.com/kubernetes-sigs/controller-runtime/tree/master/pkg/envtest [fakeclient]: https://github.com/kubernetes-sigs/controller-runtime/tree/master/pkg/client/fake [test/helpers]: https://github.com/kubernetes-sigs/cluster-api/tree/main/test/helpers + +[vscode-go]: https://marketplace.visualstudio.com/items?itemName=golang.Go \ No newline at end of file