Merge branch 'release/0.8.1'

This commit is contained in:
Freddy Tan 2016-12-21 00:57:43 +08:00
commit 331249029f
5 changed files with 65 additions and 8 deletions

View file

@ -1,5 +1,5 @@
[bumpversion] [bumpversion]
current_version = 0.8.0 current_version = 0.8.1
commit = True commit = True
tag = False tag = False

View file

@ -1 +1 @@
0.8.0 0.8.1

View file

@ -51,7 +51,7 @@ class Terraform(object):
self.terraform_bin_path = terraform_bin_path \ self.terraform_bin_path = terraform_bin_path \
if terraform_bin_path else 'terraform' if terraform_bin_path else 'terraform'
self.var_file = var_file self.var_file = var_file
self.temp_var_files = VaribleFiles() self.temp_var_files = VariableFiles()
# store the tfstate data # store the tfstate data
self.tfstate = None self.tfstate = None
@ -59,7 +59,7 @@ class Terraform(object):
def __getattr__(self, item): def __getattr__(self, item):
def wrapper(*args, **kwargs): 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 self.cmd(item, *args, **kwargs)
return wrapper return wrapper
@ -152,12 +152,12 @@ class Terraform(object):
if v is IsNotFlagged: if v is IsNotFlagged:
continue continue
if not v:
continue
if type(v) is bool: if type(v) is bool:
v = 'true' if v else 'false' v = 'true' if v else 'false'
if not v:
continue
cmds += ['-{k}={v}'.format(k=k, v=v)] cmds += ['-{k}={v}'.format(k=k, v=v)]
cmds += args cmds += args
@ -239,7 +239,7 @@ class Terraform(object):
self.temp_var_files.clean_up() self.temp_var_files.clean_up()
class VaribleFiles(object): class VariableFiles(object):
def __init__(self): def __init__(self):
self.files = [] self.files = []

31
test/bad_fmt/test.tf Normal file
View file

@ -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}"
}

View file

@ -3,6 +3,7 @@ import pytest
import os import os
import logging import logging
import re import re
import shutil
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
current_path = os.path.dirname(os.path.realpath(__file__)) 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): class TestTerraform(object):
def teardown_method(self, method): def teardown_method(self, method):
@ -79,6 +93,18 @@ class TestTerraform(object):
assert expected_output in out.replace('\n', '').replace(' ', '') assert expected_output in out.replace('\n', '').replace(' ', '')
assert err == '' assert err == ''
@pytest.mark.parametrize(
['cmd', 'args', 'options'],
[
# bool value
('fmt', ['bad_fmt'], {'list': False, 'diff': False})
]
)
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 == ''
def test_state_data(self): def test_state_data(self):
cwd = os.path.join(current_path, 'test_tfstate_file') cwd = os.path.join(current_path, 'test_tfstate_file')