python-terraform-1 Make option with bool value/ more sense for the caller

This commit is contained in:
Freddy Tan 2016-11-24 15:13:43 +08:00
parent 110a1f1c4f
commit bfd9b3a8ab
4 changed files with 28 additions and 6 deletions

1
.gitignore vendored
View file

@ -5,3 +5,4 @@
.idea .idea
.cache .cache
/.pypirc /.pypirc
/.tox/

3
requirements.txt Normal file
View file

@ -0,0 +1,3 @@
tox-pyenv
pytest
tox

View file

@ -5,7 +5,7 @@ import logging
import re import re
logging.basicConfig(level=logging.WARN) logging.basicConfig(level=logging.WARN)
current_path = os.path.dirname(os.path.realpath(__file__))
STRING_CASES = [ STRING_CASES = [
[ [
@ -61,28 +61,40 @@ class TestTerraform:
@pytest.mark.parametrize(*CMD_CASES) @pytest.mark.parametrize(*CMD_CASES)
def test_cmd(self, method, expected_output): def test_cmd(self, method, expected_output):
tf = Terraform() tf = Terraform(working_dir=current_path)
ret, out, err = method(tf) ret, out, err = method(tf)
assert expected_output in out assert expected_output in out
assert ret == 0 assert ret == 0
def test_state_data(self): def test_state_data(self):
tf = Terraform(working_dir='test_tfstate_file', state='tfstate.test') cwd = os.path.join(current_path, 'test_tfstate_file')
tf = Terraform(working_dir=cwd, state='tfstate.test')
tf.read_state_file() tf.read_state_file()
assert tf.tfstate.modules[0]['path'] == ['root'] assert tf.tfstate.modules[0]['path'] == ['root']
def test_apply(self): def test_apply(self):
tf = Terraform(working_dir='apply_tf', variables={'test_var': 'test'}) cwd = os.path.join(current_path, 'apply_tf')
tf = Terraform(working_dir=cwd, variables={'test_var': 'test'})
ret, out, err = tf.apply(var={'test_var': 'test2'}) ret, out, err = tf.apply(var={'test_var': 'test2'})
assert ret == 0 assert ret == 0
def test_override_no_color(self):
cwd = os.path.join(current_path, 'apply_tf')
tf = Terraform(working_dir=cwd, variables={'test_var': 'test'})
ret, out, err = tf.apply(var={'test_var': 'test2'},
no_color=IsNotFlagged)
out = out.replace('\n', '')
assert '\x1b[0m\x1b[1m\x1b[32mApply' in out
def test_get_output(self): def test_get_output(self):
tf = Terraform(working_dir='apply_tf', variables={'test_var': 'test'}) cwd = os.path.join(current_path, 'apply_tf')
tf = Terraform(working_dir=cwd, variables={'test_var': 'test'})
tf.apply() tf.apply()
assert tf.output('test_output') == 'test' assert tf.output('test_output') == 'test'
def test_destroy(self): def test_destroy(self):
tf = Terraform(working_dir='apply_tf', variables={'test_var': 'test'}) cwd = os.path.join(current_path, 'apply_tf')
tf = Terraform(working_dir=cwd, variables={'test_var': 'test'})
ret, out, err = tf.destroy() ret, out, err = tf.destroy()
assert ret == 0 assert ret == 0
assert 'Destroy complete! Resources: 0 destroyed.' in out assert 'Destroy complete! Resources: 0 destroyed.' in out

6
tox.ini Normal file
View file

@ -0,0 +1,6 @@
# content of: tox.ini , put in same dir as setup.py
[tox]
envlist = py27, py3
[testenv]
deps=pytest
commands=py.test test