fix test working directory

This commit is contained in:
Freddy Tan 2016-12-20 19:58:04 +08:00
parent 2d63fa8716
commit d2440a6b21

View file

@ -50,7 +50,7 @@ class TestTerraform(object):
"method", "expected" "method", "expected"
], STRING_CASES) ], STRING_CASES)
def test_generate_cmd_string(self, method, expected): def test_generate_cmd_string(self, method, expected):
tf = Terraform() tf = Terraform(working_dir=current_path)
result = method(tf) result = method(tf)
strs = expected.split() strs = expected.split()
@ -73,7 +73,7 @@ class TestTerraform(object):
("var_to_output", {'test_map_var': {"c": "c", "d": "d"}}, 'var_to_output/test_map_var.json', "test_map_output={a=ab=bc=cd=de=ef=f}") ("var_to_output", {'test_map_var': {"c": "c", "d": "d"}}, 'var_to_output/test_map_var.json', "test_map_output={a=ab=bc=cd=de=ef=f}")
]) ])
def test_apply(self, folder, variables, var_files, expected_output): def test_apply(self, folder, variables, var_files, expected_output):
tf = Terraform(variables=variables, var_file=var_files) tf = Terraform(working_dir=current_path, variables=variables, var_file=var_files)
ret, out, err = tf.apply(folder) ret, out, err = tf.apply(folder)
assert ret == 0 assert ret == 0
assert expected_output in out.replace('\n', '').replace(' ', '') assert expected_output in out.replace('\n', '').replace(' ', '')
@ -98,24 +98,24 @@ class TestTerraform(object):
] ]
) )
def test_override_default(self, folder, variables): def test_override_default(self, folder, variables):
tf = Terraform(variables=variables) tf = Terraform(working_dir=current_path, variables=variables)
ret, out, err = tf.apply(folder, var={'test_var': 'test2'}, ret, out, err = tf.apply(folder, var={'test_var': 'test2'},
no_color=IsNotFlagged) no_color=IsNotFlagged)
out = out.replace('\n', '') out = out.replace('\n', '')
assert '\x1b[0m\x1b[1m\x1b[32mApply' in out assert '\x1b[0m\x1b[1m\x1b[32mApply' in out
def test_get_output(self): def test_get_output(self):
tf = Terraform(variables={'test_var': 'test'}) tf = Terraform(working_dir=current_path, variables={'test_var': 'test'})
tf.apply('var_to_output') tf.apply('var_to_output')
assert tf.output('test_output') == 'test' assert tf.output('test_output') == 'test'
def test_destroy(self): def test_destroy(self):
tf = Terraform(variables={'test_var': 'test'}) tf = Terraform(working_dir=current_path, variables={'test_var': 'test'})
ret, out, err = tf.destroy('var_to_output') ret, out, err = tf.destroy('var_to_output')
assert ret == 0 assert ret == 0
assert 'Destroy complete! Resources: 0 destroyed.' in out assert 'Destroy complete! Resources: 0 destroyed.' in out
def test_fmt(self): def test_fmt(self):
tf = Terraform(variables={'test_var': 'test'}) tf = Terraform(working_dir=current_path, variables={'test_var': 'test'})
ret, out, err = tf.fmt(diff=True) ret, out, err = tf.fmt(diff=True)
assert ret == 0 assert ret == 0