Browse code

api/types/network: move `ListOptions` to client

Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>

Austin Vazquez authored on 2025/08/22 10:29:38
Showing 15 changed files
... ...
@@ -45,11 +45,6 @@ type CreateOptions struct {
45 45
 	Labels     map[string]string // Labels holds metadata specific to the network being created.
46 46
 }
47 47
 
48
-// ListOptions holds parameters to filter the list of networks with.
49
-type ListOptions struct {
50
-	Filters filters.Args
51
-}
52
-
53 48
 // InspectOptions holds parameters to inspect network.
54 49
 type InspectOptions struct {
55 50
 	Scope   string
... ...
@@ -133,7 +133,7 @@ type NetworkAPIClient interface {
133 133
 	NetworkDisconnect(ctx context.Context, network, container string, force bool) error
134 134
 	NetworkInspect(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, error)
135 135
 	NetworkInspectWithRaw(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, []byte, error)
136
-	NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error)
136
+	NetworkList(ctx context.Context, options ListOptions) ([]network.Summary, error)
137 137
 	NetworkRemove(ctx context.Context, network string) error
138 138
 	NetworksPrune(ctx context.Context, pruneFilter filters.Args) (network.PruneReport, error)
139 139
 }
... ...
@@ -11,7 +11,7 @@ import (
11 11
 )
12 12
 
13 13
 // NetworkList returns the list of networks configured in the docker host.
