stripe-go
stripe-go copied to clipboard
Create A Mock Test Client
Proposed Feature
After implementing the Golang SDK there could possibly be a better test suite that can be created. For instance the current issue I am having is mocking a response from:
stripeClient.Invoices.List(params)
My thinking here would be to approach this how kubernetes has with their fake client. I understand there are many ways to mock out responses (This could definitely be documented better). However it seems that having the ability to do something along the lines of:
stripeClient := &stripeFakeClient{}
stripeClient.Invoices.Create(*Invoices{//Some Random Invoice Data})
resp := stripeClient.Invoices.List(params)
without actually calling the API would make integration with your platform a lot more seamless and speed up the process.
@meggieveggie Thanks for the feedback. We usually recommend using stripe-mock for something like this which is what we use in our test suite. You can read more about this here: https://github.com/stripe/stripe-mock/ Would that work for you?
@remi-stripe My understanding of stripe-mock is that it is specifically used for integration tests and not unit tests. If this is not the case then I will try and use stripe-mock
@meggieveggie thank you for this suggestion. You are correct in that stripe-mock is built mainly for integration tests, but it should still allow you to quickly test your integration without actually hitting the Stripe API.
The limitation with stripe-mock is that it is stateless, so fetching objects you create in a test will not work. Also, the data made available is limited to that which we generate based off resource fixtures from within our API.
We have been experimenting with ways around these limitations, but don't have anything readily available right now.
to everybody still searching for a solution for unit tests without stripe mock
I managed to mock without it in the way I explained here on Stack Overflow
@meggieveggie Thanks for the feedback. We usually recommend using stripe-mock for something like this which is what we use in our test suite. You can read more about this here: https://github.com/stripe/stripe-mock/ Would that work for you?
how it can be use in unit testing?. Can you refer any example