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

Function TestGitOpsRollout

backend/tests/gitops_test.go:623–783  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

621}
622
623func TestGitOpsRollout(t *testing.T) {
624 t.Parallel()
625 a := require.New(t)
626 ctx := context.Background()
627 ctl := &controller{}
628 ctx, err := ctl.StartServerWithExternalPg(ctx)
629 a.NoError(err)
630 defer ctl.Close(ctx)
631
632 // Create a project for GitOps testing.
633 projectID := generateRandomString("gitops-rollout")
634 projectResp, err := ctl.projectServiceClient.CreateProject(ctx, connect.NewRequest(&v1pb.CreateProjectRequest{
635 Project: &v1pb.Project{
636 Name: fmt.Sprintf("projects/%s", projectID),
637 Title: projectID,
638 AllowSelfApproval: true,
639 },
640 ProjectId: projectID,
641 }))
642 a.NoError(err)
643 project := projectResp.Msg
644
645 // Provision test instance.
646 instanceRootDir := t.TempDir()
647
648 testInstanceDir, err := ctl.provisionSQLiteInstance(instanceRootDir, "gitops-rollout-test")
649 a.NoError(err)
650
651 // Add the provisioned instance.
652 testInstanceResp, err := ctl.instanceServiceClient.CreateInstance(ctx, connect.NewRequest(&v1pb.CreateInstanceRequest{
653 InstanceId: generateRandomString("instance"),
654 Instance: &v1pb.Instance{
655 Title: "gitops-rollout-test",
656 Engine: v1pb.Engine_SQLITE,
657 Environment: new("environments/test"),
658 Activation: true,
659 DataSources: []*v1pb.DataSource{{Type: v1pb.DataSourceType_ADMIN, Host: testInstanceDir, Id: "admin"}},
660 },
661 }))
662 a.NoError(err)
663 testInstance := testInstanceResp.Msg
664
665 // Create database.
666 databaseName := "gitops_rollout_db"
667 err = ctl.createDatabase(ctx, project, testInstance, nil, databaseName, "")
668 a.NoError(err)
669
670 // Step 1: Create a release containing migration files.
671 createReleaseResp, err := ctl.releaseServiceClient.CreateRelease(ctx, connect.NewRequest(&v1pb.CreateReleaseRequest{
672 Parent: project.Name,
673 Release: &v1pb.Release{
674 Type: v1pb.Release_VERSIONED,
675 Files: []*v1pb.Release_File{
676 {
677 Path: "migrations/001__create_products_table.sql",
678 Version: "001",
679 Statement: []byte(`CREATE TABLE products (
680 id INTEGER PRIMARY KEY AUTOINCREMENT,

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
createDatabaseMethod · 0.95
waitRolloutMethod · 0.95
generateRandomStringFunction · 0.85
LenMethod · 0.80
CreateProjectMethod · 0.65
CreateInstanceMethod · 0.65
CreateReleaseMethod · 0.65
CreatePlanMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected