Skip to content

Commit

Permalink
Add application violations tests for leaf cluster (#1807)
Browse files Browse the repository at this point in the history
* add tests for leaf cluster and fix some lines in managmenet cluster tests

* restructure the leaf cluster creation section

* fix Functions docstrings

* prepare the branch to merge the main changes

* add some fixes after merge the main

* fix some lines in create leaf cluster section

* leaf cluster application violation test

* change the leaf cluster name and type

* change the patSecret name

* add wait for leaf clauster availability method

* Tweaks creating leaf cluster

* Fixed leaf-cluster application violation test

* fix typo errors

* re-structure the code by creating shared methods

* enhance the shared methods for app violations

* fix the review comments

* change the violatedPolicy object name to appViolations

Co-authored-by: Saeed Fazal <saeed@weave.works>
Co-authored-by: serboctor <boctor.sarah@gmail.com>
  • Loading branch information
3 people authored Nov 2, 2022
1 parent 330490c commit 508b957
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 115 deletions.
5 changes: 4 additions & 1 deletion test/acceptance/test/pages/applications_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ type ApplicationViolationsList struct {
SearchResult *agouti.Selection
}

// AppViolationsMsgInList contains the violation's message element
type AppViolationsMsgInList struct {
AppViolationsMsg *agouti.Selection
}

// ApplicationViolationsDetailsPage contains all the fields in the app violations details page
type ApplicationViolationsDetailsPage struct {
ViolationHeader *agouti.Selection
PolicyName *agouti.Selection
Expand Down Expand Up @@ -256,13 +258,14 @@ func GetApplicationViolationsList(webDriver *agouti.Page) *ApplicationViolations
return &applicationViolationsList
}

// GetAppViolationsMsgInList returns the violation's message field which we need to press it to open the app violations detail page
func GetAppViolationsMsgInList(webDriver *agouti.Page) *AppViolationsMsgInList {
return &AppViolationsMsgInList{
AppViolationsMsg: webDriver.FirstByXPath(`//td[1]//a`),
}
}

// GetApplicationViolationsDetailsPage will have all the locators for App Violations Details page.
// GetApplicationViolationsDetailsPage returns all the locators for the app violations details page
func GetApplicationViolationsDetailsPage(webDriver *agouti.Page) *ApplicationViolationsDetailsPage {
return &ApplicationViolationsDetailsPage{
ViolationHeader: webDriver.FindByXPath(`//div[@role="heading"]/a[@href="/applications"]/parent::node()/parent::node()/following-sibling::div[2]`),
Expand Down
382 changes: 274 additions & 108 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 @@ -202,7 +202,7 @@ func DescribeClusters(gitopsTestRunner GitopsTestRunner) {
createNamespace([]string{leafCluster.Namespace})
createPATSecret(leafCluster.Namespace, patSecret)
clusterBootstrapCopnfig = createClusterBootstrapConfig(leafCluster.Name, leafCluster.Namespace, bootstrapLabel, patSecret)
gitopsCluster = connectGitopsCuster(leafCluster.Name, leafCluster.Namespace, bootstrapLabel, leafClusterkubeconfig)
gitopsCluster = connectGitopsCluster(leafCluster.Name, leafCluster.Namespace, bootstrapLabel, leafClusterkubeconfig)

ginkgo.By("And wait for GitopsCluster to be visibe on the dashboard", func() {
gomega.Eventually(clustersPage.ClusterHeader).Should(matchers.BeVisible())
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/test/ui_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func DescribePolicies(gitopsTestRunner GitopsTestRunner) {
useClusterContext(mgmtClusterContext)
createPATSecret(leafClusterNamespace, patSecret)
clusterBootstrapCopnfig = createClusterBootstrapConfig(leafClusterName, leafClusterNamespace, bootstrapLabel, patSecret)
gitopsCluster = connectGitopsCuster(leafClusterName, leafClusterNamespace, bootstrapLabel, leafClusterkubeconfig)
gitopsCluster = connectGitopsCluster(leafClusterName, leafClusterNamespace, bootstrapLabel, leafClusterkubeconfig)
createLeafClusterSecret(leafClusterNamespace, leafClusterkubeconfig)

waitForLeafClusterAvailability(leafClusterName, "Ready")
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/test/ui_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func DescribeTenants(gitopsTestRunner GitopsTestRunner) {
useClusterContext(mgmtClusterContext)
createPATSecret(leafCluster.Namespace, patSecret)
clusterBootstrapCopnfig = createClusterBootstrapConfig(leafCluster.Name, leafCluster.Namespace, bootstrapLabel, patSecret)
gitopsCluster = connectGitopsCuster(leafCluster.Name, leafCluster.Namespace, bootstrapLabel, leafClusterkubeconfig)
gitopsCluster = connectGitopsCluster(leafCluster.Name, leafCluster.Namespace, bootstrapLabel, leafClusterkubeconfig)
createLeafClusterSecret(leafCluster.Namespace, leafClusterkubeconfig)

ginkgo.By(fmt.Sprintf("And I verify %s GitopsCluster/leafCluster is bootstraped)", leafCluster.Name), func() {
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/test/ui_violations.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func DescribeViolations(gitopsTestRunner GitopsTestRunner) {
useClusterContext(mgmtClusterContext)
createPATSecret(leafClusterNamespace, patSecret)
clusterBootstrapCopnfig = createClusterBootstrapConfig(leafClusterName, leafClusterNamespace, bootstrapLabel, patSecret)
gitopsCluster = connectGitopsCuster(leafClusterName, leafClusterNamespace, bootstrapLabel, leafClusterkubeconfig)
gitopsCluster = connectGitopsCluster(leafClusterName, leafClusterNamespace, bootstrapLabel, leafClusterkubeconfig)
createLeafClusterSecret(leafClusterNamespace, leafClusterkubeconfig)

waitForLeafClusterAvailability(leafClusterName, "Ready")
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/test/utils_gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func createClusterBootstrapConfig(clusterName string, nameSpace string, bootstra
return bootstrapConfig
}

func connectGitopsCuster(clusterName string, nameSpace string, bootstrapLabel string, kubeconfigSecret string) (gitopsCluster string) {
func connectGitopsCluster(clusterName string, nameSpace string, bootstrapLabel string, kubeconfigSecret string) (gitopsCluster string) {
ginkgo.By(fmt.Sprintf("Add GitopsCluster resource for %s cluster to management cluster", clusterName), func() {
contents, err := ioutil.ReadFile(path.Join(getCheckoutRepoPath(), "test/utils/data/gitops-cluster.yaml"))
gomega.Expect(err).To(gomega.BeNil(), "Failed to read GitopsCluster template yaml")
Expand Down Expand Up @@ -520,7 +520,7 @@ func deleteSource(sourceType, sourceName, namespace, kubeconfig string) {
}

func addKustomizationBases(clusterType, clusterName, clusterNamespace string) {
ginkgo.By("And add kustomization bases for common resources for leaf cluster)", func() {
ginkgo.By("And add kustomization bases for common resources for leaf cluster", func() {
repoAbsolutePath := path.Join(configRepoAbsolutePath(gitProviderEnv))
checkoutTestDataPath := path.Join(getCheckoutRepoPath(), "test", "utils", "data")
leafClusterPath := path.Join(repoAbsolutePath, "clusters", clusterNamespace, clusterName)
Expand Down

0 comments on commit 508b957

Please sign in to comment.