2022-01-01 06:52:31 -08:00
|
|
|
# Copyright 2022 Google LLC
|
2020-11-07 01:40:09 -08:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2020-11-07 01:28:33 -08:00
|
|
|
import re
|
|
|
|
from pathlib import Path
|
|
|
|
|
2022-01-19 05:17:20 -08:00
|
|
|
BASE_PATH = Path(__file__).parent
|
2022-01-28 11:15:35 -08:00
|
|
|
EXPECTED_RESOURCES_RE = re.compile(r'# tftest modules=(\d+) resources=(\d+)')
|
2020-11-07 01:28:33 -08:00
|
|
|
|
|
|
|
|
2022-09-12 04:53:54 -07:00
|
|
|
def test_example(recursive_e2e_plan_runner, tmp_path, example):
|
2022-09-06 08:46:09 -07:00
|
|
|
(tmp_path / 'fabric').symlink_to(Path(BASE_PATH, '../../').resolve())
|
2022-01-19 05:17:20 -08:00
|
|
|
(tmp_path / 'variables.tf').symlink_to(
|
|
|
|
Path(BASE_PATH, 'variables.tf').resolve())
|
2022-11-16 14:03:29 -08:00
|
|
|
(tmp_path / 'configs').symlink_to(Path(BASE_PATH, 'configs').resolve())
|
2020-11-07 01:28:33 -08:00
|
|
|
(tmp_path / 'main.tf').write_text(example)
|
|
|
|
|
|
|
|
match = EXPECTED_RESOURCES_RE.search(example)
|
|
|
|
expected_modules = int(match.group(1)) if match is not None else 1
|
|
|
|
expected_resources = int(match.group(2)) if match is not None else 1
|
|
|
|
|
2022-11-16 14:03:29 -08:00
|
|
|
assert match is not None, "can't find tftest directive"
|
|
|
|
|
2022-09-14 05:34:30 -07:00
|
|
|
num_modules, num_resources = recursive_e2e_plan_runner(
|
|
|
|
str(tmp_path), tmpdir=False)
|
2022-11-16 14:03:29 -08:00
|
|
|
assert expected_modules == num_modules, 'wrong number of modules'
|
|
|
|
assert expected_resources == num_resources, 'wrong number of resources'
|