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
56 changes: 31 additions & 25 deletions test/acceptance/test/pages/applications_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,21 @@ type ApplicationDetailPage struct {
}

type ApplicationDetail struct {
Source *agouti.Selection
AppliedRevision *agouti.Selection
Cluster *agouti.Selection
Path *agouti.Selection
Interval *agouti.Selection
LastUpdated *agouti.Selection
Metadata *agouti.Selection
Name *agouti.Selection
Type *agouti.Selection
Namespace *agouti.Selection
Status *agouti.Selection
Message *agouti.Selection
Source *agouti.Selection
Chart *agouti.Selection
ChartVersion *agouti.Selection
AppliedRevision *agouti.Selection
AttemptedRevision *agouti.Selection
Cluster *agouti.Selection
Path *agouti.Selection
Interval *agouti.Selection
LastUpdated *agouti.Selection
Metadata *agouti.Selection
Name *agouti.Selection
Type *agouti.Selection
Namespace *agouti.Selection
Status *agouti.Selection
Message *agouti.Selection
}

type ApplicationEvent struct {
Expand Down Expand Up @@ -78,7 +81,7 @@ func (a ApplicationsPage) FindApplicationInList(applicationName string) *Applica
Namespace: application.FindByXPath(`td[4]`),
Tenant: application.FindByXPath(`td[5]`),
Cluster: application.FindByXPath(`td[6]`),
Source: application.FindByXPath(`td[7]`),
Source: application.FindByXPath(`td[7]//a`),
Status: application.FindByXPath(`td[8]`),
Message: application.FindByXPath(`td[9]`),
Revision: application.FindByXPath(`td[10]`),
Expand Down Expand Up @@ -120,18 +123,21 @@ func GetApplicationDetail(webDriver *agouti.Page) *ApplicationDetail {
reconcileDetails := webDriver.FindByXPath(`//div[contains(@class, "ReconciledObjectsTable")]//table/tbody//td[2][.="Deployment"]/ancestor::tr`)

return &ApplicationDetail{
Source: autoDetails.FindByXPath(`tr[1]/td[2]`),
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[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]`),
Namespace: reconcileDetails.FindByXPath(`td[3]`),
Status: reconcileDetails.FindByXPath(`td[4]`),
Message: reconcileDetails.FindByXPath(`td[5]`),
Source: autoDetails.FindByXPath(`tr[1]/td[2]`),
Chart: autoDetails.FindByXPath(`tr[contains(.,"Chart:")]/td[2]`),
ChartVersion: autoDetails.FindByXPath(`tr[contains(.,"Chart Version")]/td[2]`),
AppliedRevision: autoDetails.FindByXPath(`tr[contains(.,"Applied Revision")]/td[2]`),
AttemptedRevision: autoDetails.FindByXPath(`tr[contains(.,"Attempted Revision")]/td[2]`),
Cluster: autoDetails.FindByXPath(`tr[contains(.,"Cluster")]/td[2]`),
Path: autoDetails.FindByXPath(`tr[contains(.,"Path:")]/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]`),
Namespace: reconcileDetails.FindByXPath(`td[3]`),
Status: reconcileDetails.FindByXPath(`td[4]`),
Message: reconcileDetails.FindByXPath(`td[5]`),
}
}

Expand Down
28 changes: 20 additions & 8 deletions test/acceptance/test/ui_applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ func verifyAppDetails(app Application, cluster ClusterConfig) {

if app.Type == "helm_release" {
gomega.Eventually(details.Source.Text).Should(gomega.MatchRegexp("HelmChart/"+app.Namespace+"-"+app.Name), fmt.Sprintf("Failed to verify %s Source", app.Name))
gomega.Eventually(details.AppliedRevision.Text).Should(gomega.MatchRegexp(app.Name), fmt.Sprintf("Failed to verify %s Chart", app.Name))
gomega.Eventually(details.Chart.Text).Should(gomega.MatchRegexp(app.Name), fmt.Sprintf("Failed to verify %s Chart", app.Name))
gomega.Eventually(details.ChartVersion.Text).Should(gomega.MatchRegexp(app.Version), fmt.Sprintf("Failed to verify %s Chart Version", app.Name))
gomega.Eventually(details.AppliedRevision.Text, ASSERTION_30SECONDS_TIME_OUT).Should(gomega.MatchRegexp(app.Version), fmt.Sprintf("Failed to verify %s Last Applied Version", app.Name))
gomega.Eventually(details.AttemptedRevision.Text, ASSERTION_30SECONDS_TIME_OUT).Should(gomega.MatchRegexp(app.Version), fmt.Sprintf("Failed to verify %s Last Attempted Version", app.Name))

} else {
gomega.Eventually(details.Source.Text).Should(gomega.MatchRegexp("GitRepository/"+app.Name), fmt.Sprintf("Failed to verify %s Source", app.Name))
gomega.Eventually(details.AppliedRevision.Text).Should(gomega.MatchRegexp("master"), fmt.Sprintf("Failed to verify %s AppliedRevision", app.Name))
Expand All @@ -190,7 +194,8 @@ func verifyAppDetails(app Application, cluster ClusterConfig) {
gomega.Eventually(details.Name.Text).Should(gomega.MatchRegexp(app.DeploymentName), fmt.Sprintf("Failed to verify %s Deployment name", app.Name))
gomega.Eventually(details.Type.Text).Should(gomega.MatchRegexp("Deployment"), fmt.Sprintf("Failed to verify %s Type", app.Name))
gomega.Eventually(details.Namespace.Text).Should(gomega.MatchRegexp(app.TargetNamespace), fmt.Sprintf("Failed to verify %s Namespace", app.Name))
gomega.Eventually(details.Status.Text, ASSERTION_3MINUTE_TIME_OUT).Should(gomega.MatchRegexp("Ready"), fmt.Sprintf("Failed to verify %s Status", app.Name))

gomega.Eventually(details.Status.Text, ASSERTION_5MINUTE_TIME_OUT).Should(gomega.MatchRegexp("Ready"), fmt.Sprintf("Failed to verify %s Status", app.Name))
gomega.Eventually(details.Message.Text).Should(gomega.MatchRegexp("Deployment is available"), fmt.Sprintf("Failed to verify %s Message", app.Name))

})
Expand Down Expand Up @@ -340,6 +345,8 @@ func DescribeApplications(gitopsTestRunner GitopsTestRunner) {
})

ginkgo.Context("[UI] Applications(s) can be installed", func() {

var existingAppCount int
appNameSpace := "test-kustomization"
appTargetNamespace := "test-system"

Expand All @@ -354,6 +361,11 @@ func DescribeApplications(gitopsTestRunner GitopsTestRunner) {
})

ginkgo.JustAfterEach(func() {
// Wait for the application to be deleted gracefully, needed when the test fails before deleting the application
gomega.Eventually(func(g gomega.Gomega) int {
return getApplicationCount()
}, ASSERTION_2MINUTE_TIME_OUT, POLL_INTERVAL_5SECONDS).Should(gomega.Equal(existingAppCount), fmt.Sprintf("There should be %d application enteries after application(s) deletion", existingAppCount))

deleteNamespace([]string{appNameSpace, appTargetNamespace})
})

Expand All @@ -371,7 +383,7 @@ func DescribeApplications(gitopsTestRunner GitopsTestRunner) {

appDir := fmt.Sprintf("./clusters/%s/podinfo", mgmtCluster.Name)
repoAbsolutePath := configRepoAbsolutePath(gitProviderEnv)
existingAppCount := getApplicationCount()
existingAppCount = getApplicationCount()

appKustomization := createGitKustomization(podinfo.Source, podinfo.Namespace, "https://github.com/stefanprodan/podinfo", podinfo.Name, podinfo.TargetNamespace)
defer cleanGitRepository(appKustomization)
Expand Down Expand Up @@ -427,9 +439,9 @@ func DescribeApplications(gitopsTestRunner GitopsTestRunner) {
SyncInterval: "10m",
Name: "metallb",
DeploymentName: "metallb-controller",
Namespace: appNameSpace,
Namespace: GITOPS_DEFAULT_NAMESPACE, // HelmRelease application always get installed in flux-system namespace
TargetNamespace: appNameSpace,
Source: appNameSpace + "-metallb",
Source: GITOPS_DEFAULT_NAMESPACE + "-metallb",
Version: "0.0.2",
ValuesRegex: `namespace: ""`,
Values: fmt.Sprintf(`namespace: %s`, appNameSpace),
Expand All @@ -451,7 +463,7 @@ func DescribeApplications(gitopsTestRunner GitopsTestRunner) {
appKustomization := fmt.Sprintf("./clusters/%s/%s-%s-helmrelease.yaml", mgmtCluster.Name, metallb.Name, appNameSpace)

repoAbsolutePath := configRepoAbsolutePath(gitProviderEnv)
existingAppCount := getApplicationCount()
existingAppCount = getApplicationCount()

defer cleanGitRepository(appKustomization)

Expand Down Expand Up @@ -564,7 +576,7 @@ func DescribeApplications(gitopsTestRunner GitopsTestRunner) {
defer cleanGitRepository(appKustomization)

repoAbsolutePath := configRepoAbsolutePath(gitProviderEnv)
existingAppCount := getApplicationCount()
existingAppCount = getApplicationCount()

pages.NavigateToPage(webDriver, "Applications")
applicationsPage := pages.GetApplicationsPage(webDriver)
Expand Down Expand Up @@ -800,7 +812,7 @@ func DescribeApplications(gitopsTestRunner GitopsTestRunner) {
count, _ := applicationsPage.ApplicationCount.Text()
return count

}, ASSERTION_2MINUTE_TIME_OUT, POLL_INTERVAL_5SECONDS).Should(gomega.MatchRegexp(strconv.Itoa(totalAppCount)), fmt.Sprintf("Dashboard failed to update with expected applications count: %d", totalAppCount))
}, ASSERTION_3MINUTE_TIME_OUT, POLL_INTERVAL_5SECONDS).Should(gomega.MatchRegexp(strconv.Itoa(totalAppCount)), fmt.Sprintf("Dashboard failed to update with expected applications count: %d", totalAppCount))

gomega.Eventually(func(g gomega.Gomega) int {
return applicationsPage.CountApplications()
Expand Down
18 changes: 12 additions & 6 deletions test/acceptance/test/utils_gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/url"
"os"
"path"
"regexp"
Expand Down Expand Up @@ -139,7 +140,7 @@ func CheckClusterService(capiEndpointURL string) {

// Wait until we get a good looking response from /v1/<resource>
// Ignore all errors (connection refused, 500s etc)
func waitForGitopsResources(ctx context.Context, resourceName string, timeout time.Duration) error {
func waitForGitopsResources(ctx context.Context, resourcePath string, timeout time.Duration) error {
adminPassword := GetEnv("CLUSTER_ADMIN_PASSWORD", "")
waitCtx, cancel := context.WithTimeout(ctx, ASSERTION_5MINUTE_TIME_OUT)
defer cancel()
Expand All @@ -164,23 +165,28 @@ func waitForGitopsResources(ctx context.Context, resourceName string, timeout ti
return false, nil
}
// fetch gitops resource
resp, err = client.Get(test_ui_url + "/v1/" + resourceName)
resp, err = client.Get(test_ui_url + "/v1/" + resourcePath)
if err != nil {
logger.Tracef("error getting %s in (waiting for a success, retrying): %v", resourceName, err)
logger.Tracef("error getting %s in (waiting for a success, retrying): %v", resourcePath, err)
return false, nil
}
if resp.StatusCode != http.StatusOK {
logger.Tracef("wrong status from %s (waiting for a ok, retrying): %v", resourceName, resp.StatusCode)
logger.Tracef("wrong status from %s (waiting for a ok, retrying): %v", resourcePath, resp.StatusCode)
return false, nil
}

bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return false, nil
}
bodyString := string(bodyBytes)

return strings.Contains(strings.ToLower(bodyString), strings.ToLower(fmt.Sprintf(`%s":`, resourceName))), nil
parseUrl, err := url.Parse(resourcePath)
if err != nil {
logger.Errorf("failed to parse URL: %v", resourcePath)
return false, nil
}

return regexp.MatchString(strings.ToLower(fmt.Sprintf(`%s[\\"]+`, parseUrl.Path)), strings.ToLower(string(bodyBytes)))
}, waitCtx.Done())
}

Expand Down