-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6910235
commit 9257fb5
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""unit test for terraform fmt module""" | ||
__metaclass__ = type | ||
|
||
|
||
import json | ||
import pytest | ||
from mschuchard.general.plugins.modules import terraform_fmt | ||
from mschuchard.general.tests.unit.plugins.modules import utils | ||
|
||
|
||
def test_terraform_fmt_defaults(capfd): | ||
"""test terraform fmt with defaults""" | ||
utils.set_module_args({}) | ||
with pytest.raises(SystemExit, match='0'): | ||
terraform_fmt.main() | ||
|
||
stdout, stderr = capfd.readouterr() | ||
assert not stderr | ||
|
||
info = json.loads(stdout) | ||
assert 'fmt' in info['command'] | ||
assert '-no-color' in info['command'] | ||
assert '-list=false' in info['command'] | ||
assert '' == info['stdout'] | ||
|
||
|
||
def test_terraform_fmt_config_diff_write(capfd): | ||
"""test terraform fmt with config diff write""" | ||
utils.set_module_args({'diff': True, 'write': False, 'config_dir': str(utils.fixtures_dir())}) | ||
with pytest.raises(SystemExit, match='0'): | ||
terraform_fmt.main() | ||
|
||
stdout, stderr = capfd.readouterr() | ||
assert not stderr | ||
|
||
info = json.loads(stdout) | ||
assert f"-chdir={str(utils.fixtures_dir())}" in info['command'] | ||
assert '-diff' in info['command'] | ||
assert '-write=false' in info['command'] | ||
assert '' == info['stdout'] | ||
|
||
|
||
def test_terraform_fmt_check_recursive(capfd): | ||
"""test terraform validate with check recursive""" | ||
utils.set_module_args({'check': True, 'recursive': True}) | ||
with pytest.raises(SystemExit, match='0'): | ||
terraform_fmt.main() | ||
|
||
stdout, stderr = capfd.readouterr() | ||
assert not stderr | ||
|
||
info = json.loads(stdout) | ||
assert '-check' in info['command'] | ||
assert '-recursive' in info['command'] | ||
assert '' == info['stdout'] |