-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
## Changes It is currently challenging to mock APIs that return iterator structs like `*listing.PaginatedIterator` or `*listing.DedupedIterator`. To simplify mocking of iterator responses, we can change the return type for these methods to return the `listing.Iterator` interface. Then, users who need to write tests can use `listing.SliceIterator` to mock the response, for example: ```go w.GetMockWarehousesAPI().EXPECT().List(mock.Anything, mock.Anything).Return(&listing.SliceIterator[sql.EndpointInfo]{ { Id: "1", Name: "foo", }, { Id: "2", Name: "bar", }, }) ``` Similarly, methods returning `Wait*` objects are difficult to mock. The `Get()` method calls the internal `poll` field, but that cannot be set by users who want to mock the response. Exposing this method allows users to define mock responses, for example: ```go w.GetMockWarehousesAPI().EXPECT().Create(mock.Anything, createRequest).Return(&sql.WaitGetWarehouseRunning[sql.CreateWarehouseResponse]{ Poll: poll.Simple(getResponse), }, nil) ``` Callers can then call `w.Warehouses.Create(...).Get()`. Lastly, waiters for which the initial method doesn't have a response have a type parameter of `any` which cannot be mocked easily. Instead, I changed this to `struct{}` to indicate that the response is empty. ## Tests - [x] Unit tests for new helper functionality.
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.