TestNetworkCreateIPv6 verifies behavior of the "--ipv6" option. This option is an optional bool, and must default to "nil", not "true" or "false".
(t *testing.T)
| 243 | // TestNetworkCreateIPv6 verifies behavior of the "--ipv6" option. This option |
| 244 | // is an optional bool, and must default to "nil", not "true" or "false". |
| 245 | func TestNetworkCreateIPv6(t *testing.T) { |
| 246 | strPtr := func(val bool) *bool { return &val } |
| 247 | |
| 248 | tests := []struct { |
| 249 | doc, name string |
| 250 | flags []string |
| 251 | expected *bool |
| 252 | }{ |
| 253 | { |
| 254 | doc: "IPV6 default", |
| 255 | name: "ipv6-default", |
| 256 | expected: nil, |
| 257 | }, |
| 258 | { |
| 259 | doc: "IPV6 enabled", |
| 260 | name: "ipv6-enabled", |
| 261 | flags: []string{"--ipv6=true"}, |
| 262 | expected: strPtr(true), |
| 263 | }, |
| 264 | { |
| 265 | doc: "IPV6 enabled (shorthand)", |
| 266 | name: "ipv6-enabled-shorthand", |
| 267 | flags: []string{"--ipv6"}, |
| 268 | expected: strPtr(true), |
| 269 | }, |
| 270 | { |
| 271 | doc: "IPV6 disabled", |
| 272 | name: "ipv6-disabled", |
| 273 | flags: []string{"--ipv6=false"}, |
| 274 | expected: strPtr(false), |
| 275 | }, |
| 276 | } |
| 277 | |
| 278 | for _, tc := range tests { |
| 279 | t.Run(tc.doc, func(t *testing.T) { |
| 280 | cli := test.NewFakeCli(&fakeClient{ |
| 281 | networkCreateFunc: func(ctx context.Context, name string, createBody client.NetworkCreateOptions) (client.NetworkCreateResult, error) { |
| 282 | assert.Check(t, is.DeepEqual(tc.expected, createBody.EnableIPv6)) |
| 283 | return client.NetworkCreateResult{ID: name}, nil |
| 284 | }, |
| 285 | }) |
| 286 | cmd := newCreateCommand(cli) |
| 287 | cmd.SetArgs([]string{tc.name}) |
| 288 | if tc.expected != nil { |
| 289 | assert.Check(t, cmd.ParseFlags(tc.flags)) |
| 290 | } |
| 291 | assert.NilError(t, cmd.Execute()) |
| 292 | assert.Check(t, is.Equal(tc.name, strings.TrimSpace(cli.OutBuffer().String()))) |
| 293 | }) |
| 294 | } |
| 295 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…