Skip to content

Commit

Permalink
Move tests to using module_defaults (ansible-collections#368)
Browse files Browse the repository at this point in the history
* Bulk migration to module_defaults
* Tests for missing creds/region
* Move dms_identifier and dms_sg_identifier into defaults

This commit was initially merged in https://github.com/ansible-collections/community.aws
See: ansible-collections/community.aws@365b6ef
  • Loading branch information
tremble authored and alinabuzachis committed Oct 23, 2024
1 parent fae4a03 commit b7c19c9
Showing 1 changed file with 18 additions and 27 deletions.
45 changes: 18 additions & 27 deletions tests/integration/targets/ec2_transit_gateway/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
---
# tasks file for test_ec2_transit_gateway
- name: 'ec2_transit_gateway integration tests'
collections:
- amazon.aws
module_defaults:
group/aws:
aws_access_key: '{{ aws_access_key }}'
aws_secret_key: '{{ aws_secret_key }}'
security_token: '{{ security_token | default(omit) }}'
region: '{{ aws_region }}'
block:

- name: generate unique value for testing
set_fact:
tgw_description: "{{ resource_prefix }}-tgw"

- name: set up aws connection info
set_fact:
aws_connection_info: &aws_connection_info
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
security_token: "{{ security_token }}"
region: "{{ aws_region }}"
no_log: yes

- name: generate unique value for testing
set_fact:
tgw_description: "{{ resource_prefix }}-tgw"

- block:
- name: test create transit gateway without permissions
ec2_transit_gateway:
aws_access_key: '{{ omit }}'
aws_secret_key: '{{ omit }}'
security_token: '{{ omit }}'
description: "{{ tgw_description }}"
region: "{{ aws_region }}"
register: result
ignore_errors: yes

Expand All @@ -31,6 +32,7 @@
- name: test create transit gateway without region
ec2_transit_gateway:
description: "{{ tgw_description }}"
region: '{{ omit }}'
register: result
ignore_errors: yes

Expand All @@ -43,7 +45,6 @@
- name: test create transit gateway without tags
ec2_transit_gateway:
description: "{{ tgw_description }}"
<<: *aws_connection_info
register: create_result
- name: assert changed is True
assert:
Expand All @@ -55,7 +56,6 @@
description: "{{ tgw_description }}"
tags:
Name: Ansible Test TGW
<<: *aws_connection_info
register: result
- name: assert changed is True
assert:
Expand All @@ -70,7 +70,6 @@
purge_tags: False
tags:
status: ok to delete
<<: *aws_connection_info
register: result
- name: assert changed is True and have 2 tags
assert:
Expand All @@ -85,7 +84,6 @@
purge_tags: True
tags:
status: ok to delete
<<: *aws_connection_info
register: result
- name: assert changed is True and TGW tag is absent
assert:
Expand All @@ -100,7 +98,6 @@
purge_tags: True
tags:
status: ok to delete
<<: *aws_connection_info
register: result
- name: assert changed is False
assert:
Expand All @@ -110,7 +107,6 @@
# ==== Combine ec2_transit_gateway_info ======================
- name: test success with no parameters
ec2_transit_gateway_info:
<<: *aws_connection_info
register: result
- name: assert success with no parameters
assert:
Expand All @@ -122,7 +118,6 @@
ec2_transit_gateway_info:
filters:
transit-gateway-id: "{{ create_result.transit_gateway.transit_gateway_id }}"
<<: *aws_connection_info
register: result
- name: assert success with transit_gateway_id filter
assert:
Expand All @@ -134,7 +129,6 @@
ec2_transit_gateway_info:
filters:
transit-gateway-id: tgw-00000011111111122
<<: *aws_connection_info
register: result
- name: assert success with transit_gateway_id filter
assert:
Expand All @@ -145,7 +139,6 @@
- name: test NotFound exception caught and returned empty result set
ec2_transit_gateway_info:
transit_gateway_id: tgw-00000011111111122
<<: *aws_connection_info
register: result
- name: assert success with transit_gateway_id filter
assert:
Expand All @@ -158,7 +151,6 @@
filters:
options.dns-support: enable
options.vpn-ecmp-support: enable
<<: *aws_connection_info
register: result
- name: assert success with transit_gateway_id filter
assert:
Expand All @@ -171,5 +163,4 @@
ec2_transit_gateway:
description: "{{ tgw_description }}"
state: absent
<<: *aws_connection_info
ignore_errors: yes

0 comments on commit b7c19c9

Please sign in to comment.