MCPcopy Create free account
hub / github.com/docker/cli / TestNetworkCreateWithFlags

Function TestNetworkCreateWithFlags

cli/command/network/create_test.go:158–187  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

156}
157
158func TestNetworkCreateWithFlags(t *testing.T) {
159 expectedDriver := "foo"
160 expectedOpts := []network.IPAMConfig{
161 {
162 Subnet: netip.MustParsePrefix("192.168.4.0/24"),
163 IPRange: netip.MustParsePrefix("192.168.4.0/24"),
164 Gateway: netip.MustParseAddr("192.168.4.1"), // FIXME(thaJeztah): this used to accept a CIDR ("192.168.4.1/24")
165 AuxAddress: map[string]netip.Addr{},
166 },
167 }
168 cli := test.NewFakeCli(&fakeClient{
169 networkCreateFunc: func(ctx context.Context, name string, options client.NetworkCreateOptions) (client.NetworkCreateResult, error) {
170 assert.Check(t, is.Equal(expectedDriver, options.Driver), "not expected driver error")
171 assert.Check(t, is.DeepEqual(expectedOpts, options.IPAM.Config, cmpopts.EquateComparable(netip.Addr{}, netip.Prefix{})), "not expected driver error")
172 return client.NetworkCreateResult{
173 ID: name,
174 }, nil
175 },
176 })
177 args := []string{"banana"}
178 cmd := newCreateCommand(cli)
179
180 cmd.SetArgs(args)
181 assert.Check(t, cmd.Flags().Set("driver", "foo"))
182 assert.Check(t, cmd.Flags().Set("ip-range", "192.168.4.0/24"))
183 assert.Check(t, cmd.Flags().Set("gateway", "192.168.4.1")) // FIXME(thaJeztah): this used to accept a CIDR ("192.168.4.1/24")
184 assert.Check(t, cmd.Flags().Set("subnet", "192.168.4.0/24"))
185 assert.NilError(t, cmd.Execute())
186 assert.Check(t, is.Equal("banana", strings.TrimSpace(cli.OutBuffer().String())))
187}
188
189// TestNetworkCreateIPv4 verifies behavior of the "--ipv4" option. This option
190// is an optional bool, and must default to "nil", not "true" or "false".

Callers

nothing calls this directly

Calls 5

OutBufferMethod · 0.95
SetArgsMethod · 0.80
newCreateCommandFunction · 0.70
StringMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…