From 211e73a1099388d1c6f842af37e7e1a16e71573f Mon Sep 17 00:00:00 2001 From: Freddy Tan Date: Wed, 21 Dec 2016 00:18:57 +0800 Subject: [PATCH 1/5] 1. fix typo 2. fix false bool value will skip 3. fix print to log --- python_terraform/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python_terraform/__init__.py b/python_terraform/__init__.py index 9c1bc2c..e61ff00 100644 --- a/python_terraform/__init__.py +++ b/python_terraform/__init__.py @@ -51,7 +51,7 @@ class Terraform(object): self.terraform_bin_path = terraform_bin_path \ if terraform_bin_path else 'terraform' self.var_file = var_file - self.temp_var_files = VaribleFiles() + self.temp_var_files = VariableFiles() # store the tfstate data self.tfstate = None @@ -59,7 +59,7 @@ class Terraform(object): def __getattr__(self, item): def wrapper(*args, **kwargs): - print('called with %r and %r' % (args, kwargs)) + logging.debug('called with %r and %r' % (args, kwargs)) return self.cmd(item, *args, **kwargs) return wrapper @@ -152,12 +152,12 @@ class Terraform(object): if v is IsNotFlagged: continue - if not v: - continue - if type(v) is bool: v = 'true' if v else 'false' + if not v: + continue + cmds += ['-{k}={v}'.format(k=k, v=v)] cmds += args @@ -239,7 +239,7 @@ class Terraform(object): self.temp_var_files.clean_up() -class VaribleFiles(object): +class VariableFiles(object): def __init__(self): self.files = [] From f1e0ce62ed9fff9b13bb22e71df6570f03fb14dc Mon Sep 17 00:00:00 2001 From: Freddy Tan Date: Wed, 21 Dec 2016 00:41:08 +0800 Subject: [PATCH 2/5] 1. add test case --- test/bad_fmt/test.tf | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test/bad_fmt/test.tf diff --git a/test/bad_fmt/test.tf b/test/bad_fmt/test.tf new file mode 100644 index 0000000..b756909 --- /dev/null +++ b/test/bad_fmt/test.tf @@ -0,0 +1,31 @@ +variable "test_var" { + default = "" +} + +provider "archive" {} + +variable "test_list_var" { + type = "list" + default = ["a", "b"] +} + +variable "test_map_var" { + type = "map" + + default = { + "a" = "a" + "b" = "b" + } +} + +output "test_output" { + value = "${var.test_var}" +} + +output "test_list_output" { + value = "${var.test_list_var}" +} + +output "test_map_output" { + value = "${var.test_map_var}" +} From 839b30d72a14ba956903b10012a2584b3abe4d56 Mon Sep 17 00:00:00 2001 From: Freddy Tan Date: Wed, 21 Dec 2016 00:43:44 +0800 Subject: [PATCH 3/5] add test case for options --- test/test_terraform.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/test_terraform.py b/test/test_terraform.py index f05819c..ab592ea 100644 --- a/test/test_terraform.py +++ b/test/test_terraform.py @@ -79,6 +79,20 @@ class TestTerraform(object): assert expected_output in out.replace('\n', '').replace(' ', '') assert err == '' + @pytest.mark.parametrize( + ['cmd', 'args', 'options'], + [ + # bool value + ('fmt', ['bad_fmt'], {'list': False, 'diff': False}) + ] + ) + def test_options(self, cmd, args, options): + tf = Terraform(working_dir=current_path) + ret, out, err = getattr(tf, cmd)(*args, **options) + assert ret == 0 + assert out == '' + # todo revert the test file + def test_state_data(self): cwd = os.path.join(current_path, 'test_tfstate_file') From df78cfe9be48cb7ead29d64682ae039fd1812b99 Mon Sep 17 00:00:00 2001 From: Freddy Tan Date: Wed, 21 Dec 2016 00:55:55 +0800 Subject: [PATCH 4/5] fix teardown --- test/test_terraform.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/test_terraform.py b/test/test_terraform.py index ab592ea..a190b15 100644 --- a/test/test_terraform.py +++ b/test/test_terraform.py @@ -3,6 +3,7 @@ import pytest import os import logging import re +import shutil logging.basicConfig(level=logging.DEBUG) current_path = os.path.dirname(os.path.realpath(__file__)) @@ -31,6 +32,19 @@ CMD_CASES = [ ] ] +@pytest.fixture() +def fmt_test_file(request): + target = os.path.join(current_path, 'bad_fmt', 'test.backup') + orgin = os.path.join(current_path, 'bad_fmt', 'test.tf') + shutil.copy(orgin, + target) + + def td(): + shutil.move(target, orgin) + + request.addfinalizer(td) + return + class TestTerraform(object): def teardown_method(self, method): @@ -86,13 +100,11 @@ class TestTerraform(object): ('fmt', ['bad_fmt'], {'list': False, 'diff': False}) ] ) - def test_options(self, cmd, args, options): + def test_options(self, cmd, args, options, fmt_test_file): tf = Terraform(working_dir=current_path) ret, out, err = getattr(tf, cmd)(*args, **options) assert ret == 0 assert out == '' - # todo revert the test file - def test_state_data(self): cwd = os.path.join(current_path, 'test_tfstate_file') From a775380240883ff6d1a7f0f5a3d8de46ffdfc574 Mon Sep 17 00:00:00 2001 From: Freddy Tan Date: Wed, 21 Dec 2016 00:56:33 +0800 Subject: [PATCH 5/5] =?UTF-8?q?Bump=20version:=200.8.0=20=E2=86=92=200.8.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- VERSION | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 2abe63e..d43be24 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.8.0 +current_version = 0.8.1 commit = True tag = False diff --git a/VERSION b/VERSION index 8adc70f..c18d72b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.8.0 \ No newline at end of file +0.8.1 \ No newline at end of file