Skip to content

Commit

Permalink
cloudwatchlogs: Condense cloudwatch tests (ansible-collections#1395)
Browse files Browse the repository at this point in the history
cloudwatchlogs: Condense cloudwatch tests

SUMMARY

Merging tests for cloudwatchlogs and cloudwatchlogs_log_group into combined suite cloudwatchlogs.
There are 2 test suites in community.aws with substantially overlapping functionality - cloudwatchlogs and cloudwatch_log_group.
The cloudwatchlogs runs for changes to the cloudwatchlogs_log_group and cloudwatchlogs_log_group_metric_filter modules, and the cloudwatch_log_group only runs for cloudwatchlogs_log_group_info.
Merging the 2 test suites to create a combined suite for testing the overlapping functionalities could be a good idea.

ISSUE TYPE


Feature Pull Request

COMPONENT NAME


cloudwatchlogs
cloudwatchlogs_log_group

Reviewed-by: Mike Graves <[email protected]>
Reviewed-by: Jill R <None>
  • Loading branch information
mandar242 authored Aug 11, 2022
1 parent e265ece commit 9660de0
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 334 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- cloudwatchlogs_log_group - Condensed integration test suites `cloudwatchlogs` and `cloudwatchlogs_log_group` into combined suite `cloudwatchlogs` (https://github.com/ansible-collections/community.aws/pull/1395).
- cloudwatchlogs - This combined integration test suite covers tests for `cloudwatchlogs_log_group`, `cloudwatchlogs_log_group_info`, and `cloudwatchlogs_log_group_metric_filter` (https://github.com/ansible-collections/community.aws/pull/1395).
1 change: 1 addition & 0 deletions tests/integration/targets/cloudwatchlogs/aliases
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cloud/aws

cloudwatchlogs_log_group
cloudwatchlogs_log_group_info
cloudwatchlogs_log_group_metric_filter
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
---
# Tests for changes to the cloudwatchlogs_log_group and cloudwatchlogs_log_group_metric_filter

- block:

- name: create cloudwatch log group for integration test
cloudwatchlogs_log_group:
state: present
log_group_name: '{{ log_group_name }}'
retention: 1

- name: check_mode set metric filter on '{{ log_group_name }}'
cloudwatchlogs_log_group_metric_filter:
log_group_name: '{{ log_group_name }}'
filter_name: '{{ filter_name }}'
filter_pattern: '{ ($.value = *) && ($.hostname = "box")}'
state: present
metric_transformation:
metric_name: box_free_space
metric_namespace: fluentd_metrics
metric_value: "$.value"
check_mode: yes
register: out

- name: check_mode state must be changed
assert:
that:
- out is changed
- out.metric_filters | count == 1

- name: set metric filter on '{{ log_group_name }}'
cloudwatchlogs_log_group_metric_filter:
log_group_name: '{{ log_group_name }}'
filter_name: '{{ filter_name }}'
filter_pattern: '{ ($.value = *) && ($.hostname = "box")}'
state: present
metric_transformation:
metric_name: box_free_space
metric_namespace: fluentd_metrics
metric_value: "$.value"
register: out

- name: create metric filter
assert:
that:
- out is changed
- out.metric_filters | count == 1

- name: re-set metric filter on '{{ log_group_name }}'
cloudwatchlogs_log_group_metric_filter:
log_group_name: '{{ log_group_name }}'
filter_name: '{{ filter_name }}'
filter_pattern: '{ ($.value = *) && ($.hostname = "box")}'
state: present
metric_transformation:
metric_name: box_free_space
metric_namespace: fluentd_metrics
metric_value: "$.value"
register: out

- name: metric filter must not change
assert:
that:
- out is not changed

- name: update metric transformation on '{{ log_group_name }}'
cloudwatchlogs_log_group_metric_filter:
log_group_name: '{{ log_group_name }}'
filter_name: '{{ filter_name }}'
filter_pattern: '{ ($.value = *) && ($.hostname = "box")}'
state: present
metric_transformation:
metric_name: box_free_space
metric_namespace: made_with_ansible
metric_value: "$.value"
default_value: 3.1415
register: out

- name: update metric filter
assert:
that:
- out is changed
- out.metric_filters[0].metric_namespace == "made_with_ansible"
- out.metric_filters[0].default_value == 3.1415

- name: update filter_pattern on '{{ log_group_name }}'
cloudwatchlogs_log_group_metric_filter:
log_group_name: '{{ log_group_name }}'
filter_name: '{{ filter_name }}'
filter_pattern: '{ ($.value = *) && ($.hostname = "ansible")}'
state: present
metric_transformation:
metric_name: box_free_space
metric_namespace: made_with_ansible
metric_value: "$.value"
register: out

- name: update metric filter
assert:
that:
- out is changed
- out.metric_filters[0].metric_namespace == "made_with_ansible"

- name: checkmode delete metric filter on '{{ log_group_name }}'
cloudwatchlogs_log_group_metric_filter:
log_group_name: '{{ log_group_name }}'
filter_name: '{{ filter_name }}'
state: absent
check_mode: yes
register: out

- name: check_mode state must be changed
assert:
that:
- out is changed

- name: delete metric filter on '{{ log_group_name }}'
cloudwatchlogs_log_group_metric_filter:
log_group_name: '{{ log_group_name }}'
filter_name: '{{ filter_name }}'
state: absent
register: out

- name: delete metric filter
assert:
that:
- out is changed

- name: delete metric filter on '{{ log_group_name }}' which does not exist
cloudwatchlogs_log_group_metric_filter:
log_group_name: '{{ log_group_name }}'
filter_name: '{{ filter_name }}'
state: absent
register: out

- name: delete metric filter
assert:
that:
- out is not changed

always:
- name: delete metric filter
cloudwatchlogs_log_group_metric_filter:
log_group_name: '{{ log_group_name }}'
filter_name: '{{ filter_name }}'
state: absent

- name: delete cloudwatch log group for integration test
cloudwatchlogs_log_group:
state: absent
log_group_name: '{{ log_group_name }}'
ignore_errors: true
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
# Tests relating to create/delete and set tags on cloudwatchlogs_log_group

- name: Tests relating to setting tags on cloudwatchlogs_log_group
vars:
first_tags:
Expand Down Expand Up @@ -34,6 +37,115 @@
log_group_name: '{{ log_group_name }}'
block:

- name: create cloudwatch log group for integration test (check_mode)
cloudwatchlogs_log_group:
state: present
log_group_name: '{{ log_group_name }}'
retention: 1
tags:
CamelCase: Value
snake_case: value
check_mode: true
register: result

- assert:
that:
- result is changed
- '"log_groups" not in result'
- '"logs:CreateLogGroup" not in result.resource_actions'

- name: create cloudwatch log group for integration test
cloudwatchlogs_log_group:
state: present
log_group_name: '{{ log_group_name }}'
retention: 1
tags:
CamelCase: Value
snake_case: value
register: result

- assert:
that:
- result is changed
- '"log_groups" in result'
- result.log_groups | length == 1
- '"log_group_name" in log_group'
- '"creation_time" in log_group'
- '"retention_in_days" in log_group'
- '"metric_filter_count" in log_group'
- '"arn" in log_group'
- '"stored_bytes" in log_group'
# - '"kms_key_id" in log_group'
# pre-4.0.0 upgrade compatability
- '"log_group_name" in result'
- '"creation_time" in result'
- '"retention_in_days" in result'
- '"metric_filter_count" in result'
- '"arn" in result'
- '"stored_bytes" in result'
# - '"kms_key_id" in result'
- '"CamelCase" in log_group.tags'
- '"snake_case" in log_group.tags'
vars:
log_group: '{{ result.log_groups[0] }}'

- name: create cloudwatch log group for integration test (check_mode - idempotent)
cloudwatchlogs_log_group:
state: present
log_group_name: '{{ log_group_name }}'
retention: 1
check_mode: true
register: result

- assert:
that:
- result is not changed
- '"log_groups" in result'
- result.log_groups | length == 1

- name: create cloudwatch log group for integration test (idempotent)
cloudwatchlogs_log_group:
state: present
log_group_name: '{{ log_group_name }}'
retention: 1
register: result

- assert:
that:
- result is not changed
- '"log_groups" in result'
- result.log_groups | length == 1
vars:
log_group: '{{ result.log_groups[0] }}'

- name: describe all log groups
cloudwatchlogs_log_group_info: {}
register: result

- assert:
that:
- '"log_groups" in result'
- result.log_groups | length >= 1

- name: describe log group
cloudwatchlogs_log_group_info:
log_group_name: '{{ log_group_name }}'
register: result

- assert:
that:
- '"log_groups" in result'
- result.log_groups | length == 1
- '"log_group_name" in log_group'
- '"creation_time" in log_group'
- '"retention_in_days" in log_group'
- '"metric_filter_count" in log_group'
- '"arn" in log_group'
- '"stored_bytes" in log_group'
# - '"kms_key_id" in log_group'
- '"tags" in log_group'
vars:
log_group: '{{ result.log_groups[0] }}'
- name: test adding tags to cloudwatchlogs_log_group (check_mode)
cloudwatchlogs_log_group:
tags: '{{ first_tags }}'
Expand Down Expand Up @@ -267,3 +379,65 @@
that:
- update_result is not changed
- update_result.log_groups[0].tags == {}

- name: delete cloudwatch log group for integration test (check_mode)
cloudwatchlogs_log_group:
state: absent
log_group_name: '{{ log_group_name }}'
check_mode: true
register: result

- assert:
that:
- result is changed
- '"logs:DeleteLogGroup" not in result.resource_actions'

- name: delete cloudwatch log group for integration test
cloudwatchlogs_log_group:
state: absent
log_group_name: '{{ log_group_name }}'
register: result

- assert:
that:
- result is changed

- name: delete cloudwatch log group for integration test (check_mode - idempotent)
cloudwatchlogs_log_group:
state: absent
log_group_name: '{{ log_group_name }}'
check_mode: true
register: result

- assert:
that:
- result is not changed
- '"logs:DeleteLogGroup" not in result.resource_actions'

- name: delete cloudwatch log group for integration test (idempotent)
cloudwatchlogs_log_group:
state: absent
log_group_name: '{{ log_group_name }}'
register: result

- assert:
that:
- result is not changed

- name: describe missing log group
cloudwatchlogs_log_group_info:
log_group_name: '{{ log_group_name }}'
register: result

- assert:
that:
- '"log_groups" in result'
- result.log_groups | length == 0

always:

- name: delete cloudwatch log group for integration test
cloudwatchlogs_log_group:
state: absent
log_group_name: '{{ log_group_name }}'
ignore_errors: true
Loading

0 comments on commit 9660de0

Please sign in to comment.