X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/6d0accaea3d29002e1f19586f2aaf565d6665231..63a3d8f7aa5242819c1474ad0956371c8dbb982b:/test/ganeti.utils.algo_unittest.py diff --git a/test/ganeti.utils.algo_unittest.py b/test/ganeti.utils.algo_unittest.py index b0b8e36..5d08e2e 100755 --- a/test/ganeti.utils.algo_unittest.py +++ b/test/ganeti.utils.algo_unittest.py @@ -339,5 +339,34 @@ class TestSequenceToDict(unittest.TestCase): [(i, ) for i in range(200)] + [(10, )]) +class TestFlatToDict(unittest.TestCase): + def testNormal(self): + data = [ + ("lv/xenvg", {"foo": "bar", "bar": "baz"}), + ("lv/xenfoo", {"foo": "bar", "baz": "blubb"}), + ("san/foo", {"ip": "127.0.0.1", "port": 1337}), + ("san/blubb/blibb", 54), + ] + reference = { + "lv": { + "xenvg": {"foo": "bar", "bar": "baz"}, + "xenfoo": {"foo": "bar", "baz": "blubb"}, + }, + "san": { + "foo": {"ip": "127.0.0.1", "port": 1337}, + "blubb": {"blibb": 54}, + }, + } + self.assertEqual(algo.FlatToDict(data), reference) + + def testUnlikeDepth(self): + data = [ + ("san/foo", {"ip": "127.0.0.1", "port": 1337}), + ("san/foo/blubb", 23), # Another foo entry under san + ("san/blubb/blibb", 54), + ] + self.assertRaises(AssertionError, algo.FlatToDict, data) + + if __name__ == "__main__": testutils.GanetiTestProgram()