python
python copied to clipboard
fake client for unit testing
Kubernetes's client-go includes a powerful "fake" library (https://godoc.org/k8s.io/client-go/kubernetes/fake), which provides a mock API client that handles reads and writes without a cluster. It enables unit testing of code that uses client-go. This blog post has examples of how it's used: https://medium.com/@e_frogers/unit-testing-with-kubernetes-client-go-283b11aaa7db
Could this library provide a similar mock interface? I think a fake kubernetes.client.ApiClient
that works in-process instead of over HTTP (like the go fake client) would be perfect: it would be injectable into the existing clients to allow full testing.
That would be a great feature. Im using go-client for k8s and im able to do integration tests in memory. Saves a lot of time.
is this on the radar / roadmap? it would be extremely useful!
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale
/remove-lifecycle stale
I have to write some automation using Python (I wish it could be in Golang) and a fake client or, at the very least, some documentation on how to write tests when using this library would be helpful.
Can a maintainer at least touch on this subject?
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale
/remove-lifecycle stale
Any exact roadmap on this one?
Totally agree. Usually I just look at a repos unit tests to see how the contributors have mocked out their class etc but blank stubs when look in the test folder.
Any update on this one.
just saying that i need that too, i'm currently mocking my usages of the API and this is alot of work
/assign
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale
/remove-lifecycle stale
Just been bitten by this too. I wrote an ad-hoc fake for the things I use. But not very happy with that. Looking online I couldn't find any evidence of anyone doing anything better 😢 In some cases I'd just write integration tests, but my current scenario isn't really easy to run as an integration test.
Back to Go it is
+1 for this feature - one option may be like moto
library for AWS services, create a decorator-based one?
https://github.com/spulec/moto
I agree this would be useful if provided first-hand by the client. I've been able to streamline mocked responses by doing things like:
class FakeResponse:
def __init__(self, filename):
with open(filename) as file:
self.data = file.read()
configmaps = client.CoreV1Api().api_client.deserialize(FakeResponse('my-fixture.json'), 'V1ConfigMapList')
I build the fixtures by using kubectl:
kubectl get configmaps --namespace my-namespace -o yaml > my-fixture.json
Hope this helps someone fill the gap until this library has a better solution.
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale
@palnabarun it looks you self-assigned this. It seems like a tough nut to crack. Have you made any progress? Is there anything I can do to help?
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten
.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten
+1 for this feature very useful
/remove-lifecycle rotten
@kdebisschop -- No, I haven't been able to devote time to this. In the meanwhile, if you or anyone wants to take a dig at it, please feel free to do so and update the findings here.
/lifecycle frozen
(applying the label to not mark it as stale again until we have some mock designs)
That would be an awesome feature for operator testing.
kubectl get configmaps --namespace my-namespace -o yaml > my-fixture.json
@askreet Am I reading this right that you're loading the yaml into a json or was that a typo?
I would appreciate this feature too.
Any progress on this?
Yes, this would be great if it's in progress
+1 on this