summaryrefslogtreecommitdiff
path: root/tests/unittests/test_util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-07-17 10:20:40 -0400
committerScott Moser <smoser@brickies.net>2017-07-17 10:20:40 -0400
commitbe8e84b3639d41202a4e1ce7626b2053498fecdb (patch)
tree5f7a13f3feade970d9584cd9cfdf4473230363a1 /tests/unittests/test_util.py
parent7ed3cb3a699923623e75ad15c1c5d88abba48d00 (diff)
downloadvyos-cloud-init-be8e84b3639d41202a4e1ce7626b2053498fecdb.tar.gz
vyos-cloud-init-be8e84b3639d41202a4e1ce7626b2053498fecdb.zip
Support comments in content read by load_shell_content.
load_shell_content previously would not allow shell comment characters in the content being parsed. If comments=True is not passed then an exception would previously be raised as the line would not be guaranteed to have an '=' in it.
Diffstat (limited to 'tests/unittests/test_util.py')
-rw-r--r--tests/unittests/test_util.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index 65035be2..f38a664c 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -807,4 +807,20 @@ class TestSystemIsSnappy(helpers.FilesystemMockingTestCase):
self.reRoot(root_d)
self.assertTrue(util.system_is_snappy())
+
+class TestLoadShellContent(helpers.TestCase):
+ def test_comments_handled_correctly(self):
+ """Shell comments should be allowed in the content."""
+ self.assertEqual(
+ {'key1': 'val1', 'key2': 'val2', 'key3': 'val3 #tricky'},
+ util.load_shell_content('\n'.join([
+ "#top of file comment",
+ "key1=val1 #this is a comment",
+ "# second comment",
+ 'key2="val2" # inlin comment'
+ '#badkey=wark',
+ 'key3="val3 #tricky"',
+ ''])))
+
+
# vi: ts=4 expandtab