Skip to content

Commit 6a02542

Browse files
committed
test: add ansible test for api-routes
1 parent 89434c0 commit 6a02542

File tree

8 files changed

+225
-2
lines changed

8 files changed

+225
-2
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pipeline {
121121
parallel {
122122
stage ('1: run first test suite') {
123123
steps {
124-
sh script: "make -j$NPROC k3d/retest TESTS=[api,deploytarget,active-standby-kubernetes,features-kubernetes,features-kubernetes-2,features-variables] BRANCH_NAME=${SAFEBRANCH_NAME}", label: "Running first test suite on k3d cluster"
124+
sh script: "make -j$NPROC k3d/retest TESTS=[api,api-routes,deploytarget,active-standby-kubernetes,features-kubernetes,features-kubernetes-2,features-variables] BRANCH_NAME=${SAFEBRANCH_NAME}", label: "Running first test suite on k3d cluster"
125125
sh script: "pkill -f './local-dev/stern'", label: "Closing off test-suite-1 log after test completion"
126126
}
127127
}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ JWT_VERSION = 6.2.0
462462
STERN_VERSION = v2.6.1
463463
CHART_TESTING_VERSION = v3.11.0
464464
K3D_IMAGE = docker.io/rancher/k3s:v1.31.1-k3s1
465-
TESTS = [nginx,api,features-kubernetes,bulk-deployment,features-kubernetes-2,features-variables,active-standby-kubernetes,tasks,drush,python,gitlab,github,bitbucket,services]
465+
TESTS = [nginx,api,api-routes,features-kubernetes,bulk-deployment,features-kubernetes-2,features-variables,active-standby-kubernetes,tasks,drush,python,gitlab,github,bitbucket,services]
466466
CHARTS_TREEISH = main
467467
CHARTS_REPOSITORY = https://github.com/uselagoon/lagoon-charts.git
468468
#CHARTS_REPOSITORY = ../lagoon-charts

tests/tasks/api/add-api-route.gql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
mutation addRouteToProject {
2+
addRouteToProject(
3+
input: {
4+
project: "{{ project }}"
5+
environment: "{{ branch }}"
6+
domain: "{{ domain }}"
7+
service: "{{ service }}"
8+
}
9+
) {
10+
id
11+
project {
12+
name
13+
}
14+
environment {
15+
name
16+
}
17+
domain
18+
service
19+
updated
20+
created
21+
}
22+
}

tests/tasks/api/add-api-route.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
- name: "{{ testname }} - POST api add route with target environment {{ branch }} on project {{ project }} to {{ graphql_url }}"
2+
block:
3+
- ansible.builtin.include_tasks: admin-token.yaml
4+
- name: "{{ testname }} - POST api add route with target environment {{ branch }} on project {{ project }} to {{ graphql_url }}"
5+
uri:
6+
url: "{{ graphql_url }}"
7+
method: POST
8+
headers:
9+
Authorization: "Bearer {{ admin_token }}"
10+
body_format: json
11+
body:
12+
query: '{{ lookup("template", "./add-api-route.gql") }}'
13+
register: apiresponse
14+
15+
- name: "{{ testname }} - POST api add route with target project {{ project }} to {{ graphql_url }}"
16+
debug:
17+
msg: "api response: {{ apiresponse.json }}"
18+
- fail:
19+
msg: "error adding route to project"
20+
when: apiresponse.json.data.addRouteToProject.domain is not defined
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
mutation updateProject {
2+
updateProject(
3+
input: {
4+
id: {{ project_id }}
5+
patch: {
6+
autogeneratedRoutes: {{ autogenerated_routes }}
7+
}
8+
}
9+
) {
10+
id
11+
}
12+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
- name: "Update project autogeneratedroutes for {{ project }} to openshift {{ openshift }}"
2+
block:
3+
- ansible.builtin.include_tasks: admin-token.yaml
4+
- name: "{{ testname }} - POST api get project by name with target project {{ project }} to {{ graphql_url }}"
5+
uri:
6+
url: "{{ graphql_url }}"
7+
method: POST
8+
headers:
9+
Authorization: "Bearer {{ admin_token }}"
10+
body_format: json
11+
body: '{ "query": "query($project: String!) {projectByName(name:$project){id,name}}", "variables": {"project":"{{ project }}"}}'
12+
register: apiresponse
13+
- name: "{{ testname }} - POST api get project by name with target project {{ project }} and sha {{ sha }} to {{ graphql_url }}"
14+
debug:
15+
msg: "api response: {{ apiresponse.json }}"
16+
- name: "{{ testname }} - save project id as fact"
17+
set_fact:
18+
project_id: "{{ apiresponse.json.data.projectByName.id }}"
19+
- name: "Update project autogeneratedroutes for {{ project }} to openshift {{ openshift }}"
20+
uri:
21+
url: "{{ graphql_url }}"
22+
method: POST
23+
headers:
24+
Authorization: "Bearer {{ admin_token }}"
25+
body_format: json
26+
body:
27+
query: '{{ lookup("template", "./update-project-autogeneratedroutes.gql") }}'
28+
register: apiresponse
29+
- name: "Update project autogeneratedroutes for {{ project }} to openshift {{ openshift }}"
30+
debug:
31+
msg: "api response: {{ apiresponse.json }}"
32+
retries: 10
33+
delay: 30

tests/tests/api-routes.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
- ansible.builtin.import_playbook: features/api-token.yaml
3+
vars:
4+
testname: "API TOKEN"
5+
6+
- ansible.builtin.import_playbook: api/add-project.yaml
7+
vars:
8+
testname: "APIROUTES {{ cluster_type|upper }}"
9+
project: ci-api-routes-{{ cluster_type }}
10+
git_repo_name: nginx.git
11+
git_url: "{{ localgit_url }}/{{ git_repo_name }}"
12+
13+
- ansible.builtin.import_playbook: api-routes/api-routes.yaml
14+
vars:
15+
testname: "APIROUTES {{ cluster_type|upper }}"
16+
git_repo_name: nginx.git
17+
project: ci-api-routes-{{ cluster_type }}
18+
branch: api-route
19+
20+
- ansible.builtin.import_playbook: api/delete-project.yaml
21+
vars:
22+
testname: "APIROUTES {{ cluster_type|upper }}"
23+
project: ci-api-routes-{{ cluster_type }}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
2+
- name: "{{ testname }} - init git, add files, commit, git push"
3+
hosts: localhost
4+
serial: 1
5+
vars:
6+
git_files: "nginx/first/"
7+
tasks:
8+
- ansible.builtin.include_tasks: ../../tasks/git-init.yaml
9+
- ansible.builtin.include_tasks: ../../tasks/git-add-commit-push.yaml
10+
11+
- name: "{{ testname }} - api deployEnvironmentBranch on {{ project }}, which should deploy the first commit"
12+
hosts: localhost
13+
serial: 1
14+
vars:
15+
branch: "{{ branch }}"
16+
project: "{{ project }}"
17+
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
18+
tasks:
19+
- ansible.builtin.include_tasks: ../../tasks/api/deploy-no-sha.yaml
20+
21+
- name: "{{ testname }} - check if {{ project }} is deployed with searching for 'Hello World!' on autogenerated route"
22+
hosts: localhost
23+
serial: 1
24+
vars:
25+
url: "http://nginx.{{ project | regex_replace('_', '-') }}.{{ branch | regex_replace('/', '-') }}.{{ route_suffix }}"
26+
expected_content: "Hello World!"
27+
tasks:
28+
- ansible.builtin.include_tasks: ../../checks/check-url-content.yaml
29+
30+
- name: "{{ testname }} - api add route on {{ project }} environment {{ branch }}"
31+
hosts: localhost
32+
serial: 1
33+
vars:
34+
project: "{{ project }}"
35+
branch: "{{ branch }}"
36+
domain: "api-route.{{ project | regex_replace('_', '-') }}.{{ branch | regex_replace('/', '-') }}.{{ route_suffix | regex_replace(':80', '') }}"
37+
service: "nginx"
38+
tasks:
39+
- ansible.builtin.include_tasks: ../../tasks/api/add-api-route.yaml
40+
41+
- name: "{{ testname }} - api update {{ project }} autogeneratedroutes to disabled"
42+
hosts: localhost
43+
serial: 1
44+
vars:
45+
project: "{{ project }}"
46+
autogenerated_routes: "false"
47+
tasks:
48+
- ansible.builtin.include_tasks: ../../tasks/api/update-project-autogeneratedroutes.yaml
49+
50+
- name: "{{ testname }} - api deployEnvironmentBranch on {{ project }}, which should deploy the first commit"
51+
hosts: localhost
52+
serial: 1
53+
vars:
54+
branch: "{{ branch }}"
55+
project: "{{ project }}"
56+
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
57+
tasks:
58+
- ansible.builtin.include_tasks: ../../tasks/api/deploy-no-sha.yaml
59+
60+
- name: "{{ testname }} - api check deployment source user and type for deploy environment"
61+
hosts: localhost
62+
serial: 1
63+
vars:
64+
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
65+
sourceUser: "[email protected]"
66+
sourceType: "API"
67+
tasks:
68+
- ansible.builtin.include_tasks: ../../tasks/api/get-latest-deployment-source.yaml
69+
70+
- name: "{{ testname }} - check if autogenerated route for ${service}. {{ project }} does not exist anymore after disabling"
71+
hosts: localhost
72+
serial: 1
73+
vars:
74+
url: "http://nginx.{{ project | regex_replace('_', '-') }}.{{ branch | regex_replace('/', '-') }}.{{ route_suffix }}"
75+
expected_returncode: "{{ del_status_code }}"
76+
tasks:
77+
- ansible.builtin.include_tasks: ../../checks/check-url-returncode.yaml
78+
79+
- name: "{{ testname }} - check if {{ project }} is deployed with searching for 'Hello World!'"
80+
hosts: localhost
81+
serial: 1
82+
vars:
83+
url: "http://api-route.{{ project | regex_replace('_', '-') }}.{{ branch | regex_replace('/', '-') }}.{{ route_suffix }}"
84+
expected_content: "Hello World!"
85+
tasks:
86+
- ansible.builtin.include_tasks: ../../checks/check-url-content.yaml
87+
88+
- name: "{{ testname }} - api deleteEnvironment on {{ project }}, which should remove all resources"
89+
hosts: localhost
90+
serial: 1
91+
vars:
92+
project: "{{ project }}"
93+
branch: "{{ branch }}"
94+
tasks:
95+
- ansible.builtin.include_tasks: ../../tasks/api/delete-environment.yaml
96+
97+
- name: "{{ testname }} - api update {{ project }} router pattern to empty"
98+
hosts: localhost
99+
serial: 1
100+
vars:
101+
project: "{{ project }}"
102+
routerpattern: ""
103+
tasks:
104+
- ansible.builtin.include_tasks: ../../tasks/api/update-project-routerpattern.yaml
105+
106+
- name: "{{ testname }} - check if site for ${service}. {{ project }} does not exist anymore"
107+
hosts: localhost
108+
serial: 1
109+
vars:
110+
url: "http://api-route.{{ project | regex_replace('_', '-') }}.{{ branch | regex_replace('/', '-') }}.{{ route_suffix }}"
111+
expected_returncode: "{{ del_status_code }}"
112+
tasks:
113+
- ansible.builtin.include_tasks: ../../checks/check-url-returncode.yaml

0 commit comments

Comments
 (0)