-
Notifications
You must be signed in to change notification settings - Fork 18.9k
client.Client package should provide testable/mockable version for unit (not e2e) testing #30454
Copy link
Copy link
Closed
Labels
area/projectarea/testingkind/enhancementEnhancements are not bugs or new features but can improve usability or performance.Enhancements are not bugs or new features but can improve usability or performance.
Description
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?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/projectarea/testingkind/enhancementEnhancements are not bugs or new features but can improve usability or performance.Enhancements are not bugs or new features but can improve usability or performance.