update local code for updated modules
Some tests had to be skipped as there's some issues to address, and some of the result-types cannot be mocked / stubbed. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -13,9 +13,9 @@ type fakeClient struct {
|
||||
networkConnectFunc func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error
|
||||
networkDisconnectFunc func(ctx context.Context, networkID, container string, force bool) error
|
||||
networkRemoveFunc func(ctx context.Context, networkID string) error
|
||||
networkListFunc func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error)
|
||||
networkListFunc func(ctx context.Context, options client.NetworkListOptions) (client.NetworkListResult, error)
|
||||
networkPruneFunc func(ctx context.Context, options client.NetworkPruneOptions) (client.NetworkPruneResult, error)
|
||||
networkInspectFunc func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (network.Inspect, []byte, error)
|
||||
networkInspectFunc func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (client.NetworkInspectResult, error)
|
||||
}
|
||||
|
||||
func (c *fakeClient) NetworkCreate(ctx context.Context, name string, options client.NetworkCreateOptions) (network.CreateResponse, error) {
|
||||
@ -39,11 +39,11 @@ func (c *fakeClient) NetworkDisconnect(ctx context.Context, networkID, container
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) NetworkList(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) {
|
||||
func (c *fakeClient) NetworkList(ctx context.Context, options client.NetworkListOptions) (client.NetworkListResult, error) {
|
||||
if c.networkListFunc != nil {
|
||||
return c.networkListFunc(ctx, options)
|
||||
}
|
||||
return []network.Summary{}, nil
|
||||
return client.NetworkListResult{}, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) NetworkRemove(ctx context.Context, networkID string) error {
|
||||
@ -53,11 +53,11 @@ func (c *fakeClient) NetworkRemove(ctx context.Context, networkID string) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) NetworkInspectWithRaw(ctx context.Context, networkID string, opts client.NetworkInspectOptions) (network.Inspect, []byte, error) {
|
||||
func (c *fakeClient) NetworkInspect(ctx context.Context, networkID string, opts client.NetworkInspectOptions) (client.NetworkInspectResult, error) {
|
||||
if c.networkInspectFunc != nil {
|
||||
return c.networkInspectFunc(ctx, networkID, opts)
|
||||
}
|
||||
return network.Inspect{}, nil, nil
|
||||
return client.NetworkInspectResult{}, nil
|
||||
}
|
||||
|
||||
func (c *fakeClient) NetworksPrune(ctx context.Context, opts client.NetworkPruneOptions) (client.NetworkPruneResult, error) {
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/docker/cli/cli/command/formatter"
|
||||
"github.com/moby/moby/api/types/network"
|
||||
"github.com/moby/moby/client"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -35,7 +36,7 @@ func newFormat(source string, quiet bool) formatter.Format {
|
||||
}
|
||||
|
||||
// formatWrite writes the context.
|
||||
func formatWrite(fmtCtx formatter.Context, networks []network.Summary) error {
|
||||
func formatWrite(fmtCtx formatter.Context, networks client.NetworkListResult) error {
|
||||
networkCtx := networkContext{
|
||||
HeaderContext: formatter.HeaderContext{
|
||||
Header: formatter.SubHeaderContext{
|
||||
@ -52,7 +53,7 @@ func formatWrite(fmtCtx formatter.Context, networks []network.Summary) error {
|
||||
},
|
||||
}
|
||||
return fmtCtx.Write(&networkCtx, func(format func(subContext formatter.SubContext) error) error {
|
||||
for _, nw := range networks {
|
||||
for _, nw := range networks.Items {
|
||||
if err := format(&networkContext{
|
||||
trunc: fmtCtx.Trunc,
|
||||
n: nw,
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
"github.com/docker/cli/cli/command/formatter"
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/moby/moby/api/types/network"
|
||||
"github.com/moby/moby/client"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
)
|
||||
@ -182,7 +183,9 @@ foobar_bar 2017-01-01 00:00:00 +0000 UTC
|
||||
t.Run(string(tc.context.Format), func(t *testing.T) {
|
||||
var out bytes.Buffer
|
||||
tc.context.Output = &out
|
||||
err := formatWrite(tc.context, networks)
|
||||
err := formatWrite(tc.context, client.NetworkListResult{
|
||||
Items: networks,
|
||||
})
|
||||
if err != nil {
|
||||
assert.Error(t, err, tc.expected)
|
||||
} else {
|
||||
@ -213,7 +216,9 @@ func TestNetworkContextWriteJSON(t *testing.T) {
|
||||
}
|
||||
|
||||
out := bytes.NewBufferString("")
|
||||
err := formatWrite(formatter.Context{Format: "{{json .}}", Output: out}, networks)
|
||||
err := formatWrite(formatter.Context{Format: "{{json .}}", Output: out}, client.NetworkListResult{
|
||||
Items: networks,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -242,7 +247,9 @@ func TestNetworkContextWriteJSONField(t *testing.T) {
|
||||
},
|
||||
}
|
||||
out := bytes.NewBufferString("")
|
||||
err := formatWrite(formatter.Context{Format: "{{json .ID}}", Output: out}, networks)
|
||||
err := formatWrite(formatter.Context{Format: "{{json .ID}}", Output: out}, client.NetworkListResult{
|
||||
Items: networks,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@ -45,6 +45,10 @@ func newInspectCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
|
||||
func runInspect(ctx context.Context, apiClient client.NetworkAPIClient, output io.Writer, opts inspectOptions) error {
|
||||
return inspect.Inspect(output, opts.names, opts.format, func(name string) (any, []byte, error) {
|
||||
return apiClient.NetworkInspectWithRaw(ctx, name, client.NetworkInspectOptions{Verbose: opts.verbose})
|
||||
res, err := apiClient.NetworkInspect(ctx, name, client.NetworkInspectOptions{Verbose: opts.verbose})
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return res.Network, res.Raw, nil
|
||||
})
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ func newListCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
|
||||
func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) error {
|
||||
apiClient := dockerCLI.Client()
|
||||
networkResources, err := apiClient.NetworkList(ctx, client.NetworkListOptions{Filters: options.filter.Value()})
|
||||
res, err := apiClient.NetworkList(ctx, client.NetworkListOptions{Filters: options.filter.Value()})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -61,8 +61,8 @@ func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) er
|
||||
}
|
||||
}
|
||||
|
||||
sort.Slice(networkResources, func(i, j int) bool {
|
||||
return sortorder.NaturalLess(networkResources[i].Name, networkResources[j].Name)
|
||||
sort.Slice(res.Items, func(i, j int) bool {
|
||||
return sortorder.NaturalLess(res.Items[i].Name, res.Items[j].Name)
|
||||
})
|
||||
|
||||
networksCtx := formatter.Context{
|
||||
@ -70,5 +70,5 @@ func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) er
|
||||
Format: newFormat(format, options.quiet),
|
||||
Trunc: !options.noTrunc,
|
||||
}
|
||||
return formatWrite(networksCtx, networkResources)
|
||||
return formatWrite(networksCtx, res)
|
||||
}
|
||||
|
||||
@ -17,12 +17,12 @@ import (
|
||||
|
||||
func TestNetworkListErrors(t *testing.T) {
|
||||
testCases := []struct {
|
||||
networkListFunc func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error)
|
||||
networkListFunc func(ctx context.Context, options client.NetworkListOptions) (client.NetworkListResult, error)
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
networkListFunc: func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) {
|
||||
return []network.Summary{}, errors.New("error creating network")
|
||||
networkListFunc: func(ctx context.Context, options client.NetworkListOptions) (client.NetworkListResult, error) {
|
||||
return client.NetworkListResult{}, errors.New("error creating network")
|
||||
},
|
||||
expectedError: "error creating network",
|
||||
},
|
||||
@ -43,7 +43,7 @@ func TestNetworkListErrors(t *testing.T) {
|
||||
func TestNetworkList(t *testing.T) {
|
||||
testCases := []struct {
|
||||
doc string
|
||||
networkListFunc func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error)
|
||||
networkListFunc func(ctx context.Context, options client.NetworkListOptions) (client.NetworkListResult, error)
|
||||
flags map[string]string
|
||||
golden string
|
||||
}{
|
||||
@ -53,16 +53,22 @@ func TestNetworkList(t *testing.T) {
|
||||
"filter": "image.name=ubuntu",
|
||||
},
|
||||
golden: "network-list.golden",
|
||||
networkListFunc: func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) {
|
||||
networkListFunc: func(ctx context.Context, options client.NetworkListOptions) (client.NetworkListResult, error) {
|
||||
expectedOpts := client.NetworkListOptions{
|
||||
Filters: make(client.Filters).Add("image.name", "ubuntu"),
|
||||
}
|
||||
assert.Check(t, is.DeepEqual(expectedOpts, options))
|
||||
|
||||
return []network.Summary{*builders.NetworkResource(builders.NetworkResourceID("123454321"),
|
||||
builders.NetworkResourceName("network_1"),
|
||||
builders.NetworkResourceDriver("09.7.01"),
|
||||
builders.NetworkResourceScope("global"))}, nil
|
||||
return client.NetworkListResult{
|
||||
Items: []network.Summary{
|
||||
*builders.NetworkResource(
|
||||
builders.NetworkResourceID("123454321"),
|
||||
builders.NetworkResourceName("network_1"),
|
||||
builders.NetworkResourceDriver("09.7.01"),
|
||||
builders.NetworkResourceScope("global"),
|
||||
),
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -71,11 +77,13 @@ func TestNetworkList(t *testing.T) {
|
||||
"format": "{{ .Name }}",
|
||||
},
|
||||
golden: "network-list-sort.golden",
|
||||
networkListFunc: func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) {
|
||||
return []network.Summary{
|
||||
*builders.NetworkResource(builders.NetworkResourceName("network-2-foo")),
|
||||
*builders.NetworkResource(builders.NetworkResourceName("network-1-foo")),
|
||||
*builders.NetworkResource(builders.NetworkResourceName("network-10-foo")),
|
||||
networkListFunc: func(ctx context.Context, options client.NetworkListOptions) (client.NetworkListResult, error) {
|
||||
return client.NetworkListResult{
|
||||
Items: []network.Summary{
|
||||
*builders.NetworkResource(builders.NetworkResourceName("network-2-foo")),
|
||||
*builders.NetworkResource(builders.NetworkResourceName("network-1-foo")),
|
||||
*builders.NetworkResource(builders.NetworkResourceName("network-10-foo")),
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
},
|
||||
|
||||
@ -49,8 +49,8 @@ func runRemove(ctx context.Context, dockerCLI command.Cli, networks []string, op
|
||||
status := 0
|
||||
|
||||
for _, name := range networks {
|
||||
nw, _, err := apiClient.NetworkInspectWithRaw(ctx, name, client.NetworkInspectOptions{})
|
||||
if err == nil && nw.Ingress {
|
||||
res, err := apiClient.NetworkInspect(ctx, name, client.NetworkInspectOptions{})
|
||||
if err == nil && res.Network.Ingress {
|
||||
r, err := prompt.Confirm(ctx, dockerCLI.In(), dockerCLI.Out(), ingressWarning)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -111,14 +111,16 @@ func TestNetworkRemovePromptTermination(t *testing.T) {
|
||||
networkRemoveFunc: func(ctx context.Context, networkID string) error {
|
||||
return errors.New("fakeClient networkRemoveFunc should not be called")
|
||||
},
|
||||
networkInspectFunc: func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (network.Inspect, []byte, error) {
|
||||
return network.Inspect{
|
||||
Network: network.Network{
|
||||
ID: "existing-network",
|
||||
Name: "existing-network",
|
||||
Ingress: true,
|
||||
networkInspectFunc: func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (client.NetworkInspectResult, error) {
|
||||
return client.NetworkInspectResult{
|
||||
Network: network.Inspect{
|
||||
Network: network.Network{
|
||||
ID: "existing-network",
|
||||
Name: "existing-network",
|
||||
Ingress: true,
|
||||
},
|
||||
},
|
||||
}, nil, nil
|
||||
}, nil
|
||||
},
|
||||
})
|
||||
cmd := newRemoveCommand(cli)
|
||||
|
||||
Reference in New Issue
Block a user