(t *testing.T)
| 308 | } |
| 309 | |
| 310 | func TestCompleteVolumeNames(t *testing.T) { |
| 311 | tests := []struct { |
| 312 | doc string |
| 313 | volumes []volume.Volume |
| 314 | expOut []string |
| 315 | expDirective cobra.ShellCompDirective |
| 316 | }{ |
| 317 | { |
| 318 | doc: "no results", |
| 319 | expDirective: cobra.ShellCompDirectiveNoFileComp, |
| 320 | }, |
| 321 | { |
| 322 | doc: "with results", |
| 323 | volumes: []volume.Volume{ |
| 324 | {Name: "volume-c"}, |
| 325 | {Name: "volume-b"}, |
| 326 | {Name: "volume-a"}, |
| 327 | }, |
| 328 | expOut: []string{"volume-c", "volume-b", "volume-a"}, |
| 329 | expDirective: cobra.ShellCompDirectiveNoFileComp, |
| 330 | }, |
| 331 | { |
| 332 | doc: "with error", |
| 333 | expDirective: cobra.ShellCompDirectiveError, |
| 334 | }, |
| 335 | } |
| 336 | |
| 337 | for _, tc := range tests { |
| 338 | t.Run(tc.doc, func(t *testing.T) { |
| 339 | comp := VolumeNames(fakeCLI{&fakeClient{ |
| 340 | volumeListFunc: func(context.Context, client.VolumeListOptions) (client.VolumeListResult, error) { |
| 341 | if tc.expDirective == cobra.ShellCompDirectiveError { |
| 342 | return client.VolumeListResult{}, errors.New("some error occurred") |
| 343 | } |
| 344 | return client.VolumeListResult{Items: tc.volumes}, nil |
| 345 | }, |
| 346 | }}) |
| 347 | |
| 348 | volumes, directives := comp(&cobra.Command{}, nil, "") |
| 349 | assert.Check(t, is.Equal(directives&tc.expDirective, tc.expDirective)) |
| 350 | assert.Check(t, is.DeepEqual(volumes, tc.expOut)) |
| 351 | }) |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | func TestUnique(t *testing.T) { |
| 356 | base := []string{"alpha", "beta", "gamma"} |
nothing calls this directly
no test coverage detected
searching dependent graphs…