2017-07-19 03:34:03 -04:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
|
|
|
|
2023-10-23 08:51:01 -04:00
|
|
|
"github.com/docker/cli/internal/test/builders"
|
2017-07-19 03:34:03 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2024-05-31 11:28:10 -04:00
|
|
|
"github.com/docker/docker/api/types/network"
|
2017-07-19 03:34:03 -04:00
|
|
|
"github.com/docker/docker/api/types/swarm"
|
2023-07-14 17:42:40 -04:00
|
|
|
"github.com/docker/docker/api/types/system"
|
2017-07-19 03:34:03 -04:00
|
|
|
"github.com/docker/docker/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
2023-10-13 14:34:32 -04:00
|
|
|
serviceUpdateFunc func(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error)
|
2017-07-20 04:32:51 -04:00
|
|
|
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)
|
2023-07-14 17:42:40 -04:00
|
|
|
infoFunc func(ctx context.Context) (system.Info, error)
|
2024-06-05 10:28:24 -04:00
|
|
|
networkInspectFunc func(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, 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)
|
|
|
|
}
|
|
|
|
|
2023-10-23 08:51:01 -04:00
|
|
|
return *builders.Service(builders.ServiceID(serviceID)), []byte{}, nil
|
2017-07-20 04:32:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-10-13 14:34:32 -04:00
|
|
|
func (f *fakeClient) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) {
|
2017-07-20 04:32:51 -04:00
|
|
|
if f.serviceUpdateFunc != nil {
|
|
|
|
return f.serviceUpdateFunc(ctx, serviceID, version, service, options)
|
|
|
|
}
|
|
|
|
|
2023-10-13 14:34:32 -04:00
|
|
|
return swarm.ServiceUpdateResponse{}, nil
|
2017-07-20 04:32:51 -04:00
|
|
|
}
|
|
|
|
|
2023-07-14 17:42:40 -04:00
|
|
|
func (f *fakeClient) Info(ctx context.Context) (system.Info, error) {
|
2017-05-09 18:35:25 -04:00
|
|
|
if f.infoFunc == nil {
|
2023-07-14 17:42:40 -04:00
|
|
|
return system.Info{}, nil
|
2017-05-09 18:35:25 -04:00
|
|
|
}
|
|
|
|
return f.infoFunc(ctx)
|
|
|
|
}
|
|
|
|
|
2024-06-05 10:28:24 -04:00
|
|
|
func (f *fakeClient) NetworkInspect(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, error) {
|
2018-01-03 09:40:55 -05:00
|
|
|
if f.networkInspectFunc != nil {
|
|
|
|
return f.networkInspectFunc(ctx, networkID, options)
|
|
|
|
}
|
2024-06-05 10:28:24 -04:00
|
|
|
return network.Inspect{}, nil
|
2018-01-03 09:40:55 -05:00
|
|
|
}
|
|
|
|
|
2019-10-30 05:58:16 -04:00
|
|
|
func newService(id string, name string) swarm.Service {
|
2023-10-23 08:51:01 -04:00
|
|
|
return *builders.Service(builders.ServiceID(id), builders.ServiceName(name))
|
2017-07-19 03:34:03 -04:00
|
|
|
}
|