Runs a test to create and verify a devfile based on the content of the specified TestContent
(testContent TestContent, t *testing.T)
| 321 | |
| 322 | // Runs a test to create and verify a devfile based on the content of the specified TestContent |
| 323 | func (testDevfile *TestDevfile) RunTest(testContent TestContent, t *testing.T) { |
| 324 | |
| 325 | if len(testContent.CommandTypes) > 0 { |
| 326 | numCommands := GetRandomNumber(1, maxCommands) |
| 327 | for i := 0; i < numCommands; i++ { |
| 328 | commandIndex := GetRandomNumber(1, len(testContent.CommandTypes)) |
| 329 | testDevfile.AddCommand(testContent.CommandTypes[commandIndex-1]) |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | if len(testContent.ComponentTypes) > 0 { |
| 334 | numComponents := GetRandomNumber(1, maxComponents) |
| 335 | for i := 0; i < numComponents; i++ { |
| 336 | componentIndex := GetRandomNumber(1, len(testContent.ComponentTypes)) |
| 337 | testDevfile.AddComponent(testContent.ComponentTypes[componentIndex-1]) |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | if len(testContent.ProjectTypes) > 0 { |
| 342 | numProjects := GetRandomNumber(1, maxProjects) |
| 343 | for i := 0; i < numProjects; i++ { |
| 344 | projectIndex := GetRandomNumber(1, len(testContent.ProjectTypes)) |
| 345 | testDevfile.AddProject(testContent.ProjectTypes[projectIndex-1]) |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | if len(testContent.StarterProjectTypes) > 0 { |
| 350 | numStarterProjects := GetRandomNumber(1, maxStarterProjects) |
| 351 | for i := 0; i < numStarterProjects; i++ { |
| 352 | starterProjectIndex := GetRandomNumber(1, len(testContent.StarterProjectTypes)) |
| 353 | testDevfile.AddStarterProject(testContent.StarterProjectTypes[starterProjectIndex-1]) |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | if testContent.AddParent { |
| 358 | testDevfile.AddParent() |
| 359 | } |
| 360 | |
| 361 | if testContent.AddEvents { |
| 362 | testDevfile.AddEvents() |
| 363 | } |
| 364 | |
| 365 | if testContent.AddMetaData { |
| 366 | testDevfile.AddMetaData() |
| 367 | } |
| 368 | |
| 369 | err := testDevfile.Validator.WriteAndValidate(testDevfile) |
| 370 | if err != nil { |
| 371 | t.Fatalf(LogErrorMessage(fmt.Sprintf("ERROR verifying devfile : %s : %v", testContent.FileName, err))) |
| 372 | } |
| 373 | |
| 374 | } |