diff options
author | Mike Milner <mike.milner@canonical.com> | 2012-01-12 18:51:19 +0100 |
---|---|---|
committer | Mike Milner <mike.milner@canonical.com> | 2012-01-12 18:51:19 +0100 |
commit | 581be44da04ccfff8750b145efedf34f08ed02ac (patch) | |
tree | d27be87eb7daefa8114f78edb27ab208b348902d /tests | |
parent | 6ceb460199720335e70ed6965a0f393563ba730d (diff) | |
download | vyos-cloud-init-581be44da04ccfff8750b145efedf34f08ed02ac.tar.gz vyos-cloud-init-581be44da04ccfff8750b145efedf34f08ed02ac.zip |
Add some tests for get_cfg_option_list_or_str.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/test_util.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py index 34a073d9..ba15e44d 100644 --- a/tests/unittests/test_util.py +++ b/tests/unittests/test_util.py @@ -1,6 +1,6 @@ from unittest import TestCase -from cloudinit.util import mergedict +from cloudinit.util import mergedict, get_cfg_option_list_or_str class TestMergeDict(TestCase): def test_simple_merge(self): @@ -51,3 +51,29 @@ class TestMergeDict(TestCase): candidate = "candidate" result = mergedict(source, candidate) self.assertEqual(source, result) + +class TestGetCfgOptionListOrStr(TestCase): + def test_not_found_no_default(self): + config = {} + result = get_cfg_option_list_or_str(config, "key") + self.assertIsNone(result) + + def test_not_found_with_default(self): + config = {} + result = get_cfg_option_list_or_str(config, "key", default=["DEFAULT"]) + self.assertEqual(["DEFAULT"], result) + + def test_found_with_default(self): + config = {"key": ["value1"]} + result = get_cfg_option_list_or_str(config, "key", default=["DEFAULT"]) + self.assertEqual(["value1"], result) + + def test_found_convert_to_list(self): + config = {"key": "value1"} + result = get_cfg_option_list_or_str(config, "key") + self.assertEqual(["value1"], result) + + def test_value_is_none(self): + config = {"key": None} + result = get_cfg_option_list_or_str(config, "key") + self.assertEqual([], result) |