Closed IAmJSD closed 3 years ago
It might make more sense here to create interfaces that match what the commands need e.g
type loadBalancerController interface {
List(ctx context.Context, org core.OrganizationRef, opts *core.ListOptions) ([]*core.LoadBalancer, *katapult.Response, error)
Delete(ctx context.Context, lb core.LoadBalancerRef) (*core.LoadBalancer, *katapult.Response, error)
Update(ctx context.Context, lb core.LoadBalancerRef, args *core.LoadBalancerUpdateArguments) (*core.LoadBalancer, *katapult.Response, error)
Create(ctx context.Context, org core.OrganizationRef, args *core.LoadBalancerCreateArguments) (*core.LoadBalancer, *katapult.Response, error)
}
and mock those calls out using go-mock. That way we avoid relying on any details of the client library implementation. Thoughts @jimeh ?
@strideynet I agree about having custom interfaces for the specific resource clients from go-katapult that we use, and mock those.
Mocking the core.RequestMaker
interface from go-katapult is fine, but it does couple of our tests pretty tightly to the katapult/core
package, as changes to the internals of how requests are made in go-katapult that do no affect the external API of the package, would still break our tests in the CLI tool.
It does mean we probably need to do a bit more general setup for the commands in general, so we have a common place where the core.DataCentersClient
object is defined and re-used from all data center related commands, so tests can simply replace it with a interface mock.
And related to that, I think it would be nice if we could run tests against a root command, so for example to get a DC, the args list passed in would be []string{"dc", "get", "uk-lon-01"}
or something to that effect. Basically so we're testing that not only does the command work in isolation, but also that it is accessible via the correct series of commands and sub-commands. It would require a pretty open structure though so the resource clients could still be easily replaced with mocks within tests.
Code Climate has analyzed commit 1c5e0c3d and detected 0 issues on this pull request.
The test coverage on the diff in this pull request is 95.4% (50% is the threshold).
This pull request will bring the total coverage in the repository to 55.5% (-2.1% change).
View more on Code Climate.
Unit tests all commands in the application which rely on a response and user input
Fixes #6