mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-09 17:27:28 +00:00
Merge pull request #1976 from fluxcd/e2e-run-docs
Install envtest before running the unit tests
This commit is contained in:
commit
5c60e792d9
2 changed files with 29 additions and 10 deletions
|
|
@ -63,27 +63,42 @@ To get started with developing controllers, you might want to review
|
|||
walks you through writing a short and concise controller that watches out
|
||||
for source changes.
|
||||
|
||||
### How to run the test suite
|
||||
## How to run the test suite
|
||||
|
||||
Prerequisites:
|
||||
|
||||
* go >= 1.16
|
||||
* kubectl >= 1.18
|
||||
* kustomize >= 3.1
|
||||
* kubectl >= 1.19
|
||||
* kustomize >= 4.0
|
||||
|
||||
You can run the unit tests by simply doing
|
||||
Install the [controller-runtime/envtest](https://github.com/kubernetes-sigs/controller-runtime/tree/master/tools/setup-envtest) binaries with:
|
||||
|
||||
```bash
|
||||
make install-envtest
|
||||
```
|
||||
|
||||
Then you can run the unit tests with:
|
||||
|
||||
```bash
|
||||
make test
|
||||
```
|
||||
|
||||
The e2e test suite uses [kind](https://kind.sigs.k8s.io/) for running kubernetes cluster inside docker containers. You can run the e2e tests by simply doing
|
||||
After [installing Kubernetes kind](https://kind.sigs.k8s.io/docs/user/quick-start#installation) on your machine,
|
||||
create a cluster for testing with:
|
||||
|
||||
```bash
|
||||
make setup-kind
|
||||
make e2e
|
||||
```
|
||||
|
||||
# When done
|
||||
Then you can run the end-to-end tests with:
|
||||
|
||||
```bash
|
||||
make e2e
|
||||
```
|
||||
|
||||
Teardown the e2e environment with:
|
||||
|
||||
```bash
|
||||
make cleanup-kind
|
||||
```
|
||||
|
||||
|
|
|
|||
10
Makefile
10
Makefile
|
|
@ -2,7 +2,7 @@ VERSION?=$(shell grep 'VERSION' cmd/flux/main.go | awk '{ print $$4 }' | head -n
|
|||
EMBEDDED_MANIFESTS_TARGET=cmd/flux/.manifests.done
|
||||
TEST_KUBECONFIG?=/tmp/flux-e2e-test-kubeconfig
|
||||
ENVTEST_BIN_VERSION?=latest
|
||||
KUBEBUILDER_ASSETS?="$(shell $(SETUP_ENVTEST) use -i $(ENVTEST_BIN_VERSION) -p path)"
|
||||
KUBEBUILDER_ASSETS?=$(shell $(SETUP_ENVTEST) use -i $(ENVTEST_BIN_VERSION) -p path)
|
||||
|
||||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
|
||||
ifeq (,$(shell go env GOBIN))
|
||||
|
|
@ -33,13 +33,13 @@ cleanup-kind:
|
|||
kind delete cluster --name=flux-e2e-test
|
||||
rm $(TEST_KUBECONFIG)
|
||||
|
||||
test: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet setup-envtest
|
||||
test: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet install-envtest
|
||||
KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... -coverprofile cover.out --tags=unit
|
||||
|
||||
e2e: $(EMBEDDED_MANIFESTS_TARGET) tidy fmt vet
|
||||
TEST_KUBECONFIG=$(TEST_KUBECONFIG) go test ./cmd/flux/... -coverprofile e2e.cover.out --tags=e2e -v -failfast
|
||||
|
||||
test-with-kind: setup-envtest
|
||||
test-with-kind: install-envtest
|
||||
make setup-kind
|
||||
make e2e
|
||||
make cleanup-kind
|
||||
|
|
@ -58,6 +58,10 @@ install:
|
|||
install-dev:
|
||||
CGO_ENABLED=0 go build -o /usr/local/bin ./cmd/flux
|
||||
|
||||
|
||||
install-envtest: setup-envtest
|
||||
$(SETUP_ENVTEST) use $(ENVTEST_BIN_VERSION)
|
||||
|
||||
# Find or download setup-envtest
|
||||
setup-envtest:
|
||||
ifeq (, $(shell which setup-envtest))
|
||||
|
|
|
|||
Loading…
Reference in a new issue