Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Commit

Permalink
fix(ui): deleting vcs provider no longer breaks module page
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Sep 2, 2023
1 parent 419e2fb commit e28b931
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 41 deletions.
8 changes: 5 additions & 3 deletions internal/http/html/static/templates/content/module_get.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
{{ end }}
</select>
</form>
<div>
Source <span class="bg-gray-200">{{ .Module.Connection.Repo }}</span>
</div>
{{ with .Module.Connection }}
<div>
Source <span class="bg-gray-200" id="vcs-repo">{{ .Repo }}</span>
</div>
{{ end }}
</div>
<div>
<h3 class="font-semibold">
Expand Down
7 changes: 4 additions & 3 deletions internal/integration/connect_repo_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ func TestConnectRepoE2E(t *testing.T) {
github.WithCommit("0335fb07bb0244b7a169ee89d15c7703e4aaf7de"),
github.WithArchive(testutils.ReadFile(t, "../testdata/github.tar.gz")),
)
// create vcs provider for authenticating to github backend
provider := daemon.createVCSProvider(t, ctx, org)

browser.Run(t, ctx, chromedp.Tasks{
createGithubVCSProviderTasks(t, daemon.Hostname(), org.Name, "github"),
createWorkspace(t, daemon.Hostname(), org.Name, "my-test-workspace"),
connectWorkspaceTasks(t, daemon.Hostname(), org.Name, "my-test-workspace"),
connectWorkspaceTasks(t, daemon.Hostname(), org.Name, "my-test-workspace", provider.Name),
// we can now start a run via the web ui, which'll retrieve the tarball from
// the fake github server
startRunTasks(t, daemon.Hostname(), org.Name, "my-test-workspace", run.PlanAndApplyOperation),
Expand Down Expand Up @@ -103,6 +104,6 @@ func TestConnectRepoE2E(t *testing.T) {
// click delete button for one and only vcs provider
chromedp.Click(`//button[text()='delete']`),
screenshot(t),
matchText(t, "//div[@role='alert']", "deleted provider: github"),
matchText(t, "//div[@role='alert']", "deleted provider: "+provider.Name),
})
}
32 changes: 30 additions & 2 deletions internal/integration/module_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ func TestModuleE2E(t *testing.T) {
github.WithRefs("tags/v0.0.1", "tags/v0.0.2", "tags/v0.1.0"),
github.WithArchive(testutils.ReadFile(t, "./fixtures/github.module.tar.gz")),
)
// create vcs provider for module to authenticate to github backend
provider := svc.createVCSProvider(t, ctx, org)

var moduleURL string // captures url for module page
browser.Run(t, ctx, chromedp.Tasks{
createGithubVCSProviderTasks(t, svc.Hostname(), org.Name, "github"),
// publish module
chromedp.Tasks{
// go to org
Expand All @@ -52,9 +53,14 @@ func TestModuleE2E(t *testing.T) {
screenshot(t, "newly_created_module_page"),
// flash message indicates success
matchText(t, `//div[@role='alert']`, `published module: mod`),
// TODO: confirm versions are populated
// capture module url so we can visit it later
chromedp.Location(&moduleURL),
// confirm versions are populated
chromedp.WaitEnabled(`//select[@id='version']/option[text()='0.0.1']`),
chromedp.WaitEnabled(`//select[@id='version']/option[text()='0.0.2']`),
chromedp.WaitEnabled(`//select[@id='version']/option[text()='0.1.0']`),
// should show vcs repo source
matchRegex(t, `//span[@id='vcs-repo']`, `.*/terraform-aws-mod`),
},
})

Expand Down Expand Up @@ -98,4 +104,26 @@ module "mod" {
require.Contains(t, out, "Plan: 2 to add, 0 to change, 0 to destroy.")
out = svc.tfcli(t, ctx, "apply", root, "-auto-approve")
require.Contains(t, string(out), "Apply complete! Resources: 2 added, 0 changed, 0 destroyed.")

// delete vcs provider and visit the module page; it should be no longer
// connected. Then delete the module.
_, err = svc.DeleteVCSProvider(ctx, provider.ID)
require.NoError(t, err)
browser.Run(t, ctx, chromedp.Tasks{
chromedp.Tasks{
// go to org
chromedp.Navigate(organizationURL(svc.Hostname(), org.Name)),
screenshot(t),
// go to modules
chromedp.Click("#modules > a", chromedp.ByQuery),
// select existing module
chromedp.Click(`//a[text()='mod']`),
// confirm no longer connected
chromedp.WaitNotPresent(`//span[@id='vcs-repo']`),
// delete module
chromedp.Click(`//button[text()='Delete module']`),
// flash message indicates success
matchText(t, `//div[@role='alert']`, `deleted module: mod`),
},
})
}
30 changes: 2 additions & 28 deletions internal/integration/ui_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,32 +210,6 @@ func addWorkspacePermission(t *testing.T, hostname, org, workspaceName, team, ro
}
}

func createGithubVCSProviderTasks(t *testing.T, hostname, org, name string) chromedp.Tasks {
t.Helper()

return chromedp.Tasks{
// go to org
chromedp.Navigate(organizationURL(hostname, org)),
screenshot(t, "organization_main_menu"),
// go to vcs providers
chromedp.Click("#vcs_providers > a", chromedp.ByQuery),
screenshot(t, "vcs_providers_list"),
// click 'New Github VCS Provider' button
chromedp.Click(`//button[text()='New Github VCS Provider']`),
screenshot(t, "new_github_vcs_provider_form"),
// enter fake github token and name
chromedp.Focus("textarea#token", chromedp.NodeVisible, chromedp.ByQuery),
input.InsertText("fake-github-personal-token"),
chromedp.Focus("input#name", chromedp.ByQuery),
input.InsertText(name),
screenshot(t),
// submit form to create provider
chromedp.Submit("textarea#token", chromedp.ByQuery),
screenshot(t),
matchText(t, "//div[@role='alert']", "created provider: github"),
}
}

