2017-07-19 03:34:03 -04:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
|
|
|
|
2017-07-19 03:34:03 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
|
|
|
"github.com/docker/docker/client"
|
2019-10-27 20:54:22 -04:00
|
|
|
|
2017-07-20 04:32:51 -04:00
|
|
|
// Import builders to get the builder function as package function
|
2017-08-21 16:30:09 -04:00
|
|
|
. "github.com/docker/cli/internal/test/builders"
|
2017-07-19 03:34:03 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type fakeClient struct {
|
|
|
|
client.Client
|
2017-07-20 04:32:51 -04:00
|
|
|
serviceInspectWithRawFunc func(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
|
|
|
|
serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error)
|
|
|
|
serviceListFunc func(context.Context, types.ServiceListOptions) ([]swarm.Service, error)
|
2017-09-30 16:19:34 -04:00
|
|
|
taskListFunc func(context.Context, types.TaskListOptions) ([]swarm.Task, error)
|
2017-05-09 18:35:25 -04:00
|
|
|
infoFunc func(ctx context.Context) (types.Info, error)
|
2018-01-03 09:40:55 -05:00
|
|
|
networkInspectFunc func(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, error)
|
2019-10-27 20:54:22 -04:00
|
|
|
nodeListFunc func(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)
|
2017-07-19 03:34:03 -04:00
|
|
|
}
|
|
|
|
|
2017-07-20 04:32:51 -04:00
|
|
|
func (f *fakeClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
|
2019-10-27 20:54:22 -04:00
|
|
|
if f.nodeListFunc != nil {
|
|
|
|
return f.nodeListFunc(ctx, options)
|
|
|
|
}
|
2017-07-19 03:34:03 -04:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakeClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
|
2017-09-30 16:19:34 -04:00
|
|
|
if f.taskListFunc != nil {
|
|
|
|
return f.taskListFunc(ctx, options)
|
|
|
|
}
|
2017-07-19 03:34:03 -04:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2017-07-20 04:32:51 -04:00
|
|
|
func (f *fakeClient) ServiceInspectWithRaw(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) {
|
|
|
|
if f.serviceInspectWithRawFunc != nil {
|
|
|
|
return f.serviceInspectWithRawFunc(ctx, serviceID, options)
|
|
|
|
}
|
|
|
|
|
|
|
|
return *Service(ServiceID(serviceID)), []byte{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakeClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) {
|
|
|
|
if f.serviceListFunc != nil {
|
|
|
|
return f.serviceListFunc(ctx, options)
|
|
|
|
}
|
|
|
|
|
2017-07-19 03:34:03 -04:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2017-07-20 04:32:51 -04:00
|
|
|
func (f *fakeClient) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error) {
|
|
|
|
if f.serviceUpdateFunc != nil {
|
|
|
|
return f.serviceUpdateFunc(ctx, serviceID, version, service, options)
|
|
|
|
}
|
|
|
|
|
|
|
|
return types.ServiceUpdateResponse{}, nil
|
|
|
|
}
|
|
|
|
|
2017-05-09 18:35:25 -04:00
|
|
|
func (f *fakeClient) Info(ctx context.Context) (types.Info, error) {
|
|
|
|
if f.infoFunc == nil {
|
|
|
|
return types.Info{}, nil
|
|
|
|
}
|
|
|
|
return f.infoFunc(ctx)
|
|
|
|
}
|
|
|
|
|
2018-01-03 09:40:55 -05:00
|
|
|
func (f *fakeClient) NetworkInspect(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, error) {
|
|
|
|
if f.networkInspectFunc != nil {
|
|
|
|
return f.networkInspectFunc(ctx, networkID, options)
|
|
|
|
}
|
|
|
|
return types.NetworkResource{}, nil
|
|
|
|
}
|
|
|
|
|
2019-10-27 20:54:22 -04:00
|
|
|
func newService(id string, name string, opts ...func(*swarm.Service)) swarm.Service {
|
|
|
|
return *Service(append(opts, ServiceID(id), ServiceName(name))...)
|
2017-07-19 03:34:03 -04:00
|
|
|
}
|