You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/openshift/e2e/README.md
+206-1Lines changed: 206 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -103,7 +103,7 @@ These tests are written with the [Ginkgo/Gomega test frameworks](https://github.
103
103
### Tests are currently grouped as follows:
104
104
-`sequential`: Tests that are not safe to run in parallel with other tests.
105
105
- A test is NOT safe to run in parallel with other tests if:
106
-
- It modifies resources in `openshift-gitops`
106
+
- It modifies resources in `openshift-gitops` or `openshift-gitops-operators` (or similar)
107
107
- It modifies the GitOps operator `Subscription`
108
108
- It modifies cluster-scoped resources, such as `ClusterRoles`/`ClusterRoleBindings`, or `Namespaces` that are shared between tests
109
109
- More generally, if it writes to a K8s resource that is used by another test.
@@ -112,6 +112,7 @@ These tests are written with the [Ginkgo/Gomega test frameworks](https://github.
112
112
- It is fine for a parallel test to read cluster-scoped resources (such as resources in openshift-gitops namespace)
113
113
- A parallel test should NEVER write to resources that may be shared with other tests (`Subscriptions`, some cluster-scoped resources, etc.)
114
114
115
+
*Guidance*: Look at the list of restrictions for sequential. If your test is doing any of those things, it needs to run sequential. Otherwise parallel is fine.
115
116
116
117
117
118
### Test fixture:
@@ -127,6 +128,201 @@ These tests are written with the [Ginkgo/Gomega test frameworks](https://github.
127
128
- 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.
128
129
- See existing k8s tests for usage examples.
129
130
131
+
132
+
## Writing new tests
133
+
134
+
Ginkgo tests are read from left to right. For example:
- Can be read as: Eventually the `(argo cd application controller pod)` should exist (within 3 minute, chekcing every 5 seconds.)
139
+
-`fixture.Update(argoCD, func(){ (...)})`
140
+
- Can be reas ad: Update Argo CD CR using the given function
141
+
142
+
143
+
The E2E tests we use within this repo uses the standard controller-runtime k8s go API to interact with kubernetes (controller-runtime). This API is very familiar to anyone already writing go operator/controller code (such as developers of this project).
144
+
145
+
The best way to learn how to write a new test (or matcher/fixture), is just to copy an existing one!
146
+
- There are 150+ existing tests you can 'steal' from, which provide examples of nearly anything you could want.
147
+
148
+
### Standard patterns you can use
149
+
150
+
#### To verify a K8s resource has an expected status/spec:
151
+
-`fixture` packages
152
+
- Fixture packages contain utility functions which exists for (nearly) all resources (described in detail elsewhere)
153
+
- Most often, a function in a `fixture` will already exist for what you are looking for.
154
+
- For example, use `argocdFixture` to check if Argo CD is available:
When to include a test in 'parallel' package, vs when to include a test in 'sequential' package? See elsewhere in this document for the exact criteria for when to include a test in parallel, and when to include it in sequential.
176
+
177
+
*General Guidance*: Look at the list of restrictions for sequential/parallel above.
178
+
- If your test is performing any restricted behaviours, it needs to run sequential. Otherwise parallel is fine.
179
+
- For example: if your test modifies ANYTHING in `openshift-gitops` Namespace, it's not safe to run in parallel. Include it in the `sequential` tests package.
180
+
181
+
182
+
#### When writing sequential tests, ensure you:
183
+
184
+
A) Call EnsureSequentialCleanSlate before each test:
185
+
```go
186
+
BeforeEach(func() {
187
+
fixture.EnsureSequentialCleanSlate()
188
+
}
189
+
```
190
+
191
+
Unlike with parallel tests, you don't need to clean up namespace after each test. Sequential will automatically cleanup namespaces created via the `fixture.Create(...)Namespace` API. (But if you want to delete it using `defer`, it doesn't hurt).
192
+
193
+
194
+
#### When writing parallel tests, ensure you:
195
+
196
+
A) Call EnsureParallelCleanSlate before each test
197
+
```go
198
+
BeforeEach(func() {
199
+
fixture.EnsureParallelCleanSlate()
200
+
})
201
+
```
202
+
203
+
B) Clean up any namespaces (or any cluster-scoped resources you created) using `defer`:
204
+
```go
205
+
// Create a namespace to use for the duration of the test, and then automatically clean it up after.
[**Ginkgo/Gomega docs**](https://onsi.github.io/gomega/): The Ginkgo/Gomega docs are great! they are very detailed, with lots of good examples. There are also plenty of other examples of Ginkgo/Gomega you can find via searching.
351
+
352
+
**Ask an LLM (Gemini/Cursor/etc)**: Ginkgo/gomega are popular enough that LLMs are able to answer questions and write code for them.
353
+
- For example, I performed the following Gemini Pro query, and got an excellent answer:
354
+
- `With Ginkgo/Gomega (https://onsi.github.io/gomega) and Go lang, how do I create a matcher which checks whether a Kubernetes Deployment (via Deployment go object) has ready replicas of 1`
0 commit comments