Skip to content

Commit 74e7f0e

Browse files
authored
Added application sanity test (#290)
* Added application sanity test
1 parent 5ac0be1 commit 74e7f0e

File tree

8 files changed

+352
-67
lines changed

8 files changed

+352
-67
lines changed

.github/workflows/test.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ jobs:
206206
make ui-build-for-tests
207207
208208
cd test/integration/test
209-
go test -v -ginkgo.v -run TestMccpUI -ginkgo.skip=@integration -ginkgo.skip=@gce -ginkgo.skip=@eks --timeout=99999s
209+
go test -v -ginkgo.v -run TestMccpUI -ginkgo.skip=@integration -ginkgo.skip=@gce -ginkgo.skip=@eks -ginkgo.skip=@application -ginkgo.skip=@upgrade --timeout=99999s
210210
- name: Store integration test results
211211
if: ${{ always() }}
212212
uses: actions/upload-artifact@v2
@@ -377,8 +377,7 @@ jobs:
377377
- name: Download gitops binary from s3
378378
run: |
379379
mkdir -p cmd/gitops/
380-
# wget https://weave-gitops.s3.us-east-2.amazonaws.com/gitops-ubuntu-latest
381-
curl -L "https://github.com/weaveworks/weave-gitops/releases/download/v0.4.1/gitops-$(uname)-$(uname -m)" -o gitops-ubuntu-latest
380+
wget https://weave-gitops.s3.us-east-2.amazonaws.com/gitops-ubuntu-latest
382381
mv gitops-ubuntu-latest $GITOPS_BIN_PATH
383382
- name: Change bin permissions
384383
run: |

test/acceptance/test/cli_add_delete.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ func DescribeCliAddDelete(gitopsTestRunner GitopsTestRunner) {
430430
KubeconfigPath: "",
431431
}
432432
connectACluster(webDriver, gitopsTestRunner, leaf)
433+
434+
By("And template repo does not already exist", func() {
435+
gitopsTestRunner.DeleteRepo(CLUSTER_REPOSITORY)
436+
_ = deleteDirectory([]string{path.Join("/tmp", CLUSTER_REPOSITORY)})
437+
})
433438
})
434439

