(t *testing.T)
| 197 | } |
| 198 | |
| 199 | func TestCompleteImageNames(t *testing.T) { |
| 200 | tests := []struct { |
| 201 | doc string |
| 202 | images []image.Summary |
| 203 | expOut []string |
| 204 | expDirective cobra.ShellCompDirective |
| 205 | }{ |
| 206 | { |
| 207 | doc: "no results", |
| 208 | expDirective: cobra.ShellCompDirectiveNoFileComp, |
| 209 | }, |
| 210 | { |
| 211 | doc: "with results", |
| 212 | images: []image.Summary{ |
| 213 | {RepoTags: []string{"image-c:latest", "image-c:other"}}, |
| 214 | {RepoTags: []string{"image-b:latest", "image-b:other"}}, |
| 215 | {RepoTags: []string{"image-a:latest", "image-a:other"}}, |
| 216 | }, |
| 217 | expOut: []string{"image-c:latest", "image-c:other", "image-b:latest", "image-b:other", "image-a:latest", "image-a:other"}, |
| 218 | expDirective: cobra.ShellCompDirectiveNoFileComp, |
| 219 | }, |
| 220 | { |
| 221 | doc: "with error", |
| 222 | expDirective: cobra.ShellCompDirectiveError, |
| 223 | }, |
| 224 | } |
| 225 | |
| 226 | for _, tc := range tests { |
| 227 | t.Run(tc.doc, func(t *testing.T) { |
| 228 | comp := ImageNames(fakeCLI{&fakeClient{ |
| 229 | imageListFunc: func(context.Context, client.ImageListOptions) (client.ImageListResult, error) { |
| 230 | if tc.expDirective == cobra.ShellCompDirectiveError { |
| 231 | return client.ImageListResult{}, errors.New("some error occurred") |
| 232 | } |
| 233 | return client.ImageListResult{Items: tc.images}, nil |
| 234 | }, |
| 235 | }}, -1) |
| 236 | |
| 237 | volumes, directives := comp(&cobra.Command{}, nil, "") |
| 238 | assert.Check(t, is.Equal(directives&tc.expDirective, tc.expDirective)) |
| 239 | assert.Check(t, is.DeepEqual(volumes, tc.expOut)) |
| 240 | }) |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | func TestCompleteNetworkNames(t *testing.T) { |
| 245 | tests := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…