(t *testing.T)
| 242 | } |
| 243 | |
| 244 | func TestCompleteNetworkNames(t *testing.T) { |
| 245 | tests := []struct { |
| 246 | doc string |
| 247 | networks []network.Summary |
| 248 | expOut []string |
| 249 | expDirective cobra.ShellCompDirective |
| 250 | }{ |
| 251 | { |
| 252 | doc: "no results", |
| 253 | expDirective: cobra.ShellCompDirectiveNoFileComp, |
| 254 | }, |
| 255 | { |
| 256 | doc: "with results", |
| 257 | networks: []network.Summary{ |
| 258 | { |
| 259 | Network: network.Network{ |
| 260 | ID: "nw-c", |
| 261 | Name: "network-c", |
| 262 | }, |
| 263 | }, |
| 264 | { |
| 265 | Network: network.Network{ |
| 266 | ID: "nw-b", |
| 267 | Name: "network-b", |
| 268 | }, |
| 269 | }, |
| 270 | { |
| 271 | Network: network.Network{ |
| 272 | ID: "nw-a", |
| 273 | Name: "network-a", |
| 274 | }, |
| 275 | }, |
| 276 | }, |
| 277 | expOut: []string{"network-c", "network-b", "network-a"}, |
| 278 | expDirective: cobra.ShellCompDirectiveNoFileComp, |
| 279 | }, |
| 280 | { |
| 281 | doc: "with error", |
| 282 | expDirective: cobra.ShellCompDirectiveError, |
| 283 | }, |
| 284 | } |
| 285 | |
| 286 | for _, tc := range tests { |
| 287 | t.Run(tc.doc, func(t *testing.T) { |
| 288 | comp := NetworkNames(fakeCLI{&fakeClient{ |
| 289 | networkListFunc: func(context.Context, client.NetworkListOptions) (client.NetworkListResult, error) { |
| 290 | if tc.expDirective == cobra.ShellCompDirectiveError { |
| 291 | return client.NetworkListResult{}, errors.New("some error occurred") |
| 292 | } |
| 293 | return client.NetworkListResult{Items: tc.networks}, nil |
| 294 | }, |
| 295 | }}) |
| 296 | |
| 297 | volumes, directives := comp(&cobra.Command{}, nil, "") |
| 298 | assert.Check(t, is.Equal(directives&tc.expDirective, tc.expDirective)) |
| 299 | assert.Check(t, is.DeepEqual(volumes, tc.expOut)) |
| 300 | }) |
| 301 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…