(t *testing.T)
| 232 | } |
| 233 | |
| 234 | func TestContainerListFormatSizeSetsOption(t *testing.T) { |
| 235 | tests := []struct { |
| 236 | doc, format, sizeFlag string |
| 237 | sizeExpected bool |
| 238 | }{ |
| 239 | { |
| 240 | doc: "detect with all fields", |
| 241 | format: `{{json .}}`, |
| 242 | sizeExpected: true, |
| 243 | }, |
| 244 | { |
| 245 | doc: "detect with explicit field", |
| 246 | format: `{{.Size}}`, |
| 247 | sizeExpected: true, |
| 248 | }, |
| 249 | { |
| 250 | doc: "detect no size", |
| 251 | format: `{{.Names}}`, |
| 252 | sizeExpected: false, |
| 253 | }, |
| 254 | { |
| 255 | doc: "override enable", |
| 256 | format: `{{.Names}}`, |
| 257 | sizeFlag: "true", |
| 258 | sizeExpected: true, |
| 259 | }, |
| 260 | { |
| 261 | doc: "override disable", |
| 262 | format: `{{.Size}}`, |
| 263 | sizeFlag: "false", |
| 264 | sizeExpected: false, |
| 265 | }, |
| 266 | } |
| 267 | |
| 268 | for _, tc := range tests { |
| 269 | t.Run(tc.doc, func(t *testing.T) { |
| 270 | cli := test.NewFakeCli(&fakeClient{ |
| 271 | containerListFunc: func(options client.ContainerListOptions) (client.ContainerListResult, error) { |
| 272 | assert.Check(t, is.Equal(options.Size, tc.sizeExpected)) |
| 273 | return client.ContainerListResult{}, nil |
| 274 | }, |
| 275 | }) |
| 276 | cmd := newListCommand(cli) |
| 277 | cmd.SetArgs([]string{}) |
| 278 | cmd.SetOut(io.Discard) |
| 279 | cmd.SetErr(io.Discard) |
| 280 | assert.Check(t, cmd.Flags().Set("format", tc.format)) |
| 281 | if tc.sizeFlag != "" { |
| 282 | assert.Check(t, cmd.Flags().Set("size", tc.sizeFlag)) |
| 283 | } |
| 284 | assert.NilError(t, cmd.Execute()) |
| 285 | }) |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | func TestContainerListWithConfigFormat(t *testing.T) { |
| 290 | cli := test.NewFakeCli(&fakeClient{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…