// startRunTasks starts a run via the UI
func startRunTasks(t *testing.T, hostname, organization, workspaceName string, op run.Operation) chromedp.Tasks {
t.Helper()
Expand Down Expand Up @@ -277,7 +251,7 @@ func startRunTasks(t *testing.T, hostname, organization, workspaceName string, o
}
}

func connectWorkspaceTasks(t *testing.T, hostname, org, name string) chromedp.Tasks {
func connectWorkspaceTasks(t *testing.T, hostname, org, name, provider string) chromedp.Tasks {
t.Helper()

return chromedp.Tasks{
Expand All @@ -291,7 +265,7 @@ func connectWorkspaceTasks(t *testing.T, hostname, org, name string) chromedp.Ta
chromedp.Click(`//button[@id='list-workspace-vcs-providers-button']`),
screenshot(t, "workspace_vcs_providers_list"),
// select provider
chromedp.Click(`//a[normalize-space(text())='github']`),
chromedp.Click(fmt.Sprintf(`//a[normalize-space(text())='%s']`, provider)),
screenshot(t, "workspace_vcs_repo_list"),
// connect to first repo in list (there should only be one)
chromedp.Click(`//div[@class='content-list']//button[text()='connect']`),
Expand Down
36 changes: 36 additions & 0 deletions internal/integration/vcsprovider_ui_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package integration

import (
"testing"

"github.com/chromedp/cdproto/input"
"github.com/chromedp/chromedp"
)

// TestIntegration_VCSProviderUI demonstrates management of vcs providers via
// the UI.
func TestIntegration_VCSProviderUI(t *testing.T) {
integrationTest(t)

daemon, org, ctx := setup(t, nil)

browser.Run(t, ctx, chromedp.Tasks{
// go to org
chromedp.Navigate(organizationURL(daemon.Hostname(), org.Name)),
screenshot(t, "organization_main_menu"),
// go to vcs providers
chromedp.Click("#vcs_providers > a", chromedp.ByQuery),
screenshot(t, "vcs_providers_list"),
// click 'New Github VCS Provider' button
chromedp.Click(`//button[text()='New Github VCS Provider']`),
screenshot(t, "new_github_vcs_provider_form"),
// enter fake github token and name
chromedp.Focus("textarea#token", chromedp.NodeVisible, chromedp.ByQuery),
input.InsertText("fake-github-personal-token"),
chromedp.Focus("input#name", chromedp.ByQuery),
input.InsertText("my-token"),
// submit form to create provider
chromedp.Submit("textarea#token", chromedp.ByQuery),
matchText(t, "//div[@role='alert']", "created provider: my-token"),
})
}
7 changes: 4 additions & 3 deletions internal/integration/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ func TestWebhook(t *testing.T) {
daemon, org, ctx := setup(t, nil,
github.WithRepo(repo),
)
// create vcs provider for authenticating to github backend
provider := daemon.createVCSProvider(t, ctx, org)

// create and connect first workspace
browser.Run(t, ctx, chromedp.Tasks{
createGithubVCSProviderTasks(t, daemon.Hostname(), org.Name, "github"),
createWorkspace(t, daemon.Hostname(), org.Name, "workspace-1"),
connectWorkspaceTasks(t, daemon.Hostname(), org.Name, "workspace-1"),
connectWorkspaceTasks(t, daemon.Hostname(), org.Name, "workspace-1", provider.Name),
})

// webhook should be registered with github
Expand All @@ -44,7 +45,7 @@ func TestWebhook(t *testing.T) {
// create and connect second workspace
browser.Run(t, ctx, chromedp.Tasks{
createWorkspace(t, daemon.Hostname(), org.Name, "workspace-2"),
connectWorkspaceTasks(t, daemon.Hostname(), org.Name, "workspace-2"),
connectWorkspaceTasks(t, daemon.Hostname(), org.Name, "workspace-2", provider.Name),
})

// second workspace re-uses same webhook on github
Expand Down
5 changes: 3 additions & 2 deletions internal/integration/workspace_ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func TestIntegration_WorkspaceUI(t *testing.T) {
github.WithRepo(repo),
github.WithArchive(testutils.ReadFile(t, "../testdata/github.tar.gz")),
)
// create vcs provider for authenticating to github backend
provider := daemon.createVCSProvider(t, ctx, org)

// demonstrate listing and searching
browser.Run(t, ctx, chromedp.Tasks{
Expand All @@ -43,8 +45,7 @@ func TestIntegration_WorkspaceUI(t *testing.T) {
})
// demonstrate setting vcs trigger patterns
browser.Run(t, ctx, chromedp.Tasks{
createGithubVCSProviderTasks(t, daemon.Hostname(), org.Name, "github"),
connectWorkspaceTasks(t, daemon.Hostname(), org.Name, "workspace-1"),
connectWorkspaceTasks(t, daemon.Hostname(), org.Name, "workspace-1", provider.Name),
chromedp.Navigate(workspaceURL(daemon.Hostname(), org.Name, "workspace-1")),
// go to workspace settings
chromedp.Click(`//a[text()='settings']`),
Expand Down

0 comments on commit e28b931

Please sign in to comment.