From e28b931703848430d0943cf2606d701511b2f003 Mon Sep 17 00:00:00 2001 From: Louis Garman Date: Sat, 2 Sep 2023 11:13:42 +0100 Subject: [PATCH] fix(ui): deleting vcs provider no longer breaks module page --- .../static/templates/content/module_get.tmpl | 8 +++-- internal/integration/connect_repo_e2e_test.go | 7 ++-- internal/integration/module_e2e_test.go | 32 +++++++++++++++-- internal/integration/ui_helpers_test.go | 30 ++-------------- internal/integration/vcsprovider_ui_test.go | 36 +++++++++++++++++++ internal/integration/webhook_test.go | 7 ++-- internal/integration/workspace_ui_test.go | 5 +-- 7 files changed, 84 insertions(+), 41 deletions(-) create mode 100644 internal/integration/vcsprovider_ui_test.go diff --git a/internal/http/html/static/templates/content/module_get.tmpl b/internal/http/html/static/templates/content/module_get.tmpl index 1ae7ff762..43424f963 100644 --- a/internal/http/html/static/templates/content/module_get.tmpl +++ b/internal/http/html/static/templates/content/module_get.tmpl @@ -20,9 +20,11 @@ {{ end }} -
- Source {{ .Module.Connection.Repo }} -
+ {{ with .Module.Connection }} +
+ Source {{ .Repo }} +
+ {{ end }}

diff --git a/internal/integration/connect_repo_e2e_test.go b/internal/integration/connect_repo_e2e_test.go index 787075b54..a33c49d42 100644 --- a/internal/integration/connect_repo_e2e_test.go +++ b/internal/integration/connect_repo_e2e_test.go @@ -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), @@ -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), }) } diff --git a/internal/integration/module_e2e_test.go b/internal/integration/module_e2e_test.go index 4b862690c..66db5ec94 100644 --- a/internal/integration/module_e2e_test.go +++ b/internal/integration/module_e2e_test.go @@ -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 @@ -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`), }, }) @@ -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`), + }, + }) } diff --git a/internal/integration/ui_helpers_test.go b/internal/integration/ui_helpers_test.go index 151dc3495..2a1b4136b 100644 --- a/internal/integration/ui_helpers_test.go +++ b/internal/integration/ui_helpers_test.go @@ -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() @@ -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{ @@ -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']`), diff --git a/internal/integration/vcsprovider_ui_test.go b/internal/integration/vcsprovider_ui_test.go new file mode 100644 index 000000000..20ee57f44 --- /dev/null +++ b/internal/integration/vcsprovider_ui_test.go @@ -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"), + }) +} diff --git a/internal/integration/webhook_test.go b/internal/integration/webhook_test.go index 24c93f12b..26a4a6d47 100644 --- a/internal/integration/webhook_test.go +++ b/internal/integration/webhook_test.go @@ -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 @@ -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 diff --git a/internal/integration/workspace_ui_test.go b/internal/integration/workspace_ui_test.go index 7dd809be5..47de6f8e3 100644 --- a/internal/integration/workspace_ui_test.go +++ b/internal/integration/workspace_ui_test.go @@ -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{ @@ -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']`),