MCPcopy
hub / github.com/rilldata/rill / testSelfHostedDeploy

Function testSelfHostedDeploy

cli/cmd/deploy/deploy_test.go:170–242  ·  view source on GitHub ↗
(t *testing.T, adminClient *client.Client, ghClient *github.Client, adm *testcli.Fixture, token string)

Source from the content-addressed store, hash-verified

168}
169
170func testSelfHostedDeploy(t *testing.T, adminClient *client.Client, ghClient *github.Client, adm *testcli.Fixture, token string) {
171 testmode.Expensive(t)
172 result := adm.Run(t, "org", "create", "github-test")
173 require.Equal(t, 0, result.ExitCode)
174
175 // create a rill project
176 tempDir := initRillProject(t)
177
178 // create a github repo
179 repoName := "self-hosted-git-repo" + uuid.NewString()[:8]
180 repo, _, err := ghClient.Repositories.Create(t.Context(), "", &github.Repository{
181 Name: github.Ptr(repoName),
182 Private: github.Ptr(true),
183 })
184 require.NoError(t, err)
185
186 // cleanup repo
187 t.Cleanup(func() {
188 owner, ghrepo, ok := gitutil.SplitGithubRemote(*repo.CloneURL)
189 require.True(t, ok, "invalid github remote: %s", *repo.CloneURL)
190 _, err = ghClient.Repositories.Delete(context.Background(), owner, ghrepo)
191 require.NoError(t, err, "failed to delete github repo %s/%s", owner, ghrepo)
192 })
193
194 // the create repo API does not wait for repo creation to be fully processed; poll until ready
195 waitForGithubRepo(t, ghClient, *repo.Owner.Login, repoName)
196
197 author := &object.Signature{
198 Name: "Rill test user",
199 Email: "test.user@rilldata.com",
200 When: time.Now(),
201 }
202 authCloneURL := authGitURL(t, *repo.CloneURL, token)
203 err = gitutil.CommitAndPush(t.Context(), tempDir, &gitutil.Config{
204 Remote: authCloneURL,
205 DefaultBranch: "main",
206 }, "", author)
207 require.NoError(t, err, "failed to push to github repo")
208
209 // deploy project backed by github
210 result = adm.Run(t, "deploy", "--interactive=false", "--org=github-test", "--project=self-hosted-deploy", "--skip-deploy=true", "--path="+tempDir)
211 require.Equal(t, 0, result.ExitCode, result.Output)
212
213 // verify the project is correctly created
214 resp, err := adminClient.GetProject(t.Context(), &adminv1.GetProjectRequest{
215 Org: "github-test",
216 Project: "self-hosted-deploy",
217 })
218 require.NoError(t, err)
219 require.Equal(t, "self-hosted-deploy", resp.Project.Name)
220 require.Empty(t, resp.Project.ManagedGitId)
221
222 // check remote configured in directory (normalize to strip any embedded credentials)
223 remote, err := gitutil.ExtractGitRemote(tempDir, "origin", false)
224 require.NoError(t, err)
225 normalizedRemoteURL, err := gitutil.NormalizeGithubRemote(remote.URL)
226 require.NoError(t, err)
227 require.Equal(t, *repo.CloneURL, normalizedRemoteURL)

Callers 1

TestGithubDeployFunction · 0.85

Calls 15

ExpensiveFunction · 0.92
SplitGithubRemoteFunction · 0.92
CommitAndPushFunction · 0.92
ExtractGitRemoteFunction · 0.92
NormalizeGithubRemoteFunction · 0.92
initRillProjectFunction · 0.85
waitForGithubRepoFunction · 0.85
authGitURLFunction · 0.85
verifyGithubRepoContentsFunction · 0.85
CreateMethod · 0.80
putFilesFunction · 0.70
ContextMethod · 0.65

Tested by

no test coverage detected