14
-func (cli *Client) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) {
14
+func (cli *Client) NetworkList(ctx context.Context, options ListOptions) ([]network.Summary, error) {
15 15
 	query := url.Values{}
16 16
 	if options.Filters.Len() > 0 {
17 17
 		filterJSON, err := filters.ToJSON(options.Filters)
18 18
new file mode 100644
... ...
@@ -0,0 +1,8 @@
0
+package client
1
+
2
+import "github.com/moby/moby/api/types/filters"
3
+
4
+// ListOptions holds parameters to filter the list of networks with.
5
+type ListOptions struct {
6
+	Filters filters.Args
7
+}
... ...
@@ -22,7 +22,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(), network.ListOptions{})
25
+	_, err := client.NetworkList(context.Background(), ListOptions{})
26 26
 	assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
27 27
 }
28 28
 
... ...
@@ -30,27 +30,27 @@ func TestNetworkList(t *testing.T) {
30 30
 	const expectedURL = "/networks"
31 31
 
32 32
 	listCases := []struct {
33
-		options         network.ListOptions
33
+		options         ListOptions
34 34
 		expectedFilters string
35 35
 	}{
36 36
 		{
37
-			options:         network.ListOptions{},
37
+			options:         ListOptions{},
38 38
 			expectedFilters: "",
39 39
 		},
40 40
 		{
41
-			options: network.ListOptions{
41
+			options: ListOptions{
42 42
 				Filters: filters.NewArgs(filters.Arg("dangling", "false")),
43 43
 			},
44 44
 			expectedFilters: `{"dangling":{"false":true}}`,
45 45
 		},
46 46
 		{
47
-			options: network.ListOptions{
47
+			options: ListOptions{
48 48
 				Filters: filters.NewArgs(filters.Arg("dangling", "true")),
49 49
 			},
50 50
 			expectedFilters: `{"dangling":{"true":true}}`,
51 51
 		},
52 52
 		{
53
-			options: network.ListOptions{
53
+			options: ListOptions{
54 54
 				Filters: filters.NewArgs(
55 55
 					filters.Arg("label", "label1"),
56 56
 					filters.Arg("label", "label2"),
... ...
@@ -16,7 +16,6 @@ import (
16 16
 	"time"
17 17
 
18 18
 	"github.com/containerd/containerd/v2/plugins"
19
-	"github.com/moby/moby/api/types/network"
20 19
 	"github.com/moby/moby/api/types/swarm"
21 20
 	"github.com/moby/moby/client"
22 21
 	"github.com/moby/moby/v2/integration-cli/cli"
... ...
@@ -36,7 +35,7 @@ func OnlyDefaultNetworks(ctx context.Context) bool {
36 36
 	if err != nil {
37 37
 		return false
38 38
 	}
39
-	networks, err := apiClient.NetworkList(ctx, network.ListOptions{})
39
+	networks, err := apiClient.NetworkList(ctx, client.ListOptions{})
40 40
 	if err != nil || len(networks) > 0 {
41 41
 		return false
42 42
 	}
... ...
@@ -31,7 +31,7 @@ func createAmbiguousNetworks(ctx context.Context, t *testing.T, apiClient client
31 31
 	idPrefixNet := network.CreateNoError(ctx, t, apiClient, testNet[:12])
32 32
 	fullIDNet := network.CreateNoError(ctx, t, apiClient, testNet)
33 33
 
34
-	nws, err := apiClient.NetworkList(ctx, networktypes.ListOptions{})
34
+	nws, err := apiClient.NetworkList(ctx, client.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 +79,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 := apiClient.NetworkList(ctx, networktypes.ListOptions{})
82
+	nws, err := apiClient.NetworkList(ctx, client.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,6 @@ import (
7 7
 	"fmt"
8 8
 	"testing"
9 9
 
10
-	"github.com/moby/moby/api/types/network"
11 10
 	"github.com/moby/moby/client"
12 11
 	"github.com/moby/moby/v2/testutil"
13 12
 	is "gotest.tools/v3/assert/cmp"
... ...
@@ -54,7 +53,7 @@ func LinkDoesntExist(ctx context.Context, t *testing.T, master string) {
54 54
 // IsNetworkAvailable provides a comparison to check if a docker network is available
55 55
 func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name string) is.Comparison {
56 56
 	return func() is.Result {
57
-		networks, err := c.NetworkList(ctx, network.ListOptions{})
57
+		networks, err := c.NetworkList(ctx, client.ListOptions{})
58 58
 		if err != nil {
59 59
 			return is.ResultFromError(err)
60 60
 		}
... ...
@@ -70,7 +69,7 @@ func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name str
70 70
 // IsNetworkNotAvailable provides a comparison to check if a docker network is not available
71 71
 func IsNetworkNotAvailable(ctx context.Context, c client.NetworkAPIClient, name string) is.Comparison {
72 72
 	return func() is.Result {
73
-		networks, err := c.NetworkList(ctx, network.ListOptions{})
73
+		networks, err := c.NetworkList(ctx, client.ListOptions{})
74 74
 		if err != nil {
75 75
 			return is.ResultFromError(err)
76 76
 		}
... ...
@@ -4,7 +4,6 @@ import (
4 4
 	"context"
5 5
 	"fmt"
6 6
 
7
-	"github.com/moby/moby/api/types/network"
8 7
 	"github.com/moby/moby/client"
9 8
 	"gotest.tools/v3/assert/cmp"
10 9
 )
... ...
@@ -12,7 +11,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, network.ListOptions{})
15
+		networks, err := c.NetworkList(ctx, client.ListOptions{})
16 16
 		if err != nil {
17 17
 			return cmp.ResultFromError(err)
18 18
 		}
... ...
@@ -28,7 +27,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, network.ListOptions{})
31
+		networks, err := c.NetworkList(ctx, client.ListOptions{})
32 32
 		if err != nil {
33 33
 			return cmp.ResultFromError(err)
34 34
 		}
... ...
@@ -143,7 +143,7 @@ func deleteAllVolumes(ctx context.Context, t testing.TB, c client.VolumeAPIClien
143 143
 
144 144
 func deleteAllNetworks(ctx context.Context, t testing.TB, c client.NetworkAPIClient, daemonPlatform string, protectedNetworks map[string]struct{}) {
145 145
 	t.Helper()
146
-	networks, err := c.NetworkList(ctx, network.ListOptions{})
146
+	networks, err := c.NetworkList(ctx, client.ListOptions{})
147 147
 	assert.Check(t, err, "failed to list networks")
148 148
 
149 149
 	for _, n := range networks {
... ...
@@ -8,7 +8,6 @@ import (
8 8
 	"github.com/moby/moby/api/types/container"
9 9
 	"github.com/moby/moby/api/types/filters"
10 10
 	"github.com/moby/moby/api/types/image"
11
-	"github.com/moby/moby/api/types/network"
12 11
 	"github.com/moby/moby/client"
13 12
 	"github.com/moby/moby/v2/testutil"
14 13
 	"go.opentelemetry.io/otel"
... ...
@@ -168,8 +167,8 @@ func ProtectNetworks(ctx context.Context, t testing.TB, testEnv *Execution) {
168 168
 
169 169
 func getExistingNetworks(ctx context.Context, t testing.TB, testEnv *Execution) []string {
170 170
 	t.Helper()
171
-	client := testEnv.APIClient()
172
-	networkList, err := client.NetworkList(ctx, network.ListOptions{})
171
+	apiClient := testEnv.APIClient()
172
+	networkList, err := apiClient.NetworkList(ctx, client.ListOptions{})
173 173
 	assert.NilError(t, err, "failed to list networks")
174 174
 
175 175
 	var networks []string
... ...
@@ -45,11 +45,6 @@ type CreateOptions struct {
45 45
 	Labels     map[string]string // Labels holds metadata specific to the network being created.
46 46
 }
47 47
 
48
-// ListOptions holds parameters to filter the list of networks with.
49
-type ListOptions struct {
50
-	Filters filters.Args
51
-}
52
-
53 48
 // InspectOptions holds parameters to inspect network.
54 49
 type InspectOptions struct {
55 50
 	Scope   string
... ...
@@ -133,7 +133,7 @@ type NetworkAPIClient interface {
133 133
 	NetworkDisconnect(ctx context.Context, network, container string, force bool) error
134 134
 	NetworkInspect(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, error)
135 135
 	NetworkInspectWithRaw(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, []byte, error)
136
-	NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error)
136
+	NetworkList(ctx context.Context, options ListOptions) ([]network.Summary, error)
137 137
 	NetworkRemove(ctx context.Context, network string) error
138 138
 	NetworksPrune(ctx context.Context, pruneFilter filters.Args) (network.PruneReport, error)
139 139
 }
... ...
@@ -11,7 +11,7 @@ import (
11 11
 )
12 12
 
13 13
 // NetworkList returns the list of networks configured in the docker host.
14
-func (cli *Client) NetworkList(ctx context.Context, options network.ListOptions) ([]network.Summary, error) {
14
+func (cli *Client) NetworkList(ctx context.Context, options ListOptions) ([]network.Summary, error) {
15 15
 	query := url.Values{}
16 16
 	if options.Filters.Len() > 0 {
17 17
 		filterJSON, err := filters.ToJSON(options.Filters)
18 18
new file mode 100644
... ...
@@ -0,0 +1,8 @@
0
+package client
1
+
2
+import "github.com/moby/moby/api/types/filters"
3
+
4
+// ListOptions holds parameters to filter the list of networks with.
5
+type ListOptions struct {
6
+	Filters filters.Args
7
+}