diff options
author | Evgeni Golov <evgeni@golov.de> | 2019-09-20 21:47:18 +0200 |
---|---|---|
committer | Sam Doran <sdoran@redhat.com> | 2019-09-20 21:47:18 +0200 |
commit | 8d0c193b251051e459513614e6f7212ecf9f0922 (patch) | |
tree | f5681efe06868d6be2198643ab6b86ab75634a96 /test/units | |
parent | k8s: apply no longer the default behaviour (#62632) (diff) | |
download | ansible-8d0c193b251051e459513614e6f7212ecf9f0922.tar.xz ansible-8d0c193b251051e459513614e6f7212ecf9f0922.zip |
allow before/after diff to be NoneType (#62582)
when creating or deleting an object (e.g. via an API), before/after can
be `None` (or at least represented as such by the used library). to
avoid modules havig to do
diff={'before': before or '', 'after': after or ''}
let's just convert `None` to an empty string that can be diffed properly
Diffstat (limited to 'test/units')
-rw-r--r-- | test/units/plugins/callback/test_callback.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/units/plugins/callback/test_callback.py b/test/units/plugins/callback/test_callback.py index 52233800f3..906f00040c 100644 --- a/test/units/plugins/callback/test_callback.py +++ b/test/units/plugins/callback/test_callback.py @@ -365,6 +365,34 @@ class TestCallbackDiff(unittest.TestCase): ''')) + def test_diff_before_none(self): + self.assertMultiLineEqual( + self._strip_color(self.cb._get_diff({ + 'before': None, + 'after': 'one line\n', + })), + textwrap.dedent('''\ + --- before + +++ after + @@ -0,0 +1 @@ + +one line + + ''')) + + def test_diff_after_none(self): + self.assertMultiLineEqual( + self._strip_color(self.cb._get_diff({ + 'before': 'one line\n', + 'after': None, + })), + textwrap.dedent('''\ + --- before + +++ after + @@ -1 +0,0 @@ + -one line + + ''')) + class TestCallbackOnMethods(unittest.TestCase): def _find_on_methods(self, callback): |