Skip to content

Commit f78dac3

Browse files
committed
api/types: migrate NetworkListOptions to api/types/network
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent e622cea commit f78dac3

12 files changed

Lines changed: 34 additions & 26 deletions

File tree

api/types/client.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ type EventsOptions struct {
3535
Filters filters.Args
3636
}
3737

38-
// NetworkListOptions holds parameters to filter the list of networks with.
39-
type NetworkListOptions struct {
40-
Filters filters.Args
41-
}
42-
4338
// NewHijackedResponse intializes a HijackedResponse type
4439
func NewHijackedResponse(conn net.Conn, mediaType string) HijackedResponse {
4540
return HijackedResponse{Conn: conn, Reader: bufio.NewReader(conn), mediaType: mediaType}

api/types/network/network.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ const (
1717
NetworkNat = "nat"
1818
)
1919

20+
// ListOptions holds parameters to filter the list of networks with.
21+
type ListOptions struct {
22+
Filters filters.Args
23+
}
24+
2025
// InspectOptions holds parameters to inspect network.
2126
type InspectOptions struct {
2227
Scope string

api/types/types_deprecated.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ type ImageListOptions = image.ListOptions
3535
// Deprecated: use [image.RemoveOptions].
3636
type ImageRemoveOptions = image.RemoveOptions
3737

38+
// NetworkListOptions holds parameters to filter the list of networks with.
39+
//
40+
// Deprecated: use [network.ListOptions].
41+
type NetworkListOptions = network.ListOptions
42+
3843
// NetworkCreateResponse is the response message sent by the server for network create call.
3944
//
4045
// Deprecated: use [network.CreateResponse].

client/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ type NetworkAPIClient interface {
112112
NetworkDisconnect(ctx context.Context, network, container string, force bool) error
113113
NetworkInspect(ctx context.Context, network string, options network.InspectOptions) (types.NetworkResource, error)
114114
NetworkInspectWithRaw(ctx context.Context, network string, options network.InspectOptions) (types.NetworkResource, []byte, error)
115-
NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error)
115+
NetworkList(ctx context.Context, options network.ListOptions) ([]types.NetworkResource, error)
116116
NetworkRemove(ctx context.Context, network string) error
117117
NetworksPrune(ctx context.Context, pruneFilter filters.Args) (types.NetworksPruneReport, error)
118118
}

client/network_list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77

88
"github.com/docker/docker/api/types"
99
"github.com/docker/docker/api/types/filters"
10+
"github.com/docker/docker/api/types/network"
1011
)
1112

1213
// NetworkList returns the list of networks configured in the docker host.
13-
func (cli *Client) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
14+
func (cli *Client) NetworkList(ctx context.Context, options network.ListOptions) ([]types.NetworkResource, error) {
1415
query := url.Values{}
1516
if options.Filters.Len() > 0 {
1617
//nolint:staticcheck // ignore SA1019 for old code

client/network_list_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/docker/docker/api/types"
1414
"github.com/docker/docker/api/types/filters"
15+
"github.com/docker/docker/api/types/network"
1516
"github.com/docker/docker/errdefs"
1617
"gotest.tools/v3/assert"
1718
is "gotest.tools/v3/assert/cmp"
@@ -22,35 +23,35 @@ func TestNetworkListError(t *testing.T) {
2223
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
2324
}
2425

25-
_, err := client.NetworkList(context.Background(), types.NetworkListOptions{})
26+
_, err := client.NetworkList(context.Background(), network.ListOptions{})
2627
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
2728
}
2829

2930
func TestNetworkList(t *testing.T) {
3031
const expectedURL = "/networks"
3132

3233
listCases := []struct {
33-
options types.NetworkListOptions
34+
options network.ListOptions
3435
expectedFilters string
3536
}{
3637
{
37-
options: types.NetworkListOptions{},
38+
options: network.ListOptions{},
3839
expectedFilters: "",
3940
},
4041
{
41-
options: types.NetworkListOptions{
42+
options: network.ListOptions{
4243
Filters: filters.NewArgs(filters.Arg("dangling", "false")),
4344
},
4445
expectedFilters: `{"dangling":{"false":true}}`,
4546
},
4647
{
47-
options: types.NetworkListOptions{
48+
options: network.ListOptions{
4849
Filters: filters.NewArgs(filters.Arg("dangling", "true")),
4950
},
5051
expectedFilters: `{"dangling":{"true":true}}`,
5152
},
5253
{
53-
options: types.NetworkListOptions{
54+
options: network.ListOptions{
5455
Filters: filters.NewArgs(
5556
filters.Arg("label", "label1"),
5657
filters.Arg("label", "label2"),

integration-cli/requirements_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/containerd/containerd/plugin"
14-
"github.com/docker/docker/api/types"
14+
"github.com/docker/docker/api/types/network"
1515
"github.com/docker/docker/api/types/swarm"
1616
"github.com/docker/docker/client"
1717
"github.com/docker/docker/integration-cli/cli"
@@ -32,7 +32,7 @@ func OnlyDefaultNetworks(ctx context.Context) bool {
3232
if err != nil {
3333
return false
3434
}
35-
networks, err := apiClient.NetworkList(ctx, types.NetworkListOptions{})
35+
networks, err := apiClient.NetworkList(ctx, network.ListOptions{})
3636
if err != nil || len(networks) > 0 {
3737
return false
3838
}

integration/network/delete_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66

77
"github.com/docker/docker/api/types"
8+
networktypes "github.com/docker/docker/api/types/network"
89
dclient "github.com/docker/docker/client"
910
"github.com/docker/docker/integration/internal/network"
1011
"gotest.tools/v3/assert"
@@ -31,7 +32,7 @@ func createAmbiguousNetworks(ctx context.Context, t *testing.T, client dclient.A
3132
idPrefixNet := network.CreateNoError(ctx, t, client, testNet[:12])
3233
fullIDNet := network.CreateNoError(ctx, t, client, testNet)
3334

34-
nws, err := client.NetworkList(ctx, types.NetworkListOptions{})
35+
nws, err := client.NetworkList(ctx, networktypes.ListOptions{})
3536
assert.NilError(t, err)
3637

3738
assert.Check(t, is.Equal(true, containsNetwork(nws, testNet)), "failed to create network testNet")
@@ -79,7 +80,7 @@ func TestDockerNetworkDeletePreferID(t *testing.T) {
7980
assert.NilError(t, err)
8081

8182
// networks "testNet" and "idPrefixNet" should be removed, but "fullIDNet" should still exist
82-
nws, err := client.NetworkList(ctx, types.NetworkListOptions{})
83+
nws, err := client.NetworkList(ctx, networktypes.ListOptions{})
8384
assert.NilError(t, err)
8485
assert.Check(t, is.Equal(false, containsNetwork(nws, testNet)), "Network testNet not removed")
8586
assert.Check(t, is.Equal(false, containsNetwork(nws, idPrefixNet)), "Network idPrefixNet not removed")

integration/network/helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"fmt"
88
"testing"
99

10-
"github.com/docker/docker/api/types"
10+
"github.com/docker/docker/api/types/network"
1111
"github.com/docker/docker/client"
1212
"github.com/docker/docker/testutil"
1313
"gotest.tools/v3/assert/cmp"
@@ -45,7 +45,7 @@ func LinkExists(ctx context.Context, t *testing.T, master string) {
4545
// IsNetworkAvailable provides a comparison to check if a docker network is available
4646
func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name string) cmp.Comparison {
4747
return func() cmp.Result {
48-
networks, err := c.NetworkList(ctx, types.NetworkListOptions{})
48+
networks, err := c.NetworkList(ctx, network.ListOptions{})
4949
if err != nil {
5050
return cmp.ResultFromError(err)
5151
}
@@ -61,7 +61,7 @@ func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name str
6161
// IsNetworkNotAvailable provides a comparison to check if a docker network is not available
6262
func IsNetworkNotAvailable(ctx context.Context, c client.NetworkAPIClient, name string) cmp.Comparison {
6363
return func() cmp.Result {
64-
networks, err := c.NetworkList(ctx, types.NetworkListOptions{})
64+
networks, err := c.NetworkList(ctx, network.ListOptions{})
6565
if err != nil {
6666
return cmp.ResultFromError(err)
6767
}

integration/network/helpers_windows.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import (
44
"context"
55
"fmt"
66

7-
"github.com/docker/docker/api/types"
7+
"github.com/docker/docker/api/types/network"
88
"github.com/docker/docker/client"
99
"gotest.tools/v3/assert/cmp"
1010
)
1111

1212
// IsNetworkAvailable provides a comparison to check if a docker network is available
1313
func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name string) cmp.Comparison {
1414
return func() cmp.Result {
15-
networks, err := c.NetworkList(ctx, types.NetworkListOptions{})
15+
networks, err := c.NetworkList(ctx, network.ListOptions{})
1616
if err != nil {
1717
return cmp.ResultFromError(err)
1818
}
@@ -28,7 +28,7 @@ func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name str
2828
// IsNetworkNotAvailable provides a comparison to check if a docker network is not available
2929
func IsNetworkNotAvailable(ctx context.Context, c client.NetworkAPIClient, name string) cmp.Comparison {
3030
return func() cmp.Result {
31-
networks, err := c.NetworkList(ctx, types.NetworkListOptions{})
31+
networks, err := c.NetworkList(ctx, network.ListOptions{})
3232
if err != nil {
3333
return cmp.ResultFromError(err)
3434
}

0 commit comments

Comments
 (0)