435440
JustAfterEach(func() {
@@ -446,10 +451,6 @@ func DescribeCliAddDelete(gitopsTestRunner GitopsTestRunner) {
446451
})
447452

448453
It("@capd Verify leaf CAPD cluster can be provisioned and kubeconfig is available for cluster operations", func() {
449-
By("And template repo does not already exist", func() {
450-
gitopsTestRunner.DeleteRepo(CLUSTER_REPOSITORY)
451-
_ = deleteDirectory([]string{path.Join("/tmp", CLUSTER_REPOSITORY)})
452-
})
453454

454455
var repoAbsolutePath string
455456
By("When I create a private repository for cluster configs", func() {
@@ -461,7 +462,7 @@ func DescribeCliAddDelete(gitopsTestRunner GitopsTestRunner) {
461462

462463
By("And I install gitops to my active cluster", func() {
463464
Expect(FileExists(GITOPS_BIN_PATH)).To(BeTrue(), fmt.Sprintf("%s can not be found.", GITOPS_BIN_PATH))
464-
InstallAndVerifyGitops(GITOPS_DEFAULT_NAMESPACE)
465+
InstallAndVerifyGitops(GITOPS_DEFAULT_NAMESPACE, GetGitRepositoryURL(repoAbsolutePath))
465466
})
466467

467468
addCommand := fmt.Sprintf("add app . --path=./management --name=%s --auto-merge=true", appName)

test/acceptance/test/cli_upgrade.go

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ func DescribeCliUpgrade(gitopsTestRunner GitopsTestRunner) {
8787
// Create vanilla cluster for WGE upgrade
8888
CreateCluster("kind", kind_upgrade_cluster_name, "upgrade-kind-config.yaml")
8989

90+
By("And cluster repo does not already exist", func() {
91+
gitopsTestRunner.DeleteRepo(CLUSTER_REPOSITORY)
92+
_ = deleteDirectory([]string{path.Join("/tmp", CLUSTER_REPOSITORY)})
93+
})
94+
9095
})
9196

9297
JustAfterEach(func() {
@@ -106,53 +111,53 @@ func DescribeCliUpgrade(gitopsTestRunner GitopsTestRunner) {
106111

107112
It("@upgrade Verify wego core can be upgraded to wego enterprise", func() {
108113

109-
By("When I install gitops/wego to my active cluster", func() {
110-
InstallAndVerifyGitops(GITOPS_DEFAULT_NAMESPACE)
111-
})
112-
113-
By("And I install profile controllers to my active cluster", func() {
114-
InstallAndVerifyPctl(GITOPS_DEFAULT_NAMESPACE)
115-
})
116-
117-
By("And cluster repo does not already exist", func() {
118-
gitopsTestRunner.DeleteRepo(CLUSTER_REPOSITORY)
119-
_ = deleteDirectory([]string{path.Join("/tmp", CLUSTER_REPOSITORY)})
120-
})
121-
122114
By("When I create a private repository for cluster configs", func() {
123115
repoAbsolutePath = gitopsTestRunner.InitAndCreateEmptyRepo(CLUSTER_REPOSITORY, true)
124116
testFile := createTestFile("README.md", "# gitops-capi-template")
125117

126118
gitopsTestRunner.GitAddCommitPush(repoAbsolutePath, testFile)
127119
})
128120

121+
By("When I install gitops/wego to my active cluster", func() {
122+
InstallAndVerifyGitops(GITOPS_DEFAULT_NAMESPACE, GetGitRepositoryURL(repoAbsolutePath))
123+
})
124+
125+
By("And I install profile controllers to my active cluster", func() {
126+
InstallAndVerifyPctl(GITOPS_DEFAULT_NAMESPACE)
127+
})
128+
129129
addCommand := fmt.Sprintf("add app . --path=./%s --name=%s --auto-merge=true", appPath, appName)
130130
By(fmt.Sprintf("And I run gitops add app command ' %s 'in namespace %s from dir %s", addCommand, GITOPS_DEFAULT_NAMESPACE, repoAbsolutePath), func() {
131-
command := exec.Command("sh", "-c", fmt.Sprintf("cd %s && %s %s", repoAbsolutePath, GITOPS_BIN_PATH, addCommand))
132-
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
133-
Expect(err).ShouldNot(HaveOccurred())
134-
Eventually(session).Should(gexec.Exit())
135-
Expect(string(session.Err.Contents())).Should(BeEmpty())
131+
cmd := fmt.Sprintf("cd %s && %s %s", repoAbsolutePath, GITOPS_BIN_PATH, addCommand)
132+
_, err := runCommandAndReturnStringOutput(cmd)
133+
Expect(err).Should(BeEmpty())
136134
})
137135

138136
By("And I install the entitlement for cluster upgrade", func() {
139137
Expect(gitopsTestRunner.KubectlApply([]string{}, "../../utils/scripts/entitlement-secret.yaml"), "Failed to create/configure entitlement")
140138
})
141139

142140
By("And I install the git repository secret for cluster service", func() {
143-
command := exec.Command("sh", "-c", fmt.Sprintf(`kubectl create secret generic git-provider-credentials --namespace=%s --from-literal="GIT_PROVIDER_TOKEN=%s"`, GITOPS_DEFAULT_NAMESPACE, GITHUB_TOKEN))
144-
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
145-
Expect(err).ShouldNot(HaveOccurred())
146-
Eventually(session, ASSERTION_2MINUTE_TIME_OUT).Should(gexec.Exit())
147-
Expect(string(session.Err.Contents())).Should(BeEmpty(), "Failed to create git repository secret for cluster service")
141+
cmd := fmt.Sprintf(`kubectl create secret generic git-provider-credentials --namespace=%s --from-literal="GIT_PROVIDER_TOKEN=%s"`, GITOPS_DEFAULT_NAMESPACE, GITHUB_TOKEN)
142+
_, err := runCommandAndReturnStringOutput(cmd)
143+
Expect(err).Should(BeEmpty(), "Failed to create git repository secret for cluster service")
148144
})
149145

150146
By("And I install the docker registry secret for wego enteprise components", func() {
151-
command := exec.Command("sh", "-c", fmt.Sprintf(`kubectl create secret docker-registry docker-io-pull-secret --namespace=%s --docker-username=%s --docker-password=%s`, GITOPS_DEFAULT_NAMESPACE, DOCKER_IO_USER, DOCKER_IO_PASSWORD))
152-
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
153-
Expect(err).ShouldNot(HaveOccurred())
154-
Eventually(session, ASSERTION_2MINUTE_TIME_OUT).Should(gexec.Exit())
155-
Expect(string(session.Err.Contents())).Should(BeEmpty(), "Failed to create git repository secret for cluster service")
147+
cmd := fmt.Sprintf(`kubectl create secret docker-registry docker-io-pull-secret --namespace=%s --docker-username=%s --docker-password=%s`, GITOPS_DEFAULT_NAMESPACE, DOCKER_IO_USER, DOCKER_IO_PASSWORD)
148+
_, err := runCommandAndReturnStringOutput(cmd)
149+
Expect(err).Should(BeEmpty(), "Failed to create git repository secret for cluster service")
150+
})
151+
152+
By(fmt.Sprintf("And wait for %s/%s GitRepository resource to be available in cluster", GITOPS_DEFAULT_NAMESPACE, appName), func() {
153+
repoExists := func() bool {
154+
cmd := fmt.Sprintf(`kubectl get GitRepository %s -n %s`, appName, GITOPS_DEFAULT_NAMESPACE)
155+
out, _ := runCommandAndReturnStringOutput(cmd)
156+
157+
return out != ""
158+
}
159+
Eventually(repoExists, ASSERTION_2MINUTE_TIME_OUT, POLL_INTERVAL_5SECONDS).Should(BeTrue(), fmt.Sprintf("%s/%s Gitrepository resource does not exist in the cluster", GITOPS_DEFAULT_NAMESPACE, appName))
160+
156161
})
157162

158163
prBranch := "wego-upgrade-enterprise"
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package pages
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
"time"
7+
8+
. "github.com/onsi/gomega"
9+
10+
"github.com/sclevine/agouti"
11+
. "github.com/sclevine/agouti/matchers"
12+
)
13+
14+
type ApplicationPage struct {
15+
ApplicationHeader *agouti.Selection
16+
ApplicationCount *agouti.Selection
17+
AddApplication *agouti.Selection
18+
ApplicationTable *agouti.MultiSelection
19+
}
20+
21+
type Applicationrow struct {
22+
Application *agouti.Selection
23+
}
24+
25+
type Conditions struct {
26+
Type *agouti.Selection
27+
Status *agouti.Selection
28+
Reason *agouti.Selection
29+
Message *agouti.Selection
30+
}
31+
32+
type ApplicationDetails struct {
33+
Name *agouti.Selection
34+
DeploymentType *agouti.Selection
35+
URL *agouti.Selection
36+
Path *agouti.Selection
37+
}
38+
39+
// This function waits for application graph to be rendered
40+
func (a ApplicationDetails) WaitForPageToLoad(webDriver *agouti.Page) {
41+
Eventually(webDriver.Find(` svg g.output`)).Should(BeVisible(), "Application details failed to load/render as expected")
42+
}
43+
44+
// This function waits for main application page to be rendered
45+
func (a ApplicationPage) WaitForPageToLoad(webDriver *agouti.Page, appCount int) {
46+
Eventually(a.ApplicationCount).Should(BeVisible())
47+
Eventually(a.ApplicationCount, 30*time.Second).Should(MatchText(strconv.Itoa(appCount)), "Application page failed to load/render as expected")
48+
}
49+
50+
func GetApplicationPage(webDriver *agouti.Page) *ApplicationPage {
51+
applicationPage := ApplicationPage{
52+
ApplicationHeader: webDriver.Find(`div[role="heading"] a[href="/applications"]`),
53+
ApplicationCount: webDriver.FindByXPath(`//*[@href="/applications"]/parent::div[@role="heading"]/following-sibling::div`),
54+
AddApplication: webDriver.FindByButton(`Add Application`),
55+
ApplicationTable: webDriver.All(`tr.MuiTableRow-root a`),
56+
}
57+
58+
return &applicationPage
59+
}
60+
61+
func GetApplicationRow(applicationPage *ApplicationPage, applicationeName string) *Applicationrow {
62+
aCnt, _ := applicationPage.ApplicationTable.Count()
63+
for i := 0; i < aCnt; i++ {
64+
aName, _ := applicationPage.ApplicationTable.At(i).Text()
65+
if applicationeName == aName {
66+
return &Applicationrow{
67+
Application: applicationPage.ApplicationTable.At(i),
68+
}
69+
}
70+
}
71+
return nil
72+
}
73+
74+
func GetApplicationDetails(webDriver *agouti.Page) *ApplicationDetails {
75+
appDetalis := webDriver.Find(`div[role="list"] > table tr`)
76+
77+
return &ApplicationDetails{
78+
Name: appDetalis.FindByXPath(`td[1]`),
79+
DeploymentType: appDetalis.FindByXPath(`td[2]`),
80+
URL: appDetalis.FindByXPath(`td[3]`),
81+
Path: appDetalis.FindByXPath(`td[4]`),
82+
}
83+
}
84+
85+
func GetApplicationConditions(webDriver *agouti.Page, condition string) *Conditions {
86+
sourceConditions := webDriver.FindByXPath(fmt.Sprintf(`//h3[.="%s"]/following-sibling::div[1]//tbody/tr`, condition))
87+
88+
return &Conditions{
89+
Type: sourceConditions.FindByXPath(`td[1]`),
90+
Status: sourceConditions.FindByXPath(`td[2]`),
91+
Reason: sourceConditions.FindByXPath(`td[3]`),
92+
Message: sourceConditions.FindByXPath(`td[4]`),
93+
}
94+
}

test/acceptance/test/pages/navbar.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,25 @@ import (
66
. "github.com/onsi/ginkgo"
77
. "github.com/onsi/gomega"
88
"github.com/sclevine/agouti"
9-
. "github.com/sclevine/agouti/matchers"
109
)
1110

1211
//NavbarwebDriver webDriver elements
1312
type NavbarwebDriver struct {
14-
Title *agouti.Selection
15-
Clusters *agouti.Selection
16-
Templates *agouti.Selection
17-
Alerts *agouti.Selection
18-
Application *agouti.Selection
13+
Title *agouti.Selection
14+
Clusters *agouti.Selection
15+
Templates *agouti.Selection
16+
Alerts *agouti.Selection
17+
Applications *agouti.Selection
1918
}
2019

2120
//NavbarwebDriver initialises the webDriver object
2221
func Navbar(webDriver *agouti.Page) *NavbarwebDriver {
2322
navbar := NavbarwebDriver{
24-
Title: webDriver.Find(`nav a[title="Home"]`),
25-
Clusters: webDriver.Find(`nav a[href="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/clusters"]`),
26-
Templates: webDriver.Find(`nav a[href="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/clusters/templates"]`),
27-
Alerts: webDriver.Find(`nav a[href="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/clusters/alerts"]`),
28-
Application: webDriver.Find(`nav a[href="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/applications"]`),
23+
Title: webDriver.Find(`nav a[title="Home"]`),
24+
Clusters: webDriver.Find(`nav a[href="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/clusters"]`),
25+
Templates: webDriver.Find(`nav a[href="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/clusters/templates"]`),
26+
Alerts: webDriver.Find(`nav a[href="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/clusters/alerts"]`),
27+
Applications: webDriver.Find(`nav a[href="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/applications"]`),
2928
}
3029

3130
return &navbar
@@ -34,8 +33,17 @@ func Navbar(webDriver *agouti.Page) *NavbarwebDriver {
3433
func NavigateToPage(webDriver *agouti.Page, page string) {
3534
Expect(webDriver.Refresh()).ShouldNot(HaveOccurred())
3635
navbarPage := Navbar(webDriver)
36+
3737
By(fmt.Sprintf("When I click %s from Navbar", page), func() {
38-
Eventually(navbarPage.Templates).Should(HaveText(page))
39-
Expect(navbarPage.Templates.Click()).To(Succeed())
38+
switch page {
39+
case "Cluster":
40+
Expect(navbarPage.Clusters.Click()).To(Succeed())
41+
case "Templates":
42+
Expect(navbarPage.Templates.Click()).To(Succeed())
43+
case "Alerts":
44+
Expect(navbarPage.Alerts.Click()).To(Succeed())
45+
case "Applications":
46+
Expect(navbarPage.Applications.Click()).To(Succeed())
47+
}
4048
})
4149
}

0 commit comments

Comments
 (0)