ImportQaTestCases imports csv file to the table `qa_test_cases`
(qaProjectId, qaProjectName string, file io.ReadCloser, incremental bool)
| 471 | |
| 472 | // ImportQaTestCases imports csv file to the table `qa_test_cases` |
| 473 | func (s *Service) ImportQaTestCases(qaProjectId, qaProjectName string, file io.ReadCloser, incremental bool) errors.Error { |
| 474 | if !incremental { |
| 475 | // delete old data associated with this qaProjectId |
| 476 | // delete qa_test_cases |
| 477 | err := s.dal.Delete(&qa.QaTestCase{}, dal.Where("qa_project_id = ?", qaProjectId)) |
| 478 | if err != nil { |
| 479 | return errors.Default.Wrap(err, fmt.Sprintf("failed to delete old qa_test_cases for qaProjectId %s", qaProjectId)) |
| 480 | } |
| 481 | // delete qa_apis |
| 482 | err = s.dal.Delete(&qa.QaApi{}, dal.Where("qa_project_id = ?", qaProjectId)) |
| 483 | if err != nil { |
| 484 | return errors.Default.Wrap(err, fmt.Sprintf("failed to delete old qa_apis for qaProjectId %s", qaProjectId)) |
| 485 | } |
| 486 | // delete qa_test_case_executions |
| 487 | err = s.dal.Delete(&qa.QaTestCaseExecution{}, dal.Where("qa_project_id = ?", qaProjectId)) |
| 488 | if err != nil { |
| 489 | return errors.Default.Wrap(err, fmt.Sprintf("failed to delete old qa_test_case_executions for qaProjectId %s", qaProjectId)) |
| 490 | } |
| 491 | // never delete data in qa_projects |
| 492 | } |
| 493 | // create or update qa_projects |
| 494 | err := s.dal.CreateOrUpdate(&qa.QaProject{ |
| 495 | DomainEntityExtended: domainlayer.DomainEntityExtended{ |
| 496 | Id: qaProjectId, |
| 497 | }, |
| 498 | Name: qaProjectName, |
| 499 | }) |
| 500 | if err != nil { |
| 501 | return err |
| 502 | } |
| 503 | return s.importCSV(file, qaProjectId, s.qaTestCaseHandler(qaProjectId)) |
| 504 | } |
| 505 | |
| 506 | // qaTestCaseHandler saves a record into the `qa_test_cases` table |
| 507 | func (s *Service) qaTestCaseHandler(qaProjectId string) func(record map[string]interface{}) errors.Error { |