Skip to content

Commit

Permalink
1. Include unit test for function "filters_are_equal"
Browse files Browse the repository at this point in the history
2. Included a changelog minor change fragment file.
3. Enclosed types within double quotes.
  • Loading branch information
JavidMinadathAlimohi committed Dec 23, 2024
1 parent 6e5bf68 commit 7c50572
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/2205-support-minmax-s3lifecycle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- s3_lifecycle - Support for min and max object size when applying the filter rules.
4 changes: 2 additions & 2 deletions plugins/modules/s3_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ def main():
expiration_days=dict(type="int"),
expiration_date=dict(),
expire_object_delete_marker=dict(type="bool"),
maximum_object_size=dict(type=int),
minimum_object_size=dict(type=int),
maximum_object_size=dict(type="int"),
minimum_object_size=dict(type="int"),
noncurrent_version_expiration_days=dict(type="int"),
noncurrent_version_keep_newer=dict(type="int"),
noncurrent_version_storage_class=dict(default="glacier", type="str", choices=s3_storage_class),
Expand Down
108 changes: 108 additions & 0 deletions tests/unit/plugins/modules/test_s3_lifecycle_filters_are_equal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# -*- coding: utf-8 -*-

# Copyright: (c) 2023, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

import pytest

from ansible_collections.community.aws.plugins.modules.s3_lifecycle import filters_are_equal

def test_filters_are_equal():
# Test case 1: Both filters are identical
filter1 = {
"And": {
"Prefix": "nested/",
"ObjectSizeGreaterThan": 150,
"ObjectSizeLessThan": 180,
},
}
filter2 = filter1.copy()
assert filters_are_equal(filter1, filter2) is True

# Test case 2: One filter is None
filter1 = None
filter2 = {
"Prefix": "test/"
}
assert filters_are_equal(filter1, filter2) is False

# Test case 3: One filter is empty
filter1 = {}
filter2 = {
"ObjectSizeGreaterThan": 100,
}
assert filters_are_equal(filter1, filter2) is False

# Test case 4: Filters differ in a single key
filter1 = {
"ObjectSizeGreaterThan": 100,
}
filter2 = {
"ObjectSizeGreaterThan": 200, # Different value
}
assert filters_are_equal(filter1, filter2) is False

# Test case 5: Filters with missing `And` key in one filter
filter1 = {
"Prefix": "test/",
}
filter2 = {
"And": {
"Prefix": "nested/",
"ObjectSizeGreaterThan": 100,
},
}
assert filters_are_equal(filter1, filter2) is False

# Test case 6: Filters with nested `And` keys matching
filter1 = {
"And": {
"Prefix": "nested/",
"ObjectSizeGreaterThan": 150,
},
}
filter2 = {
"And": {
"Prefix": "nested/",
"ObjectSizeGreaterThan": 150,
},
}
assert filters_are_equal(filter1, filter2) is True

# Test case 7: Filters with nested `And` keys differing
filter1 = {
"And": {
"Prefix": "test/",
"ObjectSizeGreaterThan": 150,
},
}
filter2 = {
"And": {
"Prefix": "nested/", # Different key/value
"ObjectSizeLessThan": 150,
},
}
assert filters_are_equal(filter1, filter2) is False

# Test case 8: Both filters are None
filter1 = None
filter2 = None
assert filters_are_equal(filter1, filter2) is False

# Test case 9: Filters with different `Prefix` values
filter1 = {
"Prefix": "test/"
}
filter2 = {
"Prefix": "different/"
}
assert filters_are_equal(filter1, filter2) is False

# Test case 10: Filters with empty strings for `Prefix`
filter1 = {
"Prefix": ""
}
filter2 = {
"Prefix": ""
}
assert filters_are_equal(filter1, filter2) is True

0 comments on commit 7c50572

Please sign in to comment.