2017-07-19 03:34:03 -04:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
|
|
|
"github.com/docker/docker/client"
|
|
|
|
"golang.org/x/net/context"
|
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)
|
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) {
|
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)
|
|
|
|
}
|
|
|
|
|
2017-07-19 03:34:03 -04:00
|
|
|
func newService(id string, name string) swarm.Service {
|
|
|
|
return swarm.Service{
|
|
|
|
ID: id,
|
|
|
|
Spec: swarm.ServiceSpec{Annotations: swarm.Annotations{Name: name}},
|
|
|
|
}
|
|
|
|
}
|