From bc1adff98e140224422dfab680b02de141672e22 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Thu, 1 Sep 2016 17:08:42 -0400 Subject: [PATCH] Add unit tests for invalid keys in resources This is only working more or less by coincidence at the moment, so add tests to ensure that it doesn't get broken by future changes. Change-Id: I9d78d2b4f8adcd0ba9d6929c62e3975688498aaa --- heat/tests/test_validate.py | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/heat/tests/test_validate.py b/heat/tests/test_validate.py index 947b25aab9..5c68d877f8 100644 --- a/heat/tests/test_validate.py +++ b/heat/tests/test_validate.py @@ -1654,6 +1654,46 @@ class ValidateTest(common.HeatTestCase): self.assertEqual('Resource Resource Type type must be string', six.text_type(ex)) + def test_validate_resource_invalid_key(self): + t = template_format.parse(""" + heat_template_version: 2013-05-23 + resources: + resource: + type: OS::Heat::TestResource + wibble: bar + """) + template = tmpl.Template(t) + stack = parser.Stack(self.ctx, 'test_stack', template) + ex = self.assertRaises(exception.StackValidationFailed, stack.validate) + self.assertIn('wibble', six.text_type(ex)) + + def test_validate_resource_invalid_cfn_key_in_hot(self): + t = template_format.parse(""" + heat_template_version: 2013-05-23 + resources: + resource: + type: OS::Heat::TestResource + Properties: {foo: bar} + """) + template = tmpl.Template(t) + stack = parser.Stack(self.ctx, 'test_stack', template) + ex = self.assertRaises(exception.StackValidationFailed, stack.validate) + self.assertIn('Properties', six.text_type(ex)) + + def test_validate_resource_invalid_key_cfn(self): + t = template_format.parse(""" + HeatTemplateFormatVersion: '2012-12-12' + Resources: + Resource: + Type: OS::Heat::TestResource + Wibble: bar + """) + template = tmpl.Template(t) + stack = parser.Stack(self.ctx, 'test_stack', template) + # We have always allowed unknown keys in CFN-style templates, so we + # more or less have to keep allowing it. + self.assertIsNone(stack.validate()) + def test_validate_is_service_available(self): t = template_format.parse( """