def test_outputs(self): """Test parsing a file with only outputs.""" r = Parser.load( os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'output-only.tf')) self.assertEqual(2, len(r)) self.assertIn(Output("dango"), r) self.assertIn(Output("brango"), r)
def validate(self): """Validates that all variables are exported as outputs.""" base = os.path.join(Git.root(), 'modules', 'aws', 'v1') modules = [ d for d in os.listdir(base) if os.path.isdir(os.path.join(base, d)) ] success = True for module in sorted(modules): entities = get_module_entities(os.path.join(base, module)) outputs = set(filter(lambda i: isinstance(i, Output), entities)) variables = set(filter(lambda i: isinstance(i, Variable), entities)) for variable in sorted(variables, key=lambda v: v.name): if not Output(variable.name) in outputs: # TODO better reporting! print("FAILURE[{}]: variable \"{}\" not found in outputs". format(module, variable.name)) success = False print("SUCCESS[{}] All variables bound as outputs.".format(module)) return success
def test_mixed(self): """Test parsing a mixed file.""" r = Parser.load( os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'mixed.tf')) self.assertEqual(3, len(r)) self.assertIn(Resource("default", "aws_instance"), r) self.assertIn(Output("rear"), r) self.assertIn(Variable("thing"), r)
def test_hash(self): """Tests that hash representations work properly.""" self.assertEqual( 1, len({Output("name", "string"), Output("name", "list")}))