Skip to content

Commit

Permalink
Add gitopssets tests (#17)
Browse files Browse the repository at this point in the history
* add gitopssets files and page

* add gitops sets tests

* fix fialed tests

* fix tests

* fix open_gitopssets_details_page test

* update assertion

* remove assertion

* change elements locators

* add more assertions

* add sync step

* add sync button test case

* add page reload

* update README file

* change sync button locator

* final update

* add new line at the end of files

* remove waiting time

* remove f from gitopssets test file

* remove f from policies & applications test files
  • Loading branch information
taghreed86 authored Dec 18, 2023
1 parent fe1dc83 commit 05bfd26
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 42 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,9 @@ jobs:
flux reconcile kustomization violating-podinfo -n default --with-source || true
kubectl get pods -A
- name: Wait 3 minutes for the App reconciliation
uses: jakejarvis/wait-action@master
with:
time: '3m'
- name: Install gitopsset-configmaps
run: |
kubectl apply -f ./utils/data/gitops-sets-kustomization.yaml
- name: run tests
if: success()
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ It is recommended to install latest and stable version of these tools. All tools
flux reconcile kustomization violating-podinfo -n default --with-source || true
kubectl get pods -A
```

11. Install gitopsset.
```bash
kubectl apply -f ./utils/data/gitops-sets-kustomization.yaml
```

## Run Tests

Expand Down
30 changes: 30 additions & 0 deletions gitops-sets/config-map-generator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: templates.weave.works/v1alpha1
kind: GitOpsSet
metadata:
labels:
kustomize.toolkit.fluxcd.io/name: flux-system
kustomize.toolkit.fluxcd.io/namespace: flux-system
name: gitopsset-configmaps
namespace: default
spec:
generators:
- list:
elements:
- env: dev
team: dev-team
- env: production
team: ops-team
- env: staging
team: ops-team
templates:
- content:
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ .Element.env }}-info-configmap"
namespace: default
spec:
data:
description: This is a configmap for the {{ .Element.env }} environment
env: "{{ .Element.env }}"
team: "{{ .Element.team }}"
8 changes: 8 additions & 0 deletions gitops-sets/dev-info-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
labels:
templates.weave.works/name: gitopsset-configmaps
templates.weave.works/namespace: default
name: dev-info-configmap
namespace: default
8 changes: 8 additions & 0 deletions gitops-sets/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- config-map-generator.yaml
- dev-info-configmap.yaml
- production-info-configmap.yaml
- staging-info-configmap.yaml
- role.yaml
8 changes: 8 additions & 0 deletions gitops-sets/production-info-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
labels:
templates.weave.works/name: gitopsset-configmaps
templates.weave.works/namespace: default
name: production-info-configmap
namespace: default
62 changes: 62 additions & 0 deletions gitops-sets/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: demo-role
rules:
- apiGroups:
- kustomize.toolkit.fluxcd.io
resources:
- kustomizations
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: demo-role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: demo-role
subjects:
- kind: ServiceAccount
name: gitopssets-controller-manager
namespace: flux-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: configmaps-demo-role
rules:
- apiGroups:
- ""
resources:
- configmaps
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: configmaps-role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: configmaps-demo-role
subjects:
- kind: ServiceAccount
name: gitopssets-controller-manager
namespace: flux-system
8 changes: 8 additions & 0 deletions gitops-sets/staging-info-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
labels:
templates.weave.works/name: gitopsset-configmaps
templates.weave.works/namespace: default
name: staging-info-configmap
namespace: default
21 changes: 21 additions & 0 deletions pages/gitopssets_page.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class GitopsSets:
def __init__(self, page):
self.page = page

def open_gitopssets_page(self):
self.page.get_by_role("link", name="GitOpsSets").click()

def open_gitopssets_details_page(self):
self.page.get_by_role("link", name="gitopsset-configmaps").click()

def open_gitopssets_events_tab(self):
self.page.get_by_role("tab", name="Events").click()

def open_gitopssets_graph_tab(self):
self.page.get_by_role("tab", name="Graph").click()

def open_gitopssets_yaml_tab(self):
self.page.get_by_role("tab", name="Yaml").click()

def back_to_gitopssets_list(self):
self.page.get_by_test_id("link-GitOpsSet").click()
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
import os

from playwright.sync_api import Playwright, sync_playwright, expect
from pages.policies_page import Policies
from pages.application_page import Applications
import pytest


@pytest.mark.usefixtures("login")
class TestPolicies:

@pytest.fixture(autouse=True)
def _obj(self, login):
self.page = login
self.policies_page = Policies(self.page)
self.URL = os.getenv("URL")

def test_open_policies_page(self):
self.policies_page.open_policies_page()
expect(self.page).to_have_url(f"{self.URL}/policies/list")

def test_open_policy_details_page(self):
self.policies_page.open_policy_details_page()
expect(self.page).to_have_url(f"{self.URL}/policy_details/"
f"details?clusterName=management"
f"&id=weave.policies.containers-minimum-replica-count"
f"&name=Containers%20Minimum%20Replica%20Count")


@pytest.mark.usefixtures("login")
class TestApplications:
@pytest.fixture(autouse=True)
Expand All @@ -36,15 +14,16 @@ def _create_obj(self, login):
self.URL = os.getenv("URL")

def test_open_applications_page(self):
self.page.reload()
self.applications_page.open_application_page()
expect(self.page).to_have_url(f"{self.URL}/applications")
expect(self.page.locator("//table")).to_contain_text("violating-podinfo")

def test_open_application_details_page(self):
self.page.reload()
self.applications_page.open_application_details_page()
expect(self.page).to_have_url(f"{self.URL}/kustomization/"
f"details?clusterName=management"
f"&name=violating-podinfo&namespace=default")
"details?clusterName=management"
"&name=violating-podinfo&namespace=default")

def test_open_application_more_info(self):
self.applications_page.open_application_more_info()
Expand All @@ -53,35 +32,35 @@ def test_open_application_more_info(self):
def test_open_application_events_tab(self):
self.applications_page.open_application_events_tab()
expect(self.page).to_have_url(f"{self.URL}/kustomization/"
f"events?clusterName=management"
f"&name=violating-podinfo&namespace=default")
"events?clusterName=management"
"&name=violating-podinfo&namespace=default")

def test_open_application_graph_tab(self):
self.applications_page.open_application_graph_tab()
expect(self.page).to_have_url(f"{self.URL}/kustomization/"
f"graph?clusterName=management"
f"&name=violating-podinfo&namespace=default")
"graph?clusterName=management"
"&name=violating-podinfo&namespace=default")

def test_open_application_dependencies_tab(self):
self.applications_page.open_application_dependencies_tab()
expect(self.page).to_have_url(f"{self.URL}/kustomization/"
f"dependencies?clusterName=management"
f"&name=violating-podinfo&namespace=default")
"dependencies?clusterName=management"
"&name=violating-podinfo&namespace=default")
expect(self.page.get_by_text("What are dependencies for?")).to_be_visible()

def test_open_application_yaml(self):
self.applications_page.open_application_yaml_tab()
expect (self.page).to_have_url (f"{self.URL}/kustomization/"
f"yaml?clusterName=management"
f"&name=violating-podinfo&namespace=default")
expect (self.page).to_have_url(f"{self.URL}/kustomization/"
"yaml?clusterName=management"
"&name=violating-podinfo&namespace=default")
expect(self.page.get_by_text("kubectl get kustomization violating-podinfo -n default -o yaml")).to_be_visible()

# page.pause()
def test_open_application_violations_page(self):
self.applications_page.open_application_violations_tab()
expect(self.page).to_have_url(f"{self.URL}/kustomization/"
f"violations?clusterName=management"
f"&name=violating-podinfo&namespace=default")
"violations?clusterName=management"
"&name=violating-podinfo&namespace=default")

def test_open_application_violations_details(self):
self.applications_page.open_application_violations_details()
Expand All @@ -97,8 +76,8 @@ def test_open_policy_details_from_app_violations_details_page(self):
def test_open_policy_violations_page(self):
self.applications_page.open_policy_violations_page()
expect(self.page).to_have_url(f"{self.URL}/policy_details/violations?clusterName=management"
f"&id=weave.policies.container-image-pull-policy"
f"&name=Container%20Image%20Pull%20Policy")
"&id=weave.policies.container-image-pull-policy"
"&name=Container%20Image%20Pull%20Policy")

def test_open_policy_violations_details_page(self):
self.applications_page.open_policy_violations_details_page()
Expand Down
52 changes: 52 additions & 0 deletions test_weave_gitops_enterprise/test_gitopssets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os

from playwright.sync_api import Playwright, sync_playwright, expect
from pages.gitopssets_page import GitopsSets
import pytest


@pytest.mark.usefixtures("login")
class TestGitopsSets:
@pytest.fixture(autouse=True)
def _create_obj(self, login):
self.page = login
self.gitopssets_page = GitopsSets(self.page)
self.URL = os.getenv("URL")

def test_open_gitopssets_page(self):
self.gitopssets_page.open_gitopssets_page()
expect(self.page).to_have_url(f"{self.URL}/gitopssets")

def test_open_gitopssets_details_page(self):
self.gitopssets_page.open_gitopssets_details_page()
expect(self.page).to_have_url(f"{self.URL}/gitopssets/object/details?"
"clusterName=management"
"&name=gitopsset-configmaps"
"&namespace=default")

def test_open_gitopssets_events_tab(self):
self.gitopssets_page.open_gitopssets_events_tab()
expect(self.page).to_have_url(f"{self.URL}/gitopssets/object/events?"
"clusterName=management"
"&name=gitopsset-configmaps"
"&namespace=default")

def test_open_gitopssets_graph_tab(self):
self.gitopssets_page.open_gitopssets_graph_tab()
expect(self.page).to_have_url(f"{self.URL}/gitopssets/object/graph?"
"clusterName=management"
"&name=gitopsset-configmaps"
"&namespace=default")

def test_open_gitopssets_yaml_tab(self):
self.gitopssets_page.open_gitopssets_yaml_tab()
expect(self.page).to_have_url(f"{self.URL}/gitopssets/object/yaml?"
"clusterName=management"
"&name=gitopsset-configmaps"
"&namespace=default")
expect(self.page.get_by_text("kubectl get gitopsset gitopsset-configmaps -n default -o yaml")).to_be_visible()

def test_back_to_gitopssets_list(self):
self.gitopssets_page.back_to_gitopssets_list()
expect(self.page).to_have_url(f"{self.URL}/gitopssets")
expect(self.page.locator("tbody")).to_contain_text("gitopsset-configmaps")
26 changes: 26 additions & 0 deletions test_weave_gitops_enterprise/test_policies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

from playwright.sync_api import Playwright, sync_playwright, expect
from pages.policies_page import Policies
import pytest


@pytest.mark.usefixtures("login")
class TestPolicies:

@pytest.fixture(autouse=True)
def _obj(self, login):
self.page = login
self.policies_page = Policies(self.page)
self.URL = os.getenv("URL")

def test_open_policies_page(self):
self.policies_page.open_policies_page()
expect(self.page).to_have_url(f"{self.URL}/policies/list")

def test_open_policy_details_page(self):
self.policies_page.open_policy_details_page()
expect(self.page).to_have_url(f"{self.URL}/policy_details/"
"details?clusterName=management"
"&id=weave.policies.containers-minimum-replica-count"
"&name=Containers%20Minimum%20Replica%20Count")
15 changes: 15 additions & 0 deletions utils/data/gitops-sets-kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: gitopsset-configmaps
namespace: default
spec:
interval: 10m
targetNamespace: default
sourceRef:
kind: GitRepository
name: flux-system
namespace: flux-system
path: ./gitops-sets
prune: true
timeout: 1m

0 comments on commit 05bfd26

Please sign in to comment.