Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fake client for unit testing #524

Open
kevingessner opened this issue Apr 27, 2018 · 33 comments
Open

fake client for unit testing #524

kevingessner opened this issue Apr 27, 2018 · 33 comments
Assignees
Labels
lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.

Comments

@kevingessner
Copy link

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.

@AlexShemeshWix
Copy link

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.

@sayarg
Copy link

sayarg commented Feb 7, 2019

is this on the radar / roadmap? it would be extremely useful!

@fejta-bot
Copy link

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

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 8, 2019
@micw523
Copy link
Contributor

micw523 commented May 9, 2019

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label May 9, 2019
@sonnysideup
Copy link

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?

@fejta-bot
Copy link

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

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 17, 2019
@NissesSenap
Copy link

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Nov 19, 2019
@irvifa
Copy link
Member

irvifa commented Jan 1, 2020

Any exact roadmap on this one?

@darktempla
Copy link

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.

@arielb135
Copy link

just saying that i need that too, i'm currently mocking my usages of the API and this is alot of work

@palnabarun
Copy link
Member

/assign

@fejta-bot
Copy link

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

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 23, 2020
@bguseman
Copy link

bguseman commented Jul 9, 2020

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jul 9, 2020
@aflag
Copy link

aflag commented Aug 19, 2020

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.

@NickLarsenNZ
Copy link

Back to Go it is

@shiba24
Copy link

shiba24 commented Oct 4, 2020

+1 for this feature - one option may be like moto library for AWS services, create a decorator-based one?
https://github.com/spulec/moto

@askreet
Copy link

askreet commented Dec 16, 2020

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.

@fejta-bot
Copy link

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

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Mar 16, 2021
@kdebisschop
Copy link

@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?

@fejta-bot
Copy link

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

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 5, 2021
@mayeuldalzon
Copy link

mayeuldalzon commented May 12, 2021

+1 for this feature very useful

@palnabarun
Copy link
Member

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Jun 7, 2021
@palnabarun
Copy link
Member

@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.

@palnabarun
Copy link
Member

/lifecycle frozen

(applying the label to not mark it as stale again until we have some mock designs)

@k8s-ci-robot k8s-ci-robot added the lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. label Jun 7, 2021
@TomaszKlosinski
Copy link

That would be an awesome feature for operator testing.

@bubthegreat
Copy link

bubthegreat commented Aug 4, 2022

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?

@PatrikDubec
Copy link

I would appreciate this feature too.

@allenmqcymp
Copy link

Any progress on this?

@Pithikos
Copy link

Yes, this would be great if it's in progress

@daveortiz-ctct
Copy link

+1 on this

@olsenbudanur
Copy link

another +1 on this

@yafimvo
Copy link

yafimvo commented Oct 23, 2024

another +2

@olsenbudanur
Copy link

Simple example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness.
Projects
None yet
Development

No branches or pull requests