Skip to content

Commit e5445ae

Browse files
chore: improve e2e tests (#521)
Signed-off-by: Kavindu Dodanduwa <[email protected]> Signed-off-by: Kavindu Dodanduwa <[email protected]> Co-authored-by: Florian Bacher <[email protected]>
1 parent 4d5dfdd commit e5445ae

File tree

18 files changed

+69
-370
lines changed

18 files changed

+69
-370
lines changed

Makefile

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,23 @@ vet: ## Run go vet against code.
6565
unit-test: manifests fmt vet generate envtest ## Run tests.
6666
go test ./... -v -short -coverprofile cover.out
6767

68-
## Requires the operator to be deployed
69-
.PHONY: e2e-test
70-
e2e-test: manifests generate fmt vet
71-
kubectl -n open-feature-operator-system apply -f ./test/e2e/e2e.yml
72-
kubectl wait --for=condition=Available=True deploy --all -n 'open-feature-operator-system'
73-
./test/e2e/run.sh
74-
75-
.PHONY: e2e-test-kuttl #these tests should run on a real cluster!
68+
## e2e tests require the operator to be deployed in a real cluster
69+
.PHONY: e2e-test-kuttl
7670
e2e-test-kuttl:
77-
kubectl kuttl test --start-kind=false ./test/e2e/kuttl --config=./kuttl-test.yaml
71+
kubectl kuttl test --start-kind=false --config=./kuttl-test.yaml
7872

79-
.PHONY: e2e-test-kuttl-local #these tests should run on a real cluster!
73+
.PHONY: e2e-test-kuttl-local
8074
e2e-test-kuttl-local:
81-
kubectl kuttl test --start-kind=false ./test/e2e/kuttl/scenarios --config=./kuttl-test-local.yaml
75+
kubectl kuttl test --start-kind=false --config=./kuttl-test-local.yaml
76+
77+
.PHONY: e2e-test-validate-local
78+
e2e-test-validate-local:
79+
docker build . -t open-feature-operator-local:validate
80+
kind create cluster --config ./test/e2e/kind-cluster.yml --name e2e-tests
81+
kind load docker-image open-feature-operator-local:validate --name e2e-tests
82+
IMG=open-feature-operator-local:validate make deploy-operator
83+
IMG=open-feature-operator-local:validate make e2e-test-kuttl
84+
kind delete cluster --name e2e-tests
8285

8386
.PHONY: lint
8487
lint:

docs/development_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Run `make test` to run the test suite. The controller integration tests use [env
1313
This provides means of asserting that the Kubernetes components reach the desired state without the overhead of using an actual cluster, keeping
1414
test runtime and resource consumption down.
1515

16-
An e2e test suite can also be found in the [`/test/e2e`](../test/e2e/DEVELOPER.md) directory. These tests are run as part of the `pr-lint` github action, they work by deploying an nginx reverse proxy and asserting that curls to the proxy elicit expected behaviour from the flagd sidecar created by open-feature-operator.
16+
An e2e test suite can also be found in the [`/test/e2e`](../test/e2e/README.md) directory. These tests are run as part of the `pr-checks` github action, they work by deploying an nginx reverse proxy and asserting that curls to the proxy elicit expected behaviour from the flagd sidecar created by open-feature-operator.
1717

1818
## Releases
1919

kuttl-test-local.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: kuttl.dev/v1
22
kind: TestSuite
33
crdDir: ./config/crd/bases
44
testDirs:
5-
- ./test/e2e/kuttl/scenarios/
5+
- ./test/e2e/kuttl
66
timeout: 300

kuttl-test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ apiVersion: kuttl.dev/v1
22
kind: TestSuite
33
crdDir: ./config/crd/bases
44
testDirs:
5-
- ./test/e2e/kuttl/scenarios/
5+
- ./test/e2e/kuttl
66
timeout: 300
7-
skipDelete: true
7+
skipDelete: true # skip removing test related resources (ex:- namespaces)

test/e2e/DEVELOPER.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/e2e/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# E2E Testing
2+
3+
This suite tests the end-to-end operation of the open-feature-operator.
4+
5+
Tests are written with [kuttl](https://kuttl.dev/) and assertions are executed from a curl enabled Job.
6+
Ngnix reverse proxy is used as the workload where flagd get injected using OFO annotations.
7+
8+
## Running and validating locally
9+
10+
It is recommended to run and validate e2e test locally before opening a pull request.
11+
12+
To run locally (commands are executed from the project root level),
13+
14+
1. Build the operator locally - `docker build . -t open-feature-operator-local:validate`
15+
2. Create a kind cluster - `kind create cluster --config ./test/e2e/kind-cluster.yml --name e2e-tests`
16+
3. Load locally build operator image - `kind load docker-image open-feature-operator-local:validate --name e2e-tests`
17+
4. Deploy Operator to kind cluster - `IMG=open-feature-operator-local:validate make deploy-operator`
18+
5. Execute kuttl tests - `IMG=open-feature-operator-local:validate make e2e-test-kuttl`
19+
20+
Alternatively, you can use `e2e-test-validate-local` Makefile rule to execute all above and cleanup the kind cluster,
21+
22+
> make e2e-test-validate-local
23+
24+
After the test run, make sure test status by validating kuttl output,
25+
26+
```text
27+
--- PASS: kuttl (48.71s)
28+
--- PASS: kuttl/harness (0.00s)
29+
--- PASS: kuttl/harness/assets (0.01s)
30+
--- PASS: kuttl/harness/flagd-disabled (12.58s)
31+
--- PASS: kuttl/harness/inject-flagd (26.41s)
32+
--- PASS: kuttl/harness/fsconfig-file-sync (31.73s)
33+
--- PASS: kuttl/harness/fsconfig-k8s-sync (31.74s)
34+
--- PASS: kuttl/harness/fsconfig-flagd-proxy-sync (48.49s)
35+
```
36+
37+
### Running individual tests
38+
39+
You can use kuttl command options to execute individual tests. Consider the example command below,
40+
41+
>$ kubectl kuttl test --start-kind=false ./test/e2e/kuttl --config=kuttl-test.yaml --test=flagd-disabled

test/e2e/e2e.yml

Lines changed: 0 additions & 137 deletions
This file was deleted.

test/e2e/flag-evaluation.sh

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/e2e/kuttl/flagd-disabled/00-assert.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ apiVersion: kuttl.dev/v1beta1
22
kind: TestAssert
33
commands:
44
- command: kubectl wait --for=condition=complete job flagd-query-test -n $NAMESPACE
5+
collectors:
6+
- command: kubectl logs -l job-name=flagd-query-test -n $NAMESPACE

test/e2e/kuttl/fsconfig-file-sync/00-assert.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ apiVersion: kuttl.dev/v1beta1
22
kind: TestAssert
33
commands:
44
- command: kubectl wait --for=condition=complete job flagd-query-test -n $NAMESPACE
5+
collectors:
6+
- command: kubectl logs -l job-name=flagd-query-test -n $NAMESPACE

0 commit comments

Comments
 (0)