mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: refactor ListOptions to NetworkListOptions
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
This commit is contained in:
@@ -133,7 +133,7 @@ type NetworkAPIClient interface {
|
||||
NetworkDisconnect(ctx context.Context, network, container string, force bool) error
|
||||
NetworkInspect(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, error)
|
||||
NetworkInspectWithRaw(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, []byte, error)
|
||||
NetworkList(ctx context.Context, options ListOptions) ([]network.Summary, error)
|
||||
NetworkList(ctx context.Context, options NetworkListOptions) ([]network.Summary, error)
|
||||
NetworkRemove(ctx context.Context, network string) error
|
||||
NetworksPrune(ctx context.Context, pruneFilter filters.Args) (network.PruneReport, error)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// NetworkList returns the list of networks configured in the docker host.
|
||||
func (cli *Client) NetworkList(ctx context.Context, options ListOptions) ([]network.Summary, error) {
|
||||
func (cli *Client) NetworkList(ctx context.Context, options NetworkListOptions) ([]network.Summary, error) {
|
||||
query := url.Values{}
|
||||
if options.Filters.Len() > 0 {
|
||||
filterJSON, err := filters.ToJSON(options.Filters)
|
||||
|
||||
@@ -2,7 +2,7 @@ package client
|
||||
|
||||
import "github.com/moby/moby/api/types/filters"
|
||||
|
||||
// ListOptions holds parameters to filter the list of networks with.
|
||||
type ListOptions struct {
|
||||
// NetworkListOptions holds parameters to filter the list of networks with.
|
||||
type NetworkListOptions struct {
|
||||
Filters filters.Args
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestNetworkListError(t *testing.T) {
|
||||
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
|
||||
}
|
||||
|
||||
_, err := client.NetworkList(context.Background(), ListOptions{})
|
||||
_, err := client.NetworkList(context.Background(), NetworkListOptions{})
|
||||
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
|
||||
}
|
||||
|
||||
@@ -30,27 +30,27 @@ func TestNetworkList(t *testing.T) {
|
||||
const expectedURL = "/networks"
|
||||
|
||||
listCases := []struct {
|
||||
options ListOptions
|
||||
options NetworkListOptions
|
||||
expectedFilters string
|
||||
}{
|
||||
{
|
||||
options: ListOptions{},
|
||||
options: NetworkListOptions{},
|
||||
expectedFilters: "",
|
||||
},
|
||||
{
|
||||
options: ListOptions{
|
||||
options: NetworkListOptions{
|
||||
Filters: filters.NewArgs(filters.Arg("dangling", "false")),
|
||||
},
|
||||
expectedFilters: `{"dangling":{"false":true}}`,
|
||||
},
|
||||
{
|
||||
options: ListOptions{
|
||||
options: NetworkListOptions{
|
||||
Filters: filters.NewArgs(filters.Arg("dangling", "true")),
|
||||
},
|
||||
expectedFilters: `{"dangling":{"true":true}}`,
|
||||
},
|
||||
{
|
||||
options: ListOptions{
|
||||
options: NetworkListOptions{
|
||||
Filters: filters.NewArgs(
|
||||
filters.Arg("label", "label1"),
|
||||
filters.Arg("label", "label2"),
|
||||
|
||||
@@ -35,7 +35,7 @@ func OnlyDefaultNetworks(ctx context.Context) bool {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
networks, err := apiClient.NetworkList(ctx, client.ListOptions{})
|
||||
networks, err := apiClient.NetworkList(ctx, client.NetworkListOptions{})
|
||||
if err != nil || len(networks) > 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func createAmbiguousNetworks(ctx context.Context, t *testing.T, apiClient client
|
||||
idPrefixNet := network.CreateNoError(ctx, t, apiClient, testNet[:12])
|
||||
fullIDNet := network.CreateNoError(ctx, t, apiClient, testNet)
|
||||
|
||||
nws, err := apiClient.NetworkList(ctx, client.ListOptions{})
|
||||
nws, err := apiClient.NetworkList(ctx, client.NetworkListOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.Check(t, is.Equal(true, containsNetwork(nws, testNet)), "failed to create network testNet")
|
||||
@@ -79,7 +79,7 @@ func TestDockerNetworkDeletePreferID(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
// networks "testNet" and "idPrefixNet" should be removed, but "fullIDNet" should still exist
|
||||
nws, err := apiClient.NetworkList(ctx, client.ListOptions{})
|
||||
nws, err := apiClient.NetworkList(ctx, client.NetworkListOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(false, containsNetwork(nws, testNet)), "Network testNet not removed")
|
||||
assert.Check(t, is.Equal(false, containsNetwork(nws, idPrefixNet)), "Network idPrefixNet not removed")
|
||||
|
||||
@@ -53,7 +53,7 @@ func LinkDoesntExist(ctx context.Context, t *testing.T, master string) {
|
||||
// IsNetworkAvailable provides a comparison to check if a docker network is available
|
||||
func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name string) is.Comparison {
|
||||
return func() is.Result {
|
||||
networks, err := c.NetworkList(ctx, client.ListOptions{})
|
||||
networks, err := c.NetworkList(ctx, client.NetworkListOptions{})
|
||||
if err != nil {
|
||||
return is.ResultFromError(err)
|
||||
}
|
||||
@@ -69,7 +69,7 @@ func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name str
|
||||
// IsNetworkNotAvailable provides a comparison to check if a docker network is not available
|
||||
func IsNetworkNotAvailable(ctx context.Context, c client.NetworkAPIClient, name string) is.Comparison {
|
||||
return func() is.Result {
|
||||
networks, err := c.NetworkList(ctx, client.ListOptions{})
|
||||
networks, err := c.NetworkList(ctx, client.NetworkListOptions{})
|
||||
if err != nil {
|
||||
return is.ResultFromError(err)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
// IsNetworkAvailable provides a comparison to check if a docker network is available
|
||||
func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name string) cmp.Comparison {
|
||||
return func() cmp.Result {
|
||||
networks, err := c.NetworkList(ctx, client.ListOptions{})
|
||||
networks, err := c.NetworkList(ctx, client.NetworkListOptions{})
|
||||
if err != nil {
|
||||
return cmp.ResultFromError(err)
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func IsNetworkAvailable(ctx context.Context, c client.NetworkAPIClient, name str
|
||||
// IsNetworkNotAvailable provides a comparison to check if a docker network is not available
|
||||
func IsNetworkNotAvailable(ctx context.Context, c client.NetworkAPIClient, name string) cmp.Comparison {
|
||||
return func() cmp.Result {
|
||||
networks, err := c.NetworkList(ctx, client.ListOptions{})
|
||||
networks, err := c.NetworkList(ctx, client.NetworkListOptions{})
|
||||
if err != nil {
|
||||
return cmp.ResultFromError(err)
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func deleteAllVolumes(ctx context.Context, t testing.TB, c client.VolumeAPIClien
|
||||
|
||||
func deleteAllNetworks(ctx context.Context, t testing.TB, c client.NetworkAPIClient, daemonPlatform string, protectedNetworks map[string]struct{}) {
|
||||
t.Helper()
|
||||
networks, err := c.NetworkList(ctx, client.ListOptions{})
|
||||
networks, err := c.NetworkList(ctx, client.NetworkListOptions{})
|
||||
assert.Check(t, err, "failed to list networks")
|
||||
|
||||
for _, n := range networks {
|
||||
|
||||
@@ -168,7 +168,7 @@ func ProtectNetworks(ctx context.Context, t testing.TB, testEnv *Execution) {
|
||||
func getExistingNetworks(ctx context.Context, t testing.TB, testEnv *Execution) []string {
|
||||
t.Helper()
|
||||
apiClient := testEnv.APIClient()
|
||||
networkList, err := apiClient.NetworkList(ctx, client.ListOptions{})
|
||||
networkList, err := apiClient.NetworkList(ctx, client.NetworkListOptions{})
|
||||
assert.NilError(t, err, "failed to list networks")
|
||||
|
||||
var networks []string
|
||||
|
||||
2
vendor/github.com/moby/moby/client/client_interfaces.go
generated
vendored
2
vendor/github.com/moby/moby/client/client_interfaces.go
generated
vendored
@@ -133,7 +133,7 @@ type NetworkAPIClient interface {
|
||||
NetworkDisconnect(ctx context.Context, network, container string, force bool) error
|
||||
NetworkInspect(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, error)
|
||||
NetworkInspectWithRaw(ctx context.Context, network string, options network.InspectOptions) (network.Inspect, []byte, error)
|
||||
NetworkList(ctx context.Context, options ListOptions) ([]network.Summary, error)
|
||||
NetworkList(ctx context.Context, options NetworkListOptions) ([]network.Summary, error)
|
||||
NetworkRemove(ctx context.Context, network string) error
|
||||
NetworksPrune(ctx context.Context, pruneFilter filters.Args) (network.PruneReport, error)
|
||||
}
|
||||
|
||||
2
vendor/github.com/moby/moby/client/network_list.go
generated
vendored
2
vendor/github.com/moby/moby/client/network_list.go
generated
vendored
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
// NetworkList returns the list of networks configured in the docker host.
|
||||
func (cli *Client) NetworkList(ctx context.Context, options ListOptions) ([]network.Summary, error) {
|
||||
func (cli *Client) NetworkList(ctx context.Context, options NetworkListOptions) ([]network.Summary, error) {
|
||||
query := url.Values{}
|
||||
if options.Filters.Len() > 0 {
|
||||
filterJSON, err := filters.ToJSON(options.Filters)
|
||||
|
||||
4
vendor/github.com/moby/moby/client/network_list_opts.go
generated
vendored
4
vendor/github.com/moby/moby/client/network_list_opts.go
generated
vendored
@@ -2,7 +2,7 @@ package client
|
||||
|
||||
import "github.com/moby/moby/api/types/filters"
|
||||
|
||||
// ListOptions holds parameters to filter the list of networks with.
|
||||
type ListOptions struct {
|
||||
// NetworkListOptions holds parameters to filter the list of networks with.
|
||||
type NetworkListOptions struct {
|
||||
Filters filters.Args
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user