(t *testing.T)
| 94 | } |
| 95 | |
| 96 | func TestManagedDeployWithPrimaryBranch(t *testing.T) { |
| 97 | testmode.Expensive(t) |
| 98 | adm := testadmin.New(t) |
| 99 | |
| 100 | _, c := adm.NewUser(t) |
| 101 | u1 := testcli.New(t, adm, c.Token) |
| 102 | |
| 103 | result := u1.Run(t, "org", "create", "github-branch-test") |
| 104 | require.Equal(t, 0, result.ExitCode) |
| 105 | |
| 106 | // set up a git repo with two branches having different content: |
| 107 | // - main: models/model.sql contains SELECT 'main' AS env |
| 108 | // - staging: models/model.sql contains SELECT 'staging' AS env |
| 109 | // The repo is left on the staging branch for the deploy. |
| 110 | tempDir := initRillProject(t) |
| 111 | initGitWithTwoBranches(t, tempDir) |
| 112 | |
| 113 | result = u1.Run(t, "project", "deploy", "--interactive=false", "--org=github-branch-test", "--project=rill-mgd-branch", "--skip-deploy=true", "--primary-branch=staging", "--path="+tempDir) |
| 114 | require.Equal(t, 0, result.ExitCode, result.Output) |
| 115 | |
| 116 | // verify the project is correctly created |
| 117 | resp, err := c.GetProject(t.Context(), &adminv1.GetProjectRequest{ |
| 118 | Org: "github-branch-test", |
| 119 | Project: "rill-mgd-branch", |
| 120 | }) |
| 121 | require.NoError(t, err) |
| 122 | require.Equal(t, "rill-mgd-branch", resp.Project.Name) |
| 123 | |
| 124 | // verify the primary branch is set to "staging" |
| 125 | require.Equal(t, "staging", resp.Project.PrimaryBranch) |
| 126 | |
| 127 | // get a github client |
| 128 | installationID, err := adm.Admin.Github.ManagedOrgInstallationID() |
| 129 | require.NoError(t, err) |
| 130 | ghClient := adm.Admin.Github.InstallationClient(installationID, nil) |
| 131 | |
| 132 | // verify the model file is present on the "staging" branch |
| 133 | verifyGithubRepoBranchContents(t, ghClient, resp.Project.GitRemote, "staging", map[string]string{ |
| 134 | "models/model.sql": `SELECT 'staging' AS env`, |
| 135 | }) |
| 136 | } |
| 137 | |
| 138 | // This test require gh cli to be installed on the system. |
| 139 | // Alternatively a personal access token can be set via RILL_TEST_GH_TOKEN environment variable. |
nothing calls this directly
no test coverage detected