-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Using v15.0.0 of the Go client.
What were you hoping/trying to do?
I'm currently trying to upgrade from an old version of the LaunchDarkly Go client to latest version. I have a number of tests that were able to mock the old client. I'd like to be able to mock out the methods of the new client as well.
What is the issue you're running into?
It is not currently possible to mock out the generated Go API client for testing. The current client exposes access to each of the LaunchDarkly API endpoints through a pair of methods on the ...ApiService type. For example, in the case of deleting tokens, these methods are DeleteTokens(... and DeleteTokensExecute(... on the AccessTokensApiService type. The DeleteTokens(... method returns a request object, ApiDeleteTokensRequest, that can be further modified. When the caller has set all the needed fields on the request, they can call .Execute() on the request object, which dispatches to the underlying client's .DeleteTokensExecute method. The request object dispatches to this underlying client by keeping a reference to the client on the request. In version v15.0.0 of the LaunchDarkly client that reference is a concrete type, not an interface.
This implementation prevents the creation of a mock because the DeleteTokens(... method has to return a request object with a concrete, non-mocked client, set on it. Meaning, even if you define your own interface to wrap the DeleteTokens method, there still needs to be a concrete non-interface on the request eventually.
The openapi generator exposes a flag, generateIntrefaces, to instead generate interfaces and use the interface type on the request objects instead of a concrete type.
Currently, I'm generating a client myself as a workaround. It would be great if the client generated clients distributed in the Go client repo were created with this parameter.
Let me know if there are any questions about the above or if I've missed something!