2017-06-21 05:25:25 -04:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
|
|
|
|
2017-06-21 05:25:25 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2024-02-21 10:36:17 -05:00
|
|
|
"github.com/docker/docker/api/types/filters"
|
2017-07-20 07:59:00 -04:00
|
|
|
"github.com/docker/docker/api/types/network"
|
2017-06-21 05:25:25 -04:00
|
|
|
"github.com/docker/docker/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
type fakeClient struct {
|
|
|
|
client.Client
|
2017-07-20 07:59:00 -04:00
|
|
|
networkCreateFunc func(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error)
|
|
|
|
networkConnectFunc func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error
|
|
|
|
networkDisconnectFunc func(ctx context.Context, networkID, container string, force bool) error
|
2022-04-08 22:43:28 -04:00
|
|
|
networkRemoveFunc func(ctx context.Context, networkID string) error
|
2017-08-01 05:06:47 -04:00
|
|
|
networkListFunc func(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error)
|
2024-02-21 10:36:17 -05:00
|
|
|
networkPruneFunc func(ctx context.Context, pruneFilters filters.Args) (types.NetworksPruneReport, error)
|
|
|
|
networkInspectFunc func(ctx context.Context, networkID string, options types.NetworkInspectOptions) (types.NetworkResource, []byte, error)
|
2017-06-21 05:25:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *fakeClient) NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error) {
|
|
|
|
if c.networkCreateFunc != nil {
|
|
|
|
return c.networkCreateFunc(ctx, name, options)
|
|
|
|
}
|
|
|
|
return types.NetworkCreateResponse{}, nil
|
|
|
|
}
|
2017-07-20 07:59:00 -04:00
|
|
|
|
|
|
|
func (c *fakeClient) NetworkConnect(ctx context.Context, networkID, container string, config *network.EndpointSettings) error {
|
|
|
|
if c.networkConnectFunc != nil {
|
|
|
|
return c.networkConnectFunc(ctx, networkID, container, config)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *fakeClient) NetworkDisconnect(ctx context.Context, networkID, container string, force bool) error {
|
|
|
|
if c.networkDisconnectFunc != nil {
|
|
|
|
return c.networkDisconnectFunc(ctx, networkID, container, force)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2017-08-01 05:06:47 -04:00
|
|
|
|
|
|
|
func (c *fakeClient) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
|
|
|
|
if c.networkListFunc != nil {
|
|
|
|
return c.networkListFunc(ctx, options)
|
|
|
|
}
|
|
|
|
return []types.NetworkResource{}, nil
|
|
|
|
}
|
2022-04-08 22:43:28 -04:00
|
|
|
|
|
|
|
func (c *fakeClient) NetworkRemove(ctx context.Context, networkID string) error {
|
|
|
|
if c.networkRemoveFunc != nil {
|
|
|
|
return c.networkRemoveFunc(ctx, networkID)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-02-21 10:36:17 -05:00
|
|
|
func (c *fakeClient) NetworkInspectWithRaw(ctx context.Context, networkID string, opts types.NetworkInspectOptions) (types.NetworkResource, []byte, error) {
|
|
|
|
if c.networkInspectFunc != nil {
|
|
|
|
return c.networkInspectFunc(ctx, networkID, opts)
|
|
|
|
}
|
2022-04-08 22:43:28 -04:00
|
|
|
return types.NetworkResource{}, nil, nil
|
|
|
|
}
|
2024-02-21 10:36:17 -05:00
|
|
|
|
|
|
|
func (c *fakeClient) NetworksPrune(ctx context.Context, pruneFilter filters.Args) (types.NetworksPruneReport, error) {
|
|
|
|
if c.networkPruneFunc != nil {
|
|
|
|
return c.networkPruneFunc(ctx, pruneFilter)
|
|
|
|
}
|
|
|
|
return types.NetworksPruneReport{}, nil
|
|
|
|
}
|