(ctx context.Context, a *require.Assertions, ctl *controller, project *v1pb.Project, database *v1pb.Database, statement string, wait bool)
| 466 | } |
| 467 | |
| 468 | func createIssueAndReturnSQLReviewResult(ctx context.Context, a *require.Assertions, ctl *controller, project *v1pb.Project, database *v1pb.Database, statement string, wait bool) []*v1pb.PlanCheckRun_Result { |
| 469 | sheet, err := ctl.sheetServiceClient.CreateSheet(ctx, connect.NewRequest(&v1pb.CreateSheetRequest{ |
| 470 | Parent: project.Name, |
| 471 | Sheet: &v1pb.Sheet{ |
| 472 | Content: []byte(statement), |
| 473 | }, |
| 474 | })) |
| 475 | a.NoError(err) |
| 476 | |
| 477 | plan, err := ctl.planServiceClient.CreatePlan(ctx, connect.NewRequest(&v1pb.CreatePlanRequest{ |
| 478 | Parent: project.Name, |
| 479 | Plan: &v1pb.Plan{ |
| 480 | Specs: []*v1pb.Plan_Spec{ |
| 481 | { |
| 482 | Id: uuid.NewString(), |
| 483 | Config: &v1pb.Plan_Spec_ChangeDatabaseConfig{ |
| 484 | ChangeDatabaseConfig: &v1pb.Plan_ChangeDatabaseConfig{ |
| 485 | Targets: []string{database.Name}, |
| 486 | Sheet: sheet.Msg.Name, |
| 487 | }, |
| 488 | }, |
| 489 | }, |
| 490 | }, |
| 491 | }, |
| 492 | })) |
| 493 | a.NoError(err) |
| 494 | |
| 495 | result, err := ctl.GetSQLReviewResult(ctx, plan.Msg) |
| 496 | a.NoError(err) |
| 497 | |
| 498 | var statementAdviseResults []*v1pb.PlanCheckRun_Result |
| 499 | for _, r := range result.Results { |
| 500 | if r.Type == v1pb.PlanCheckRun_Result_STATEMENT_ADVISE { |
| 501 | statementAdviseResults = append(statementAdviseResults, r) |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | if wait { |
| 506 | a.NotNil(result) |
| 507 | a.Len(statementAdviseResults, 1) |
| 508 | a.Equal(v1pb.Advice_SUCCESS, statementAdviseResults[0].Status) |
| 509 | issue, err := ctl.issueServiceClient.CreateIssue(ctx, connect.NewRequest(&v1pb.CreateIssueRequest{ |
| 510 | Parent: project.Name, |
| 511 | Issue: &v1pb.Issue{ |
| 512 | Type: v1pb.Issue_DATABASE_CHANGE, |
| 513 | Title: fmt.Sprintf("change database %s", database.Name), |
| 514 | Description: fmt.Sprintf("change database %s", database.Name), |
| 515 | Plan: plan.Msg.Name, |
| 516 | }, |
| 517 | })) |
| 518 | a.NoError(err) |
| 519 | rollout, err := ctl.rolloutServiceClient.CreateRollout(ctx, connect.NewRequest(&v1pb.CreateRolloutRequest{Parent: plan.Msg.Name})) |
| 520 | a.NoError(err) |
| 521 | err = ctl.waitRollout(ctx, issue.Msg.Name, rollout.Msg.Name) |
| 522 | a.NoError(err) |
| 523 | // Wait some time till written data becomes consistent. |
| 524 | time.Sleep(5 * time.Second) |
| 525 | } |
no test coverage detected