2017-06-21 05:25:25 -04:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
2018-05-03 21:02:44 -04:00
|
|
|
"context"
|
|
|
|
|
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
|
2024-06-06 20:31:09 -04:00
|
|
|
networkCreateFunc func(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error)
|
2017-07-20 07:59:00 -04:00
|
|
|
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
|
2024-06-05 10:28:24 -04:00
|
|
|
networkListFunc func(ctx context.Context, options network.ListOptions) ([]network.Summary, error)
|
2024-06-06 20:31:09 -04:00
|
|
|
networkPruneFunc func(ctx context.Context, pruneFilters filters.Args) (network.PruneReport, error)
|
2024-06-05 10:28:24 -04:00
|
|
|
networkInspectFunc func(ctx context.Context, networkID string, options network.InspectOptions) (network.Inspect, []byte, error)
|
2017-06-21 05:25:25 -04:00
|
|
|
}
|
|
|
|
|
2024-06-06 20:31:09 -04:00
|
|
|
func (c *fakeClient) NetworkCreate(ctx context.Context, name string, options network.CreateOptions) (network.CreateResponse, error) {
|
2017-06-21 05:25:25 -04:00
|
|
|
if c.networkCreateFunc != nil {
|
|
|
|
return c.networkCreateFunc(ctx, name, options)
|
|
|
|
}
|
2024-05-31 11:28:10 -04:00
|
|
|
return network.CreateResponse{}, nil
|
2017-06-21 05:25:25 -04:00
|
|
|
}
|
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
|
|
|
|
2024-06-05 10:28:24 -04:00
|
|
|
func (c *fakeClient) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) {
|
2017-08-01 05:06:47 -04:00
|
|
|
if c.networkListFunc != nil {
|
|
|
|
return c.networkListFunc(ctx, options)
|
|
|
|
}
|
2024-06-05 10:28:24 -04:00
|
|
|
return []network.Inspect{}, nil
|
2017-08-01 05:06:47 -04:00
|
|
|
}
|
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-06-05 10:28:24 -04:00
|
|
|
func (c *fakeClient) NetworkInspectWithRaw(ctx context.Context, networkID string, opts network.InspectOptions) (network.Inspect, []byte, error) {
|
2024-02-21 10:36:17 -05:00
|
|
|
if c.networkInspectFunc != nil {
|
|
|
|
return c.networkInspectFunc(ctx, networkID, opts)
|
|
|
|
}
|
2024-06-05 10:28:24 -04:00
|
|
|
return network.Inspect{}, nil, nil
|
2022-04-08 22:43:28 -04:00
|
|
|
}
|
2024-02-21 10:36:17 -05:00
|
|
|
|
2024-06-06 20:31:09 -04:00
|
|
|
func (c *fakeClient) NetworksPrune(ctx context.Context, pruneFilter filters.Args) (network.PruneReport, error) {
|
2024-02-21 10:36:17 -05:00
|
|
|
if c.networkPruneFunc != nil {
|
|
|
|
return c.networkPruneFunc(ctx, pruneFilter)
|
|
|
|
}
|
2024-06-06 20:31:09 -04:00
|
|
|
return network.PruneReport{}, nil
|
2024-02-21 10:36:17 -05:00
|
|
|
}
|