Add unit test for heat_local

For improving test coverage, this patch adds unit test for heat_local.

Change-Id: I000a73d8c54b5bb9c506d8674fbd963fed72e8f3
This commit is contained in:
Motohiro OTSUKA 2014-09-12 16:45:08 +09:00
parent 0f83ecbc2f
commit 3822b55d21
1 changed files with 24 additions and 2 deletions

View File

@ -46,8 +46,8 @@ class TestHeatLocal(testtools.TestCase):
cfg.CONF.reset()
super(TestHeatLocal, self).tearDown()
def _call_collect(self, temp_name):
cfg.CONF.heat_local.path = [temp_name]
def _call_collect(self, *temp_name):
cfg.CONF.heat_local.path = list(temp_name)
md = heat_local.Collector().collect()
self.assertEqual('heat_local', md[0][0])
return md[0][1]
@ -66,6 +66,28 @@ class TestHeatLocal(testtools.TestCase):
self.assertEqual('', self.log.output)
def test_collect_heat_local_twice(self):
with tempfile.NamedTemporaryFile() as md:
md.write(json.dumps(META_DATA).encode('utf-8'))
md.flush()
local_md = self._call_collect(md.name, md.name)
self.assertThat(local_md, matchers.IsInstance(dict))
for k in ('localstrA', 'localint9', 'localmap_xy'):
self.assertIn(k, local_md)
self.assertEqual(local_md[k], META_DATA[k])
self.assertEqual('', self.log.output)
def test_collect_heat_local_with_invalid_metadata(self):
with tempfile.NamedTemporaryFile() as md:
md.write("{'invalid' => 'INVALID'}".encode('utf-8'))
md.flush()
self.assertRaises(exc.HeatLocalMetadataNotAvailable,
self._call_collect, md.name)
self.assertIn('Local metadata not found', self.log.output)
def test_collect_ec2_nofile(self):
tdir = self.useFixture(fixtures.TempDir())
test_path = os.path.join(tdir.path, 'does-not-exist.json')