-
Story
-
Resolution: Done
-
Normal
-
None
-
None
-
False
-
None
-
False
-
-
-
0
-
0
The current state of testing in OpenShift leaves a lot to be desired. We are overly reliant upon large E2E tests which typically target a live OpenShift cluster. This has numerous disadvantages, such as:
- Greater CI and infra expense
- Slow feedback loop
- Flaky tests
- Unknown test coverage level
- More difficult to debug
Having recently attended a Testing-CoP (Community of Practice) presentation by Andrea Fasano (recording / slides), I learned about a couple of tools and techniques that can improve our overall test coverage and can help us have a faster developer feedback loop.
In particular, I learned about EnvTest and FakeClient. I was already aware of EnvTest because Joel Speed introduced a few integration tests to our repository that uses EnvTest to essentially spin up an in-memory environment to test parts of an operator. FakeClient is part of the official Kubernetes client-go package and is essentially what it says; a fake version of the Kube API client that one can pass in for testing purposes. It's worth mentioning that the code generation steps for the MCO API also generates fake versions of its clients.
With these two libraries in mind, we can create a suite of integration tests which can run locally on someone’s workstation without requiring an OpenShift cluster to be available. Additionally, these can be run in CI in a fraction of the time our E2E suite takes to run.
Done When:
- An MCO component is identified that would be straightforward to test using either EnvTest or FakeClient. At first glance, the Drain Controller might be a good candidate.
- At least one passing integration test for that component is written using either EnvTest or FakeClient (or both!).
- A PR to the MCO repository is merged which contains this integration test.
- A write-up of lessons learned / overall experience is shared with the MCO team and / or a broader audience.