def test_stub_defaults(): """Test CLI default arguments.""" with change_dir("tests"): args = cli.parse_args([]) maker = StubMaker(args) assert maker.args.input == "variables.tf" assert maker.args.output == "modstub.tf" assert not maker.args.force
def test_var_defaults(): """Test CLI default arguments.""" with change_dir("tests"): args = cli.parse_args([]) extractor = VarExtractor(args) assert extractor.args.input == "main.tf" assert extractor.args.output == "variables.tf" assert not extractor.args.force
def test_no_force(): """Test extracting variables.""" with change_dir("tests"): args = cli.parse_args([]) filename = "variables.1.tf" assert not os.path.isfile(filename) extractor = VarExtractor(args) assert extractor.extract() == EXIT_OKAY assert os.path.isfile(filename) os.remove(filename)
def test_check(): """Test checking for missing variables.""" with change_dir("tests"): args = cli.parse_args([ "-c", "-i", "main_missing.tf", "-o", "variables_missing.tf", ]) checker = Checker(args) missing = checker.find_missing() assert len(missing['main']) == 1 and missing['main'][0] == "create" assert len(missing['var']) == 1 and missing['var'][0] == "extra_var"
def test_same_content_maker(): """Test extracting variables.""" with change_dir("tests"): filename = "modstub.1.tf" if os.path.isfile(filename): os.remove(filename) args = cli.parse_args(["-mfa", "-o", filename]) maker = StubMaker(args) assert maker.extract() == EXIT_OKAY with open("modstub.tf", "r", encoding='utf_8') as file_handle: first_list = file_handle.read().splitlines() with open(filename, "r", encoding='utf_8') as file_handle: second_list = file_handle.read().splitlines() assert first_list == second_list os.remove(filename)
def test_template(): """Test extracting variables.""" with change_dir("tests"): filename = "template_vars.1.tf" if os.path.isfile(filename): os.remove(filename) args = cli.parse_args(["-fa", "--template", "-o", filename]) extractor = TemplateExtractor(args) assert extractor.extract() == EXIT_OKAY with open("template_vars.tf", "r", encoding='utf_8') as file_handle: first_list = file_handle.read().splitlines() with open(filename, "r", encoding='utf_8') as file_handle: second_list = file_handle.read().splitlines() assert first_list == second_list os.remove(filename)
def test_gen_tfvars(): """Test extracting variables.""" with change_dir("tests"): filename = "terraform.1.tfvars" if os.path.isfile(filename): os.remove(filename) args = cli.parse_args(["-fta", "-o", filename]) extractor = EnvGenerator(args) assert extractor.extract() == EXIT_OKAY with open("terraform.tfvars", "r", encoding='utf_8') as file_handle: first_list = file_handle.read().splitlines() with open(filename, "r", encoding='utf_8') as file_handle: second_list = file_handle.read().splitlines() assert first_list == second_list os.remove(filename)