Skip to content

Commit 32a5773

Browse files
committed
Add Ginkgo test instructions via README.md
Signed-off-by: Jonathan West <jonwest@redhat.com>
1 parent 237427b commit 32a5773

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed

test/openshift/e2e/README.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Gitops-operator E2E Tests
2+
3+
gitops-operator E2E tests are defined within the `test/openshift/e2e/ginkgo` (as of this writing).
4+
5+
These tests are written with the Ginkgo/Gomega test framework, and were ported from previous Kuttl tests.
6+
7+
## Running tests
8+
9+
### A) Run tests against OpenShift GitOps installed via OLM
10+
11+
The E2E tests can be run from the `Makefile` at the root of the gitops-operator repository.
12+
13+
```bash
14+
# Run Sequential tests
15+
make e2e-tests-sequential-ginkgo
16+
# You can add 'SKIP_HA_TESTS=true' if you are on a cluster with <3 nodes
17+
# Example: 'SKIP_HA_TESTS=true make e2e-tests-sequential-ginkgo'
18+
19+
# Run Parallel tests (up to 5 tests will run at a time)
20+
make e2e-tests-parallel-ginkgo
21+
# As above, can add SKIP_HA_TESTS, if necessary.
22+
```
23+
24+
### B) Run E2E tests against local operator (operator running via `make run`)
25+
26+
```bash
27+
# 1) Start operator locally
28+
make run
29+
30+
# 2) Start tests in LOCAL_RUN mode (this skips tests that require Subscription or CSVs)
31+
LOCAL_RUN=true make e2e-tests-sequential-ginkgo
32+
# and/or
33+
LOCAL_RUN=true make e2e-tests-parallel-ginkgo
34+
# Not all tests are supported when running locally. See 'Skip' messages for details.
35+
```
36+
37+
### C) Run a specific test:
38+
39+
```bash
40+
# 'make ginkgo' to download ginkgo, if needed
41+
# Examples:
42+
./bin/ginkgo -v -focus "1-106_validate_argocd_metrics_controller" -r ./test/openshift/e2e/ginkgo/sequential
43+
./bin/ginkgo -v -focus "1-099_validate_server_autoscale" -r ./test/openshift/e2e/ginkgo/parallel
44+
```
45+
46+
## Configuring which tests run
47+
48+
Not all tests support all configurations:
49+
* For example, if you are running gitops-operator via `make run`, this blocks any tests that require changes to `Subscription`.
50+
* Thus, when running locally, you can set `LOCAL_RUN=true` to skip those unsupported tests.
51+
52+
There are a few environment variables that can be set to configure which tests run.
53+
54+
55+
### If you are running the gitops-operator via `make run` from your local machine
56+
57+
Some tests require the gitops-operator to be running on cluster (and/or installed via OLM).
58+
59+
BUT, this is not true when you are running the operator on your local machine during the development process.
60+
61+
You can skip non-local-supported tests by setting `LOCAL_RUN=true`:
62+
```bash
63+
LOCAL_RUN=true make e2e-tests-sequential-ginkgo
64+
# and/or
65+
LOCAL_RUN=true make e2e-tests-sequential-parallel
66+
```
67+
68+
69+
### If you are running tests on a cluster with < 3 nodes:
70+
71+
Tests that verify operator HA (e.g. Redis HA) behaviour require a cluster with at least 3 nodes. If you are running on a cluster with less than 3 nodes, you can skip these tests by setting `SKIP_HA_TESTS=true`:
72+
```bash
73+
SKIP_HA_TESTS=true make e2e-tests-sequential-ginkgo
74+
```
75+
76+
### If you are testing a gitops-operator install that is running on K8s cluster, but that was NOT installed via Subscription (OLM)
77+
78+
In some cases, you may want to run the gitops-operator tests against an install of OpenShift GitOps that was NOT installed via OLM, but IS running on cluster. For example, via a plain `Deployment` in the gitops operator Namepsace.
79+
80+
For this, you may use the `NON_OLM` env var:
81+
```bash
82+
NON_OLM=true make e2e-tests-sequential-ginkgo
83+
```
84+
85+
Note: If `LOCAL_RUN` is set, you do not need to set `NON_OLM` (it is assumed).
86+
87+
88+
### You can specify multiple test env vars at the same time.
89+
90+
For example, if you are running operator via `make run`, on a non-HA cluster (<3 nodes):
91+
```bash
92+
SKIP_HA_TESTS=true LOCAL_RUN=true make e2e-tests-sequential-ginkgo
93+
```
94+
95+
96+
97+
## Test Code
98+
99+
gitops-operator E2E tests are defined within `test/openshift/e2e/ginkgo`.
100+
101+
These tests are written with the [Ginkgo/Gomega test frameworks](https://github.com/onsi/ginkgo), and were ported from previous Kuttl tests.
102+
103+
### Tests are currently grouped as follows:
104+
- `sequential`: Tests that are not safe to run in parallel with other tests.
105+
- A test is NOT safe to run in parallel with other tests if:
106+
- It modifies resources in `openshift-gitops`
107+
- It modifies the GitOps operator `Subscription`
108+
- It modifies cluster-scoped resources, such as `ClusterRoles`/`ClusterRoleBindings`, or `Namespaces` that are shared between tests
109+
- More generally, if it writes to a K8s resource that is used by another test.
110+
- `parallel`: Tests that are safe to run in parallel with other tests
111+
- A test is safe to run in paralel if it does not have any of the above problematic behaviours.
112+
- It is fine for a parallel test to read cluster-scoped resources (such as resources in openshift-gitops namespace)
113+
- A parallel test should NEVER write to resources that may be shared with other tests (Subscriptions, some cluster-scoped resources, etc.)
114+
115+
116+
117+
### Test fixture:
118+
- Utility functions for writing tests can be found within the `fixture/` folder.
119+
- `fixture/fixture.go` contains utility functions that are generally useful to writing tests.
120+
- `fixture/(name of resource)` contains functions that are specific to working with a particular resource.
121+
- For example, if you wanted to wait for an `Application` CR to be Synced/Healthy, you would use the functions defined in `fixture/application`.
122+
- Likewise, if you want to check a `Deployment`, see `fixture/deployment`.
123+
- Fixtures exist for nearly all interesting resources
124+
- The goal of this test fixture is to make it easy to write tests, and to ensure it is easy to understand and maintain existing tests.
125+
- See existing k8s tests for usage examples.
126+
127+
## Tips for debugging tests
128+
129+
### If you are debugging tests in CI
130+
- If you are debugging a test failure, considering adding a call to the `fixture.OutputDebugOnFail()` function at the end of the test.
131+
- `OutputDebugOnFail` will output helpful information when a test fails (such as namespace contents and operator pod logs)
132+
- See existing test code for examples.
133+
134+
135+
### If you are debugging tests locally
136+
- Consider setting the `E2E_DEBUG_SKIP_CLEANUP` variable when debugging tests locally.
137+
- The `E2E_DEBUG_SKIP_CLEANUP` environment variable will skip cleanup at the end of the test.
138+
- The default E2E test behaviour is to clean up test resources at the end of the test.
139+
- This is good when tests are succeeding, but when they are failing it can be helpful to look at the state of those K8s resources at the time of failure.
140+
- Those old tests resources WILL still be cleaned up when you next start the test again.
141+
- This will allow you to `kubectl get` the test resource to see why the test failed.
142+
143+
Example:
144+
```bash
145+
E2E_DEBUG_SKIP_CLEANUP=true ./bin/ginkgo -v -focus "1-099_validate_server_autoscale" -r ./test/openshift/e2e/ginkgo/parallel
146+
```

0 commit comments

Comments
 (0)