Description
I'm trying to write tests against code consuming client.Client, I can see a number of ways of abstracting this but they all feel obtuse and repetitive.
Are there efforts to create a testable / mockable version of the client.Client code in the docker/docker repository?
Go includes modules to allow testing of http servers - so it seems like it could be an idiomatic pattern to provide a docker/docker client.Client version which can also provide a testable interface.
I may be missing something here, but have had a chat with Justin and browsed the source, I didn't seem to find something like a way to create a client for unit testing.
Ideally I could do something like this:
testClient := client.NewTestClient{}
error := scaleService(alert, &testClient)
....
func scaleService(req requests.PrometheusAlert, c *client.Client) error {
var err error
serviceName := req.Alerts[0].Labels.FunctionName
service, _, inspectErr := c.ServiceInspectWithRaw(context.Background(), serviceName)
if inspectErr == nil {
var replicas uint64
if req.Status == "firing" {
if *service.Spec.Mode.Replicated.Replicas < 20 {
replicas = *service.Spec.Mode.Replicated.Replicas + uint64(5)
} else {
return err
}
// c.ServiceUpdate(......
}
I wondered if @dnephin might have some ideas?
Description
I'm trying to write tests against code consuming client.Client, I can see a number of ways of abstracting this but they all feel obtuse and repetitive.
Are there efforts to create a testable / mockable version of the client.Client code in the
docker/dockerrepository?Go includes modules to allow testing of http servers - so it seems like it could be an idiomatic pattern to provide a docker/docker client.Client version which can also provide a testable interface.
I may be missing something here, but have had a chat with Justin and browsed the source, I didn't seem to find something like a way to create a client for unit testing.
Ideally I could do something like this:
I wondered if @dnephin might have some ideas?