(t *testing.T)
| 295 | } |
| 296 | |
| 297 | func TestValidateCompositeCommand(t *testing.T) { |
| 298 | |
| 299 | component := "alias1" |
| 300 | validExecCommands := []v1alpha2.Command{ |
| 301 | generateDummyExecCommand("command1", component, &v1alpha2.CommandGroup{Kind: runGroup}), |
| 302 | generateDummyExecCommand("command2", component, &v1alpha2.CommandGroup{Kind: buildGroup}), |
| 303 | generateDummyExecCommand("command3", component, &v1alpha2.CommandGroup{Kind: runGroup}), |
| 304 | } |
| 305 | components := []v1alpha2.Component{ |
| 306 | generateDummyContainerComponent(component, nil, nil, nil, v1alpha2.Annotation{}, false), |
| 307 | } |
| 308 | |
| 309 | invalidCmdErr := ".*command does not map to a valid component" |
| 310 | missingCmdErr := ".*the command .* mentioned in the composite command does not exist in the devfile" |
| 311 | selfRefCmdErr := ".*composite command cannot reference itself" |
| 312 | indirectRefCmdErr := "composite command cannot indirectly reference itself" |
| 313 | |
| 314 | tests := []struct { |
| 315 | name string |
| 316 | commands []v1alpha2.Command |
| 317 | testCompositeCommand string |
| 318 | wantErr *string |
| 319 | }{ |
| 320 | { |
| 321 | name: "Valid Composite Command", |
| 322 | commands: append(validExecCommands, |
| 323 | generateDummyCompositeCommand("command4", []string{"command1", "command2", "command3"}, &v1alpha2.CommandGroup{Kind: buildGroup})), |
| 324 | testCompositeCommand: "command4", |
| 325 | }, |
| 326 | { |
| 327 | name: "Invalid composite command, references non-existent command", |
| 328 | commands: append(validExecCommands, |
| 329 | generateDummyCompositeCommand("command4", []string{"command1", "fakecommand", "command3"}, &v1alpha2.CommandGroup{Kind: buildGroup})), |
| 330 | testCompositeCommand: "command4", |
| 331 | wantErr: &missingCmdErr, |
| 332 | }, |
| 333 | { |
| 334 | name: "Invalid composite command, references itself", |
| 335 | commands: append(validExecCommands, |
| 336 | generateDummyCompositeCommand("command4", []string{"command1", "command4", "command3"}, &v1alpha2.CommandGroup{Kind: buildGroup})), |
| 337 | testCompositeCommand: "command4", |
| 338 | wantErr: &selfRefCmdErr, |
| 339 | }, |
| 340 | { |
| 341 | name: "Invalid composite command, indirectly references itself", |
| 342 | commands: append(validExecCommands, |
| 343 | generateDummyCompositeCommand("command4", []string{"command5", "command3"}, &v1alpha2.CommandGroup{Kind: buildGroup}), |
| 344 | generateDummyCompositeCommand("command5", []string{"command1", "command4", "command3"}, &v1alpha2.CommandGroup{Kind: buildGroup})), |
| 345 | testCompositeCommand: "command4", |
| 346 | wantErr: &indirectRefCmdErr, |
| 347 | }, |
| 348 | { |
| 349 | name: "Invalid composite command, points to invalid exec command", |
| 350 | commands: []v1alpha2.Command{ |
| 351 | generateDummyCompositeCommand("command4", []string{"command1", "command2"}, &v1alpha2.CommandGroup{Kind: buildGroup}), |
| 352 | generateDummyExecCommand("command1", component, &v1alpha2.CommandGroup{Kind: runGroup}), |
| 353 | generateDummyExecCommand("command2", "some-fake-component", &v1alpha2.CommandGroup{Kind: buildGroup}), |
| 354 | }, |
nothing calls this directly
no test coverage detected