operator-framework / java-operator-sdk

Java SDK for building Kubernetes Operators
https://javaoperatorsdk.io/
Apache License 2.0
793 stars 213 forks source link

Unit testing support for Dependent Resources #1355

Closed csviri closed 1 year ago

csviri commented 2 years ago

Support for unit testing (mocking) should be improved for dependent resources. Currently for example for CRUDKubernetesDependentResource is calling eventsource().getSecondaryResource to load the actual state from cache. Eventually this as described on other issues:

https://github.com/java-operator-sdk/java-operator-sdk/issues/1175 https://github.com/java-operator-sdk/java-operator-sdk/issues/1240

might be better to call context.getSecondaryResource().

With this we could actually make it easy to support cache state for unit tests.

But we should also create examples, and support for client mocking.

Acceptance Criteria:

csviri commented 1 year ago

The problem here is that now dependent resources use also event source under the hood, (not to read the resource but to make sure some of the updates end up in the caches and similar tricks). It is quite hard to mock that all. But also conceptually, the framework tests dependent resources, so its kinda made sure those are tested. All the addition user does can be (desired state, matchers) tested separatettly by an unit test, what is trivial.