summaryrefslogtreecommitdiff
path: root/cloudinit/tests/test_util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2018-03-09 04:22:24 +0100
committerChad Smith <chad.smith@canonical.com>2018-03-09 04:22:24 +0100
commitb7a790246e52520b47a467fe89b81199b9cf03f6 (patch)
treef39c712b38233faad1896ef6de50b9f7a3a6bb6d /cloudinit/tests/test_util.py
parent1e2e810f3f7cb6a163a0229ac37037e8c6744d72 (diff)
downloadvyos-cloud-init-b7a790246e52520b47a467fe89b81199b9cf03f6.tar.gz
vyos-cloud-init-b7a790246e52520b47a467fe89b81199b9cf03f6.zip
shellify: raise TypeError on bad input.
This makes 2 changes to shellify's behavior: a.) raise a TypeError rather than a RuntimeError. b.) raise a TypeError if input is not a list or tuple.
Diffstat (limited to 'cloudinit/tests/test_util.py')
-rw-r--r--cloudinit/tests/test_util.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/cloudinit/tests/test_util.py b/cloudinit/tests/test_util.py
index ba6bf699..c3e2e404 100644
--- a/cloudinit/tests/test_util.py
+++ b/cloudinit/tests/test_util.py
@@ -44,3 +44,26 @@ class TestUtil(CiTestCase):
m_mount_info.return_value = ('/dev/sda1', 'btrfs', '/', 'ro,relatime')
is_rw = util.mount_is_read_write('/')
self.assertEqual(is_rw, False)
+
+
+class TestShellify(CiTestCase):
+
+ def test_input_dict_raises_type_error(self):
+ self.assertRaisesRegex(
+ TypeError, 'Input.*was.*dict.*xpected',
+ util.shellify, {'mykey': 'myval'})
+
+ def test_input_str_raises_type_error(self):
+ self.assertRaisesRegex(
+ TypeError, 'Input.*was.*str.*xpected', util.shellify, "foobar")
+
+ def test_value_with_int_raises_type_error(self):
+ self.assertRaisesRegex(
+ TypeError, 'shellify.*int', util.shellify, ["foo", 1])
+
+ def test_supports_strings_and_lists(self):
+ self.assertEqual(
+ '\n'.join(["#!/bin/sh", "echo hi mom", "'echo' 'hi dad'",
+ "'echo' 'hi' 'sis'", ""]),
+ util.shellify(["echo hi mom", ["echo", "hi dad"],
+ ('echo', 'hi', 'sis')]))