Enforce terraform fmt in examples
This commit is contained in:
parent
0faf8ae1f1
commit
e700a27079
|
@ -24,9 +24,9 @@ BLUEPRINTS_PATH = FABRIC_ROOT / 'blueprints/'
|
||||||
MODULES_PATH = FABRIC_ROOT / 'modules/'
|
MODULES_PATH = FABRIC_ROOT / 'modules/'
|
||||||
SUBMODULES_PATH = MODULES_PATH / 'cloud-config-container'
|
SUBMODULES_PATH = MODULES_PATH / 'cloud-config-container'
|
||||||
|
|
||||||
FILE_TEST_RE = re.compile(r'# tftest-file id=(\w+) path=([\S]+)')
|
FILE_TEST_RE = re.compile(r'# tftest-file +id=(\w+) +path=([\S]+)')
|
||||||
|
|
||||||
Example = collections.namedtuple('Example', 'code module files')
|
Example = collections.namedtuple('Example', 'name code module files')
|
||||||
File = collections.namedtuple('File', 'path content')
|
File = collections.namedtuple('File', 'path content')
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,11 +71,11 @@ def pytest_generate_tests(metafunc):
|
||||||
continue
|
continue
|
||||||
if child.lang == 'hcl':
|
if child.lang == 'hcl':
|
||||||
path = module.relative_to(FABRIC_ROOT)
|
path = module.relative_to(FABRIC_ROOT)
|
||||||
examples.append(Example(code, path, files[last_header]))
|
|
||||||
name = f'{path}:{last_header}'
|
name = f'{path}:{last_header}'
|
||||||
if index > 1:
|
if index > 1:
|
||||||
name += f' {index}'
|
name += f' {index}'
|
||||||
ids.append(name)
|
ids.append(name)
|
||||||
|
examples.append(Example(name, code, path, files[last_header]))
|
||||||
elif isinstance(child, marko.block.Heading):
|
elif isinstance(child, marko.block.Heading):
|
||||||
last_header = child.children[0].children
|
last_header = child.children[0].children
|
||||||
index = 0
|
index = 0
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
BASE_PATH = Path(__file__).parent
|
BASE_PATH = Path(__file__).parent
|
||||||
|
@ -52,5 +53,12 @@ def test_example(plan_validator, tmp_path, example):
|
||||||
assert expected_modules == num_modules, 'wrong number of modules'
|
assert expected_modules == num_modules, 'wrong number of modules'
|
||||||
assert expected_resources == num_resources, 'wrong number of resources'
|
assert expected_resources == num_resources, 'wrong number of resources'
|
||||||
|
|
||||||
|
# TODO(jccb): this should probably be done in check_documentation
|
||||||
|
# but we already have all the data here.
|
||||||
|
result = subprocess.run(
|
||||||
|
'terraform fmt -check -diff -no-color main.tf'.split(), cwd=tmp_path,
|
||||||
|
stdout=subprocess.PIPE, encoding='utf-8')
|
||||||
|
assert result.returncode == 0, f'terraform code not formatted correctly\n{result.stdout}'
|
||||||
|
|
||||||
else:
|
else:
|
||||||
assert False, "can't find tftest directive"
|
assert False, "can't find tftest directive"
|
||||||
|
|
Loading…
Reference in New Issue