Fix TestNetworkConnectWithFlags

The test didn't do anything useful...
- Despite its name it used newCreateCommand() instead of
  newConnectCommand() with create flags/options instead of connect.
- There was no fake networkCreateFunc(), so the result of the 'connect'
  wasn't checked.
- The fake networkConnectFunc() was never called, so didn't spot the
  problem.

Signed-off-by: Rob Murray <rob.murray@docker.com>
This commit is contained in:
Rob Murray 2024-04-08 09:07:48 +01:00
parent 6c70360c79
commit e8bfedd266
1 changed files with 24 additions and 13 deletions

View File

@ -43,27 +43,38 @@ func TestNetworkConnectErrors(t *testing.T) {
} }
func TestNetworkConnectWithFlags(t *testing.T) { func TestNetworkConnectWithFlags(t *testing.T) {
expectedOpts := []network.IPAMConfig{ expectedConfig := &network.EndpointSettings{
{ IPAMConfig: &network.EndpointIPAMConfig{
Subnet: "192.168.4.0/24", IPv4Address: "192.168.4.1",
IPRange: "192.168.4.0/24", IPv6Address: "fdef:f401:8da0:1234::5678",
Gateway: "192.168.4.1/24", LinkLocalIPs: []string{"169.254.42.42"},
AuxAddress: map[string]string{}, },
Links: []string{"otherctr"},
Aliases: []string{"poor-yorick"},
DriverOpts: map[string]string{
"adriveropt": "anoptval",
}, },
} }
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
networkConnectFunc: func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error { networkConnectFunc: func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error {
assert.Check(t, is.DeepEqual(expectedOpts, config.IPAMConfig), "not expected driver error") assert.Check(t, is.DeepEqual(expectedConfig, config))
return nil return nil
}, },
}) })
args := []string{"banana"} args := []string{"mynet", "myctr"}
cmd := newCreateCommand(cli) cmd := newConnectCommand(cli)
cmd.SetArgs(args) cmd.SetArgs(args)
cmd.Flags().Set("driver", "foo") for _, opt := range []struct{ name, value string }{
cmd.Flags().Set("ip-range", "192.168.4.0/24") {"alias", "poor-yorick"},
cmd.Flags().Set("gateway", "192.168.4.1/24") {"driver-opt", "adriveropt=anoptval"},
cmd.Flags().Set("subnet", "192.168.4.0/24") {"ip", "192.168.4.1"},
{"ip6", "fdef:f401:8da0:1234::5678"},
{"link", "otherctr"},
{"link-local-ip", "169.254.42.42"},
} {
err := cmd.Flags().Set(opt.name, opt.value)
assert.Check(t, err)
}
assert.NilError(t, cmd.Execute()) assert.NilError(t, cmd.Execute())
} }