MCPcopy Index your code
hub / github.com/bytebase/bytebase / createIssueAndReturnSQLReviewResult

Function createIssueAndReturnSQLReviewResult

backend/tests/sql_review_test.go:468–528  ·  view source on GitHub ↗
(ctx context.Context, a *require.Assertions, ctl *controller, project *v1pb.Project, database *v1pb.Database, statement string, wait bool)

Source from the content-addressed store, hash-verified

466}
467
468func 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 }

Callers 2

TestSQLReviewForMySQLFunction · 0.85

Calls 8

GetSQLReviewResultMethod · 0.80
LenMethod · 0.80
waitRolloutMethod · 0.80
CreateSheetMethod · 0.65
CreatePlanMethod · 0.65
EqualMethod · 0.65
CreateIssueMethod · 0.65
CreateRolloutMethod · 0.65

Tested by

no test coverage detected