TestNetworkCreateIPv4 verifies behavior of the "--ipv4" option. This option is an optional bool, and must default to "nil", not "true" or "false".
(t *testing.T)
| 189 | // TestNetworkCreateIPv4 verifies behavior of the "--ipv4" option. This option |
| 190 | // is an optional bool, and must default to "nil", not "true" or "false". |
| 191 | func TestNetworkCreateIPv4(t *testing.T) { |
| 192 | boolPtr := func(val bool) *bool { return &val } |
| 193 | |
| 194 | tests := []struct { |
| 195 | doc, name string |
| 196 | flags []string |
| 197 | expected *bool |
| 198 | }{ |
| 199 | { |
| 200 | doc: "IPv4 default", |
| 201 | name: "ipv4-default", |
| 202 | expected: nil, |
| 203 | }, |
| 204 | { |
| 205 | doc: "IPv4 enabled", |
| 206 | name: "ipv4-enabled", |
| 207 | flags: []string{"--ipv4=true"}, |
| 208 | expected: boolPtr(true), |
| 209 | }, |
| 210 | { |
| 211 | doc: "IPv4 enabled (shorthand)", |
| 212 | name: "ipv4-enabled-shorthand", |
| 213 | flags: []string{"--ipv4"}, |
| 214 | expected: boolPtr(true), |
| 215 | }, |
| 216 | { |
| 217 | doc: "IPv4 disabled", |
| 218 | name: "ipv4-disabled", |
| 219 | flags: []string{"--ipv4=false"}, |
| 220 | expected: boolPtr(false), |
| 221 | }, |
| 222 | } |
| 223 | |
| 224 | for _, tc := range tests { |
| 225 | t.Run(tc.doc, func(t *testing.T) { |
| 226 | cli := test.NewFakeCli(&fakeClient{ |
| 227 | networkCreateFunc: func(ctx context.Context, name string, createBody client.NetworkCreateOptions) (client.NetworkCreateResult, error) { |
| 228 | assert.Check(t, is.DeepEqual(createBody.EnableIPv4, tc.expected)) |
| 229 | return client.NetworkCreateResult{ID: name}, nil |
| 230 | }, |
| 231 | }) |
| 232 | cmd := newCreateCommand(cli) |
| 233 | cmd.SetArgs([]string{tc.name}) |
| 234 | if tc.expected != nil { |
| 235 | assert.Check(t, cmd.ParseFlags(tc.flags)) |
| 236 | } |
| 237 | assert.NilError(t, cmd.Execute()) |
| 238 | assert.Check(t, is.Equal(tc.name, strings.TrimSpace(cli.OutBuffer().String()))) |
| 239 | }) |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | // TestNetworkCreateIPv6 verifies behavior of the "--ipv6" option. This option |
| 244 | // is an optional bool, and must default to "nil", not "true" or "false". |
nothing calls this directly
no test coverage detected
searching dependent graphs…