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
Currently, koof.testing.KopfRunner provides a way to run an operator in the background while running a test or a piece of code. The only way to assert anything is to check the resources themselves.
That would be much more helpful, if some internals are exposed on what is happening inside.
Easier assertions on the outcomes of the operator actions, in a form of a little DSL for the Outcome & Outcomes & State classes.
A runner for predefined registry rather than only a CLI runner (as it is now).
Pytest fixtures to simplify a background operator running, while populating it inside of the tests/fixtures (not pre-populated).
Maybe something more. The issue is to be finished.
A general goal: Testing the operator should be as easy as developing it, i.e. expressing the ideas in few lines of code, and preferably so that a test fits on one screen/slide (as a measure of simplicity).
importkopfimportpykubeclassKopfExample(pykube.objects.NamespacedAPIObject):
version="zalando.org/v1"endpoint="kopfexamples"kind="KopfExample"deftest_me(kopf_operator):
# Add handlers to a LIVE operator on the go.kopf_runner.load('myapp/handlers.py')
# Create an resource.api=pykube.HTTPClient(pykube.KubeConfig.from_env())
kex1=KopfExample(api, {
'metadata': {'name': 'kex1'},
'spec': {'duration': '3m'},
})
kex1.create()
# Block the test until some internal condition is reached.kopf_runner.wait_until_handled(kex1.obj, timeout=100)
# Assert what happened internally.assertlen(kopf_runner.reactions) ==1# not overreacting :-) assertkopf_runner.reactions[-1].cause.reason==kopf.Reason.CREATEassertkopf_runner.reactions[-1].cause.body['metadata']['name'] =='kex1'assertkopf_runner.reactions[-1].handlers['create_fn'].duration<=30# secondsassertkopf_runner.reactions[-1].handlers['create_fn'].retries==1# no retriesassertkopf_runner.reactions[-1].handlers['create_fn'].outcomes[-1].result=='result'assertkopf_runner.reactions[-1].handlers['create_fn'].outcomes[-1].exceptionisNone# Assert what happened externally.kex1.reload()
assertkex1.status['create_fn'] =='result'
The text was updated successfully, but these errors were encountered:
Currently, koof.testing.KopfRunner provides a way to run an operator in the background while running a test or a piece of code. The only way to assert anything is to check the resources themselves.
That would be much more helpful, if some internals are exposed on what is happening inside.
A/C:
Handler outcomes exposed for tests (as introduces in [PR] Refactoring 4/3: In-memory handler outcomes & persistent state merges #221). Including all the outcomes if there were few retries.
Easier assertions on the outcomes of the operator actions, in a form of a little DSL for the
Outcome
&Outcomes
&State
classes.A runner for predefined registry rather than only a CLI runner (as it is now).
Pytest fixtures to simplify a background operator running, while populating it inside of the tests/fixtures (not pre-populated).
Maybe something more. The issue is to be finished.
A general goal: Testing the operator should be as easy as developing it, i.e. expressing the ideas in few lines of code, and preferably so that a test fits on one screen/slide (as a measure of simplicity).
For example (but not for definition):
The text was updated successfully, but these errors were encountered: