setupPlanUpdateFixture creates the fixture. withIssue=false skips the CreateIssue call (used by the no-issue gate test).
(t *testing.T, withIssue bool)
| 30 | // setupPlanUpdateFixture creates the fixture. withIssue=false skips the |
| 31 | // CreateIssue call (used by the no-issue gate test). |
| 32 | func setupPlanUpdateFixture(t *testing.T, withIssue bool) *planUpdateFixture { |
| 33 | t.Helper() |
| 34 | a := require.New(t) |
| 35 | ctx := context.Background() |
| 36 | ctl := &controller{} |
| 37 | ctx, err := ctl.StartServerWithExternalPg(ctx) |
| 38 | a.NoError(err) |
| 39 | t.Cleanup(func() { _ = ctl.Close(ctx) }) |
| 40 | |
| 41 | instanceRootDir := t.TempDir() |
| 42 | instanceName := "planUpdateInstance_" + generateRandomString("inst") |
| 43 | instanceDir, err := ctl.provisionSQLiteInstance(instanceRootDir, instanceName) |
| 44 | a.NoError(err) |
| 45 | instanceResp, err := ctl.instanceServiceClient.CreateInstance(ctx, connect.NewRequest(&v1pb.CreateInstanceRequest{ |
| 46 | InstanceId: generateRandomString("instance"), |
| 47 | Instance: &v1pb.Instance{ |
| 48 | Title: instanceName, |
| 49 | Engine: v1pb.Engine_SQLITE, |
| 50 | Environment: new("environments/prod"), |
| 51 | Activation: true, |
| 52 | DataSources: []*v1pb.DataSource{{Type: v1pb.DataSourceType_ADMIN, Host: instanceDir, Id: "admin"}}, |
| 53 | }, |
| 54 | })) |
| 55 | a.NoError(err) |
| 56 | instance := instanceResp.Msg |
| 57 | |
| 58 | databaseName := "planUpdateDb_" + generateRandomString("db") |
| 59 | a.NoError(ctl.createDatabase(ctx, ctl.project, instance, nil, databaseName, "")) |
| 60 | databaseResp, err := ctl.databaseServiceClient.GetDatabase(ctx, connect.NewRequest(&v1pb.GetDatabaseRequest{ |
| 61 | Name: fmt.Sprintf("%s/databases/%s", instance.Name, databaseName), |
| 62 | })) |
| 63 | a.NoError(err) |
| 64 | |
| 65 | mkSheet := func(content string) *v1pb.Sheet { |
| 66 | s, err := ctl.sheetServiceClient.CreateSheet(ctx, connect.NewRequest(&v1pb.CreateSheetRequest{ |
| 67 | Parent: ctl.project.Name, |
| 68 | Sheet: &v1pb.Sheet{Content: []byte(content)}, |
| 69 | })) |
| 70 | a.NoError(err) |
| 71 | return s.Msg |
| 72 | } |
| 73 | sheet1 := mkSheet("CREATE TABLE plan_update_a (id INTEGER PRIMARY KEY);") |
| 74 | sheet2 := mkSheet("CREATE TABLE plan_update_b (id INTEGER PRIMARY KEY);") |
| 75 | |
| 76 | planResp, err := ctl.planServiceClient.CreatePlan(ctx, connect.NewRequest(&v1pb.CreatePlanRequest{ |
| 77 | Parent: ctl.project.Name, |
| 78 | Plan: &v1pb.Plan{ |
| 79 | Specs: []*v1pb.Plan_Spec{{ |
| 80 | Id: uuid.NewString(), |
| 81 | Config: &v1pb.Plan_Spec_ChangeDatabaseConfig{ |
| 82 | ChangeDatabaseConfig: &v1pb.Plan_ChangeDatabaseConfig{ |
| 83 | Targets: []string{databaseResp.Msg.Name}, |
| 84 | Sheet: sheet1.Name, |
| 85 | }, |
| 86 | }, |
| 87 | }}, |
| 88 | }, |
| 89 | })) |
no test coverage detected