Fixes GcpRequest comparison for boolean parameters

Fixes #402 .
This commit is contained in:
nkakouros 2023-01-22 00:37:58 +01:00 committed by Yusuke Tsutsumi
parent 226ec3dd3f
commit 30c2bbd84e
2 changed files with 34 additions and 3 deletions

View file

@ -362,7 +362,7 @@ class GcpRequest(object):
def _compare_dicts(self, req_dict, resp_dict):
difference = {}
for key in req_dict:
if resp_dict.get(key):
if resp_dict.get(key) is not None:
difference[key] = self._compare_value(req_dict.get(key), resp_dict.get(key))
# Remove all empty values from difference.
@ -408,7 +408,7 @@ class GcpRequest(object):
diff = None
# If a None is found, a difference does not exist.
# Only differing values matter.
if not resp_value:
if resp_value is None:
return None
# Can assume non-None types at this point.
@ -444,7 +444,7 @@ class GcpRequest(object):
# Value1 False, resp_value 'false'
if not req_value and to_text(resp_value) == 'false':
return None
return resp_value
return True
# to_text may throw UnicodeErrors.
# These errors shouldn't crash Ansible and should be hidden.

View file

@ -143,3 +143,34 @@ class GCPRequestDifferenceTestCase(unittest.TestCase):
request2 = GcpRequest(value2)
self.assertNotEquals(request1, request2)
self.assertEqual(request1.difference(request2), difference)
def test_dicts_boolean_with_difference(self):
value1 = {
"foo": True,
"bar": False,
"baz": True,
"qux": False,
}
value2 = {
"foo": True,
"bar": False,
"baz": False,
"qux": True,
}
value2 = {
"foo": True,
"bar": False,
"baz": False,
"qux": True,
}
difference = {
"baz": True,
"qux": True,
}
request1 = GcpRequest(value1)
request2 = GcpRequest(value2)
self.assertNotEquals(request1, request2)
self.assertEqual(request1.difference(request2), difference)