Browse code

api/types: migrate NetworkListOptions to api/types/network

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2024/06/01 00:41:31
Showing 12 changed files
... ...
@@ -35,11 +35,6 @@ type EventsOptions struct {
35 35
 	Filters filters.Args
36 36
 }
37 37
 
38
-// NetworkListOptions holds parameters to filter the list of networks with.
39
-type NetworkListOptions struct {
40
-	Filters filters.Args
41
-}
42
-
43 38
 // NewHijackedResponse intializes a HijackedResponse type
44 39
 func NewHijackedResponse(conn net.Conn, mediaType string) HijackedResponse {
45 40
 	return HijackedResponse{Conn: conn, Reader: bufio.NewReader(conn), mediaType: mediaType}
... ...
@@ -17,6 +17,11 @@ const (
17 17
 	NetworkNat = "nat"
18 18
 )
19 19
 
20
+// ListOptions holds parameters to filter the list of networks with.
21
+type ListOptions struct {
22
+	Filters filters.Args
23
+}
24
+
20 25
 // InspectOptions holds parameters to inspect network.
21 26
 type InspectOptions struct {
22 27
 	Scope   string
... ...
@@ -35,6 +35,11 @@ type ImageListOptions = image.ListOptions
35 35
 // Deprecated: use [image.RemoveOptions].
36 36
 type ImageRemoveOptions = image.RemoveOptions
37 37
 
38
+// NetworkListOptions holds parameters to filter the list of networks with.
39
+//
40
+// Deprecated: use [network.ListOptions].
41
+type NetworkListOptions = network.ListOptions
42
+
38 43
 // NetworkCreateResponse is the response message sent by the server for network create call.
39 44
 //
40 45
 // Deprecated: use [network.CreateResponse].
... ...
@@ -112,7 +112,7 @@ type NetworkAPIClient interface {
112 112
 	NetworkDisconnect(ctx context.Context, network, container string, force bool) error
113 113
 	NetworkInspect(ctx context.Context, network string, options network.InspectOptions) (types.NetworkResource, error)
114 114
 	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)
116 116
 	NetworkRemove(ctx context.Context, network string) error
117 117
 	NetworksPrune(ctx context.Context, pruneFilter filters.Args) (types.NetworksPruneReport, error)
118 118
 }
... ...
@@ -7,10 +7,11 @@ import (
7 7
 
8 8
 	"github.com/docker/docker/api/types"
9 9
 	"github.com/docker/docker/api/types/filters"
10
+	"github.com/docker/docker/api/types/network"
10 11
 )
11 12
 
12 13
 // 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) {
14 15
 	query := url.Values{}
15 16
 	if options.Filters.Len() > 0 {
16 17
 		//nolint:staticcheck // ignore SA1019 for old code
... ...
@@ -12,6 +12,7 @@ import (
12 12
 
13 13
 	"github.com/docker/docker/api/types"
14 14
 	"github.com/docker/docker/api/types/filters"
15
+	"github.com/docker/docker/api/types/network"
15 16
 	"github.com/docker/docker/errdefs"
16 17
 	"gotest.tools/v3/assert"
17 18
 	is "gotest.tools/v3/assert/cmp"
... ...
@@ -22,7 +23,7 @@ func TestNetworkListError(t *testing.T) {
22 22
 		client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
23 23
 	}
24 24
 
25
-	_, err := client.NetworkList(context.Background(), types.NetworkListOptions{})
25
+	_, err := client.NetworkList(context.Background(), network.ListOptions{})
26 26
 	assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
27 27
 }
28 28
 
... ...
@@ -30,27 +31,27 @@ func TestNetworkList(t *testing.T) {
30 30
 	const expectedURL = "/networks"
31 31
 
32 32
 	listCases := []struct {
33
-		options         types.NetworkListOptions
33
+		options         network.ListOptions
34 34
 		expectedFilters string
35 35
 	}{
36 36
 		{
37
-			options:         types.NetworkListOptions{},
37
+			options:         network.ListOptions{},
38 38
 			expectedFilters: "",
39 39
 		},
40 40
 		{
41
-			options: types.NetworkListOptions{
41
+			options: network.ListOptions{
42 42
 				Filters: filters.NewArgs(filters.Arg("dangling", "false")),
43 43
 			},
44 44
 			expectedFilters: `{"dangling":{"false":true}}`,
45 45
 		},
46 46
 		{
47
-			options: types.NetworkListOptions{
47
+			options: network.ListOptions{
48 48
 				Filters: filters.NewArgs(filters.Arg("dangling", "true")),
49 49
 			},
50 50
 			expectedFilters: `{"dangling":{"true":true}}`,
51 51
 		},
52 52
 		{
53
-			options: types.NetworkListOptions{
53
+			options: network.ListOptions{
54 54
 				Filters: filters.NewArgs(
55 55
 					filters.Arg("label", "label1"),
56 56
 					filters.Arg("label", "label2"),
... ...
@@ -11,7 +11,7 @@ import (
11 11
 	"time"
12 12
 
13 13
 	"github.com/containerd/containerd/plugin"
14
-	"github.com/docker/docker/api/types"
14
+	"github.com/docker/docker/api/types/network"
15 15
 	"github.com/docker/docker/api/types/swarm"
16 16
 	"github.com/docker/docker/client"
17 17
 	"github.com/docker/docker/integration-cli/cli"
... ...
@@ -32,7 +32,7 @@ func OnlyDefaultNetworks(ctx context.Context) bool {
32 32
 	if err != nil {
33 33
 		return false
34 34
 	}
35
-	networks, err := apiClient.NetworkList(ctx, types.NetworkListOptions{})
35
+	networks, err := apiClient.NetworkList(ctx, network.ListOptions{})
36 36
 	if err != nil || len(networks) > 0 {
37 37
 		return false
38 38
 	}
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"testing"
6 6
 
7 7
 	"github.com/docker/docker/api/types"
8
+	networktypes "github.com/docker/docker/api/types/network"
8 9
 	dclient "github.com/docker/docker/client"
9 10
 	"github.com/docker/docker/integration/internal/network"
10 11
 	"gotest.tools/v3/assert"
... ...
@@ -31,7 +32,7 @@ func createAmbiguousNetworks(ctx context.Context, t *testing.T, client dclient.A
31 31
 	idPrefixNet := network.CreateNoError(ctx, t, client, testNet[:12])
32 32
 	fullIDNet := network.CreateNoError(ctx, t, client, testNet)
33 33
 
34
-	nws, err := client.NetworkList(ctx, types.NetworkListOptions{})
34
+	nws, err := client.NetworkList(ctx, networktypes.ListOptions{})
35 35
 	assert.NilError(t, err)
36 36
 
37 37
 	assert.Check(t, is.Equal(true, containsNetwork(nws, testNet)), "failed to create network testNet")
... ...
@@ -79,7 +80,7 @@ func TestDockerNetworkDeletePreferID(t *testing.T) {
79 79
 	assert.NilError(t, err)
80 80
 
81 81
 	// networks "testNet" and "idPrefixNet" should be removed, but "fullIDNet" should still exist
82
-	nws, err := client.NetworkList(ctx, types.NetworkListOptions{})
82
+	nws, err := client.NetworkList(ctx, networktypes.ListOptions{})
83 83
 	assert.NilError(t, err)
84 84
 	assert.Check(t, is.Equal(false, containsNetwork(nws, testNet)), "Network testNet not removed")
85 85
 	assert.Check(t, is.Equal(false, containsNetwork(nws, idPrefixNet)), "Network idPrefixNet not removed")
... ...
@@ -7,7 +7,7 @@ import (
7 7
 	"fmt"
8 8
 	"testing"
9 9
 
10
-	"github.com/docker/docker/api/types"
10
+	"github.com/docker/docker/api/types/network"
11 11
 	"github.com/docker/docker/client"
12 12
 	"github.com/docker/docker/testutil"
13 13
 	"gotest.tools/v3/assert/cmp"
... ...
@@ -45,7 +45,7 @@ func LinkExists(ctx context.Context, t *testing.T, master string) {
45 45
 // IsNetworkAvailable provides a comparison to check if a docker network is available
46 46
 func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name string) cmp.Comparison {
47 47
 	return func() cmp.Result {
48
-		networks, err := c.NetworkList(ctx, types.NetworkListOptions{})
48
+		networks, err := c.NetworkList(ctx, network.ListOptions{})
49 49
 		if err != nil {
50 50
 			return cmp.ResultFromError(err)
51 51
 		}
... ...
@@ -61,7 +61,7 @@ func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name str
61 61
 // IsNetworkNotAvailable provides a comparison to check if a docker network is not available
62 62
 func IsNetworkNotAvailable(ctx context.Context, c client.NetworkAPIClient, name string) cmp.Comparison {
63 63
 	return func() cmp.Result {
64
-		networks, err := c.NetworkList(ctx, types.NetworkListOptions{})
64
+		networks, err := c.NetworkList(ctx, network.ListOptions{})
65 65
 		if err != nil {
66 66
 			return cmp.ResultFromError(err)
67 67
 		}
... ...
@@ -4,7 +4,7 @@ import (
4 4
 	"context"
5 5
 	"fmt"
6 6
 
7
-	"github.com/docker/docker/api/types"
7
+	"github.com/docker/docker/api/types/network"
8 8
 	"github.com/docker/docker/client"
9 9
 	"gotest.tools/v3/assert/cmp"
10 10
 )
... ...
@@ -12,7 +12,7 @@ import (
12 12
 // IsNetworkAvailable provides a comparison to check if a docker network is available
13 13
 func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name string) cmp.Comparison {
14 14
 	return func() cmp.Result {
15
-		networks, err := c.NetworkList(ctx, types.NetworkListOptions{})
15
+		networks, err := c.NetworkList(ctx, network.ListOptions{})
16 16
 		if err != nil {
17 17
 			return cmp.ResultFromError(err)
18 18
 		}
... ...
@@ -28,7 +28,7 @@ func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name str
28 28
 // IsNetworkNotAvailable provides a comparison to check if a docker network is not available
29 29
 func IsNetworkNotAvailable(ctx context.Context, c client.NetworkAPIClient, name string) cmp.Comparison {
30 30
 	return func() cmp.Result {
31
-		networks, err := c.NetworkList(ctx, types.NetworkListOptions{})
31
+		networks, err := c.NetworkList(ctx, network.ListOptions{})
32 32
 		if err != nil {
33 33
 			return cmp.ResultFromError(err)
34 34
 		}
... ...
@@ -149,7 +149,7 @@ func deleteAllVolumes(ctx context.Context, t testing.TB, c client.VolumeAPIClien
149 149
 
150 150
 func deleteAllNetworks(ctx context.Context, t testing.TB, c client.NetworkAPIClient, daemonPlatform string, protectedNetworks map[string]struct{}) {
151 151
 	t.Helper()
152
-	networks, err := c.NetworkList(ctx, types.NetworkListOptions{})
152
+	networks, err := c.NetworkList(ctx, network.ListOptions{})
153 153
 	assert.Check(t, err, "failed to list networks")
154 154
 
155 155
 	for _, n := range networks {
... ...
@@ -4,10 +4,10 @@ import (
4 4
 	"context"
5 5
 	"testing"
6 6
 
7
-	"github.com/docker/docker/api/types"
8 7
 	"github.com/docker/docker/api/types/container"
9 8
 	"github.com/docker/docker/api/types/filters"
10 9
 	"github.com/docker/docker/api/types/image"
10
+	"github.com/docker/docker/api/types/network"
11 11
 	"github.com/docker/docker/api/types/volume"
12 12
 	"github.com/docker/docker/errdefs"
13 13
 	"github.com/docker/docker/testutil"
... ...
@@ -160,7 +160,7 @@ func ProtectNetworks(ctx context.Context, t testing.TB, testEnv *Execution) {
160 160
 func getExistingNetworks(ctx context.Context, t testing.TB, testEnv *Execution) []string {
161 161
 	t.Helper()
162 162
 	client := testEnv.APIClient()
163
-	networkList, err := client.NetworkList(ctx, types.NetworkListOptions{})
163
+	networkList, err := client.NetworkList(ctx, network.ListOptions{})
164 164
 	assert.NilError(t, err, "failed to list networks")
165 165
 
166 166
 	var networks []string