-
Notifications
You must be signed in to change notification settings - Fork 848
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
Fakes Support #16613
Comments
A mock client like in the case of |
please priority this request, this is blocking AKS from moving to track2 API. we rely on interface for our unittest too. |
I really don't think we need interfaces for all clients. these can be written by the consumer. what does help testability is some test fakes for some particular constructs.
|
we definitely need and all BeginCreateOrUpdate/BeginDelete return this Interface, instead of concrete type. @serbrech how do you get around this issue? |
Returning an interface is not versioning tolerant, and we explicitly chose not to do that here for this reason. Here's an example of how you could create a mock |
|
A We can (and do) change the implementation without the need for a public interface. |
as I said, the only part that felt less test friendly was the poller. but with a little helper, it became quite straight forward.
|
The gist from @jhendrixMSFT also works by decorating the real client. it's probably simpler than our own setup in fact. |
No matter how you go, the interface changes completely between track1 and track2, so in the scope of a migration from track1 to track2, asking for the interfaces in track 2 does not reduce the work of the migration at all. you might as well generate the minimal interface you need yourself. That will ensure that you control how they look, and you are still free to put an adapter in between if you want a different api for your service. It also doesn't impose this unnecessary requirement on the SDK |
I do think that the SDK team should spend time writing client tests as an exercise, and documenting how they expect the end user to fake the clients. When I search the SDK repo for how you test the functionality, I found many occurences where your tests would instanciate an internal struct that wouldn't be accessible to me. (the poller for example). That would force you to think about testability from the end user perspective. Maybe it will drive some API changes, or drive the creation of a test helper package. |
We've done this to some degree, and it did end up slightly changing some of the APIs (earlier iterations of the Poller weren't mocking friendly at all). For mocking, there are various tools floating around can be used to generate interfaces/stubs, so we didn't feel the need to generate them ourselves (there's also the whole "don't overuse mocks" so we wanted to explore other options). I can put together a doc/sample of how this would work. Internally, we've been using recordings which works well but comes with its own baggage. We also haven't productized our recording framework at present, though there have been some asks for this. I've also been experimenting with how we could achieve a fake, similar to what GCP offers (example). I'm hacking on a rough prototype to see if it has any merit. The nice thing is that this doesn't require any changes to the client; you just plug in the fake via the client options. client, err := armresources.NewClient("subID", &fakeTokenCredential{}, &arm.ClientOptions{
ClientOptions: azcore.ClientOptions{
Transport: NewFakeARMResourcesServer(&myFakeARMResourcesServer{}), // magic happens here
},
}) The fakes would likely be codegen'ed but live elsewhere (sub-package, or possibly separate repo?). |
fake/mock on transport layer would require us to carry raw request payload. while we prefer fake/mock on client layer, so we can just mock/fake the object directly. |
It doesn't have to, and my current prototype doesn't require raw payloads. |
This is my fake server proof-of-concept. https://gist.github.com/jhendrixMSFT/efd5bcc94f2d545b5cb3a4f5e66446f4 It fakes three APIs from |
I like this direction @jhendrixMSFT. you provide testability without compromising the API, and the consumer still have all the flexibility they want. As a consumer, if you're ok generating mocks for your tests, you might as well generate the interfaces too. |
@jhendrixMSFT any tentative timeline when fakes would be available? |
We've been performing some internal user-studies on a few different designs. And while I think we're close, the final design hasn't landed yet. The current prototype, which hasn't incorporated feedback from our last round of internal testing, can be found here if you'd like to see the direction we're going. |
Thanks @jhendrixMSFT ! |
@jhendrixMSFT This kind of approach will work nicely but you will need to expose another variable to each We are heavy users of mock/unit-test for all the big cloud providers so this will be super valuable to us instead of writing interfaces manually for the Azure SDK. |
actually we don't care version tolerant for those interface, we only care if it's mock friendly. (assume you publish interface per version, and I don't think you can easily publish interface regulate all versions) bump version is a manual process with pull-request anyway, we used to update code along version bump. |
@unmarshall thanks for the feedback. Indeed we have a problem here when executing faked pager/poller APIs concurrently. I'll take a look at how we can fix this. |
@unmarshall we've released updated betas with a fix for this. |
@jhendrixMSFT I was trying to write tests using fake package for |
@unmarshall unfortunately we don't have any such construct as we only generate client-side content. |
Thanks for your response. With the introduction of fakes, do you think such a thing would be helpful to write tests? |
@jhendrixMSFT I was writing fake implementation for |
@jhendrixMSFT Any timeline when fake support will be out of beta? |
@unmarshall we've been conducting some user-studies the past few weeks to see where we can make improvements. Those have concluded, so we're working on incorporating the feedback. I'm hoping that this can go GA in our September release but I'm not 100% sure yet. |
|
@jhendrixMSFT Any update on the promotion of fakes support to GA? |
Yes! I meant to post this earlier here but got sidetracked. We're going to GA fakes in our November release window. So, the first week of November we'll release |
thanks so much for this update with general timelines, super helpful for planning the refactor to take advantage of these new features |
Congrats to you and the SDK team on this accomplishment @jhendrixMSFT! We greatly appreciate the transparency and active engagement! 🎉 |
Just a heads-up to folks using fakes that |
All of the ARM SDKs have been updated with fakes support. |
@jhendrixMSFT - |
@unmarshall we haven't considered adding fakes to |
@jhendrixMSFT : Hi, I noticed that the latest SDK has key vault secrets and keys fake clients (in |
Hmm I don't see a client for certificates in |
So, I may be looking incorrectly. Let's see...
Perhaps I'm not implementing this correctly? I'm just starting at this... |
Thanks for clarifying. We've only enabled fakes for the ARM SDKs, i.e. the ones under |
Thanks for putting together the fake library. It makes testing my codes much easier. Is there a plan to do the same for |
I'd love to see fakes directly provided by type azureBlobishClient interface {
UploadStream(ctx context.Context, containerName string, blobName string, body io.Reader, o *azblob.UploadStreamOptions) (azblob.UploadStreamResponse, error)
DownloadStream(ctx context.Context, containerName string, blobName string, o *azblob.DownloadStreamOptions) (azblob.DownloadStreamResponse, error)
} Obviously just expand the interface for whatever methods you need to use in production code path. |
Thanks @discentem ! I laugh-cried at your message because that's exactly what I had for my project in lieu of an official |
Unfortunately, I don't have a good timeline for fakes in |
Hi @MartinForReal, we deeply appreciate your input into this project. Regrettably, this issue has remained inactive for over 2 years, leading us to the decision to close it. We've implemented this policy to maintain the relevance of our issue queue and facilitate easier navigation for new contributors. If you still believe this topic requires attention, please feel free to create a new issue, referencing this one. Thank you for your understanding and ongoing support. |
I'm wondering if there will be support for mock client because it will help end user develop unit test case.
The text was updated successfully, but these errors were encountered: