-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Include unit test for function "filters_are_equal"
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
Showing
3 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
tests/unit/plugins/modules/test_s3_lifecycle_filters_are_equal.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |