| 1 |
- name: Wrap API Gateway tests with credentials by default |
| 2 |
module_defaults: |
| 3 |
group/aws: |
| 4 |
access_key: '{{ aws_access_key }}' |
| 5 |
secret_key: '{{ aws_secret_key }}' |
| 6 |
session_token: '{{ security_token | default(omit) }}' |
| 7 |
region: '{{ aws_region }}' |
| 8 |
|
| 9 |
block: |
| 10 |
|
| 11 |
# ====================== testing failure cases: ================================== |
| 12 |
|
| 13 |
- name: test with no parameters |
| 14 |
api_gateway: |
| 15 |
register: result |
| 16 |
ignore_errors: true |
| 17 |
|
| 18 |
- name: assert failure when called with no parameters |
| 19 |
assert: |
| 20 |
that: |
| 21 |
- 'result.failed' |
| 22 |
- '"no swagger info provided" in result.msg' |
| 23 |
|
| 24 |
- name: test for disallowing multiple swagger sources |
| 25 |
api_gateway: |
| 26 |
api_id: 'fake-api-doesnt-exist' |
| 27 |
swagger_file: foo.yml |
| 28 |
swagger_text: "this is not really an API" |
| 29 |
register: result |
| 30 |
ignore_errors: true |
| 31 |
|
| 32 |
- name: assert failure when called with with minimal parameters but no region |
| 33 |
assert: |
| 34 |
that: |
| 35 |
- 'result.failed' |
| 36 |
- 'result.msg.startswith("parameters are mutually exclusive")' |
| 37 |
|
| 38 |
|
| 39 |
# ====================== regular testing: =================================== |
| 40 |
|
| 41 |
- name: build API file |
| 42 |
template: |
| 43 |
src: minimal-swagger-api.yml.j2 |
| 44 |
dest: "{{output_dir}}/minimal-swagger-api.yml" |
| 45 |
vars: |
| 46 |
api_name: "{{ resource_prefix }}-minimal" |
| 47 |
|
| 48 |
- name: deploy new API |
| 49 |
api_gateway: |
| 50 |
api_file: "{{output_dir}}/minimal-swagger-api.yml" |
| 51 |
stage: "minimal" |
| 52 |
endpoint_type: 'REGIONAL' |
| 53 |
state: present |
| 54 |
register: create_result |
| 55 |
|
| 56 |
- name: assert deploy new API worked |
| 57 |
assert: |
| 58 |
that: |
| 59 |
- 'create_result.changed == True' |
| 60 |
- 'create_result.failed == False' |
| 61 |
- 'create_result.deploy_response.description == "Automatic deployment by Ansible."' |
| 62 |
- 'create_result.configure_response.id == create_result.api_id' |
| 63 |
- 'create_result.configure_response.endpoint_configuration.types.0 == "REGIONAL"' |
| 64 |
|
| 65 |
- name: check if API endpoint works |
| 66 |
uri: |
| 67 |
url: "https://{{create_result.api_id}}.execute-api.{{aws_region}}.amazonaws.com/minimal" |
| 68 |
retries: 10 |
| 69 |
delay: 5 |
| 70 |
until: uri_result is successful |
| 71 |
register: uri_result |
| 72 |
|
| 73 |
- name: assert API works success |
| 74 |
assert: |
| 75 |
that: |
| 76 |
- 'uri_result.status == 200' |
| 77 |
|
| 78 |
- name: check if nonexistent endpoint causes error |
| 79 |
uri: |
| 80 |
url: "https://{{create_result.api_id}}.execute-api.{{aws_region}}.amazonaws.com/nominal" |
| 81 |
register: bad_uri_result |
| 82 |
ignore_errors: true |
| 83 |
|
| 84 |
- name: assert |
| 85 |
assert: |
| 86 |
that: |
| 87 |
- bad_uri_result is failed |
| 88 |
|
| 89 |
- name: Update API to test params effect |
| 90 |
api_gateway: |
| 91 |
api_id: '{{create_result.api_id}}' |
| 92 |
api_file: "{{output_dir}}/minimal-swagger-api.yml" |
| 93 |
cache_enabled: true |
| 94 |
cache_size: '1.6' |
| 95 |
tracing_enabled: true |
| 96 |
state: present |
| 97 |
register: update_result |
| 98 |
|
| 99 |
- name: assert update result |
| 100 |
assert: |
| 101 |
that: |
| 102 |
- update_result is changed |
| 103 |
|
| 104 |
# ==== additional create/delete tests ==== |
| 105 |
|
| 106 |
- name: deploy first API |
| 107 |
api_gateway: |
| 108 |
api_file: "{{output_dir}}/minimal-swagger-api.yml" |
| 109 |
stage: "minimal" |
| 110 |
cache_enabled: false |
| 111 |
state: present |
| 112 |
register: create_result_1 |
| 113 |
|
| 114 |
- name: deploy second API rapidly after first |
| 115 |
api_gateway: |
| 116 |
api_file: "{{output_dir}}/minimal-swagger-api.yml" |
| 117 |
stage: "minimal" |
| 118 |
state: present |
| 119 |
register: create_result_2 |
| 120 |
|
| 121 |
- name: assert both APIs deployed successfully |
| 122 |
assert: |
| 123 |
that: |
| 124 |
- 'create_result_1.changed == True' |
| 125 |
- 'create_result_2.changed == True' |
| 126 |
- '"api_id" in create_result_1' |
| 127 |
- '"api_id" in create_result_1' |
| 128 |
- 'create_result_1.configure_response.endpoint_configuration.types.0 == "EDGE"' |
| 129 |
|
| 130 |
- name: destroy first API |
| 131 |
api_gateway: |
| 132 |
state: absent |
| 133 |
api_id: '{{create_result_1.api_id}}' |
| 134 |
register: destroy_result_1 |
| 135 |
|
| 136 |
- name: destroy second API rapidly after first |
| 137 |
api_gateway: |
| 138 |
state: absent |
| 139 |
api_id: '{{create_result_2.api_id}}' |
| 140 |
register: destroy_result_2 |
| 141 |
|
| 142 |
- name: assert both APIs deployed successfully |
| 143 |
assert: |
| 144 |
that: |
| 145 |
- destroy_result_1 is changed |
| 146 |
- destroy_result_2 is changed |
| 147 |
|
| 148 |
# ==== test create/delete using lookup=tag ==== |
| 149 |
- include_tasks: lookup.yml |
| 150 |
|
| 151 |
# ==== Tagging ==== |
| 152 |
- include_tasks: tagging.yml |
| 153 |
|
| 154 |
# ================= end testing ==================================== |
| 155 |
|
| 156 |
always: |
| 157 |
|
| 158 |
- name: Ensure cleanup of API deploy |
| 159 |
api_gateway: |
| 160 |
state: absent |
| 161 |
api_id: '{{create_result.api_id}}' |
| 162 |
ignore_errors: true |
| 163 |
|
| 164 |
- name: Ensure cleanup of API deploy 1 |
| 165 |
api_gateway: |
| 166 |
state: absent |
| 167 |
api_id: '{{create_result_1.api_id}}' |
| 168 |
ignore_errors: true |
| 169 |
|
| 170 |
- name: Ensure cleanup of API deploy 2 |
| 171 |
api_gateway: |
| 172 |
state: absent |
| 173 |
api_id: '{{create_result_2.api_id}}' |
| 174 |
ignore_errors: true |