Skip to content

Commit

Permalink
test: add tests for checking build status before deleting envs
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon committed Apr 4, 2024
1 parent 78cc6fe commit 5fbca51
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/tasks/api/get-latest-deployment-source.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
query: '{{ lookup("template", "./get-latest-deployment-source.gql") }}'
register: apiresponse

- name: "{{ testname }} - POST api trigger bulk deployment for environments to {{ graphql_url }}"
- name: "{{ testname }} - POST api check response {{ graphql_url }}"
debug:
msg: "api response: {{ apiresponse.json }}"

Expand All @@ -49,6 +49,6 @@
retries: 60
delay: 10

- name: "{{ testname }} - POST api trigger bulk deployment for environments to {{ graphql_url }}"
- name: "{{ testname }} - POST api check response {{ graphql_url }}"
debug:
msg: "api response: {{ apiresponse.json }}"
19 changes: 19 additions & 0 deletions tests/tasks/api/get-latest-deployment-status.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
query environmentByKubernetesNamespaceName {
environmentByKubernetesNamespaceName(
kubernetesNamespaceName: "{{ namespace }}"
){
deployments(limit: 1){
id
name
status
bulkId
bulkName
priority
started
created
completed
sourceUser
sourceType
}
}
}
53 changes: 53 additions & 0 deletions tests/tasks/api/get-latest-deployment-status.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
- name: "{{ testname }} - Verify that status are correct"
block:
- ansible.builtin.include_tasks: admin-token.yaml
- name: "{{ testname }} - POST api check latest deployment {{ graphql_url }}"
uri:
url: "{{ graphql_url }}"
method: POST
headers:
Authorization: "Bearer {{ admin_token }}"
body_format: json
body:
query: '{{ lookup("template", "./get-latest-deployment-status.gql") }}'
register: apiresponse
until:
- apiresponse.json.data.environmentByKubernetesNamespaceName.deployments[0].status is defined
retries: 30
delay: 10

- ansible.builtin.include_tasks: admin-token.yaml
- name: "{{ testname }} - POST api check latest deployment {{ graphql_url }}"
uri:
url: "{{ graphql_url }}"
method: POST
headers:
Authorization: "Bearer {{ admin_token }}"
body_format: json
body:
query: '{{ lookup("template", "./get-latest-deployment-status.gql") }}'
register: apiresponse

- name: "{{ testname }} - POST api check response {{ graphql_url }}"
debug:
msg: "api response: {{ apiresponse.json }}"

- ansible.builtin.include_tasks: admin-token.yaml
- name: "{{ testname }} - POST api check latest deployment status are correct {{ graphql_url }}"
uri:
url: "{{ graphql_url }}"
method: POST
headers:
Authorization: "Bearer {{ admin_token }}"
body_format: json
body:
query: '{{ lookup("template", "./get-latest-deployment-status.gql") }}'
register: apiresponse
until:
- apiresponse.json.data.environmentByKubernetesNamespaceName.deployments[0].status == buildStatus
retries: 60
delay: 10

- name: "{{ testname }} - POST api check response {{ graphql_url }}"
debug:
msg: "api response: {{ apiresponse.json }}"
9 changes: 9 additions & 0 deletions tests/tests/github/branch-picky.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
project: "{{ project }}"
url: "{{ check_url }}"

- name: "{{ testname }} - api check deployment status"
hosts: localhost
serial: 1
vars:
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
buildStatus: "complete"
tasks:
- ansible.builtin.include_tasks: ../../tasks/api/get-latest-deployment-status.yaml

- name: "{{ testname }} - webhook github delete push"
hosts: localhost
serial: 1
Expand Down
9 changes: 9 additions & 0 deletions tests/tests/github/branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@
project: "{{ project }}"
url: "{{ check_url }}"

- name: "{{ testname }} - api check deployment status"
hosts: localhost
serial: 1
vars:
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
buildStatus: "complete"
tasks:
- ansible.builtin.include_tasks: ../../tasks/api/get-latest-deployment-status.yaml

- name: "{{ testname }} - webhook github delete push"
hosts: localhost
serial: 1
Expand Down
9 changes: 9 additions & 0 deletions tests/tests/gitlab/branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@
project: "{{ project }}"
url: "{{ check_url }}"

- name: "{{ testname }} - api check deployment status"
hosts: localhost
serial: 1
vars:
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
buildStatus: "complete"
tasks:
- ansible.builtin.include_tasks: ../../tasks/api/get-latest-deployment-status.yaml

- name: "{{ testname }} - webhook gitlab delete push"
hosts: localhost
serial: 1
Expand Down
9 changes: 9 additions & 0 deletions tests/tests/nginx/nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@
tasks:
- ansible.builtin.include_tasks: ../../tasks/api/get-latest-deployment-source.yaml

- name: "{{ testname }} - api check deployment status"
hosts: localhost
serial: 1
vars:
namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}"
buildStatus: "complete"
tasks:
- ansible.builtin.include_tasks: ../../tasks/api/get-latest-deployment-status.yaml

- name: "{{ testname }} - api deleteEnvironment on {{ project }}, which should remove all resources"
hosts: localhost
serial: 1
Expand Down

0 comments on commit 5fbca51

Please sign in to comment.