Create fully recursive e2e test runner

This commit is contained in:
Julio Castillo
2022-09-12 13:53:54 +02:00
parent 9072a572b1
commit 7e9173d35d
17 changed files with 50 additions and 98 deletions

View File

@@ -1,58 +0,0 @@
# Copyright 2022 Google LLC
#
# 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.
"Shared fixtures"
import inspect
import os
import types
import pytest
import tftest
BASEDIR = os.path.dirname(os.path.dirname(__file__))
@pytest.fixture(scope='session')
def fast_e2e_plan_runner(_plan_runner):
"Plan runner for end-to-end root module, returns modules and resources."
def run_plan(fixture_path=None, targets=None, refresh=True,
include_bare_resources=False, compute_sums=True, **tf_vars):
"Runs Terraform plan on a root module using defaults, returns data."
plan = _plan_runner(fixture_path, targets=targets, refresh=refresh,
**tf_vars)
root_module = plan.root_module['child_modules'][0]
# Count all modules and resources up to 2 levels deep. We include
# the second level to account for wrapper modules used by stages 3
modules = {}
for m in root_module['child_modules']:
key = m['address'].removeprefix(root_module['address'])[1:]
modules[key] = m.get('resources', [])
if m.get('child_modules'):
for m2 in m['child_modules']:
key2 = m2['address'].removeprefix(root_module['address'])[1:]
modules[key2] = m2.get('resources', [])
resources = [r for m in modules.values() for r in m]
if include_bare_resources:
bare_resources = root_module['resources']
resources.extend(bare_resources)
if compute_sums:
return len(modules), len(resources), {
k: len(v) for k, v in modules.items()
}
return modules, resources
return run_plan

View File

@@ -26,8 +26,8 @@
# }
def test_counts(fast_e2e_plan_runner):
def test_counts(recursive_e2e_plan_runner):
"Test stage."
# TODO: to re-enable per-module resource count check print _, then test
num_modules, num_resources, _ = fast_e2e_plan_runner()
num_modules, num_resources = recursive_e2e_plan_runner()
assert num_modules > 0 and num_resources > 0

View File

@@ -13,8 +13,8 @@
# limitations under the License.
def test_counts(fast_e2e_plan_runner):
def test_counts(recursive_e2e_plan_runner):
"Test stage."
num_modules, num_resources, _ = fast_e2e_plan_runner()
num_modules, num_resources = recursive_e2e_plan_runner()
# TODO: to re-enable per-module resource count check print _, then test
assert num_modules > 0 and num_resources > 0

View File

@@ -13,8 +13,8 @@
# limitations under the License.
def test_counts(fast_e2e_plan_runner):
def test_counts(recursive_e2e_plan_runner):
"Test stage."
num_modules, num_resources, _ = fast_e2e_plan_runner()
num_modules, num_resources = recursive_e2e_plan_runner()
# TODO: to re-enable per-module resource count check print _, then test
assert num_modules > 0 and num_resources > 0

View File

@@ -27,9 +27,9 @@ STAGE_PEERING = STAGES / '02-networking-peering'
STAGE_VPN = STAGES / '02-networking-vpn'
def test_counts(fast_e2e_plan_runner):
def test_counts(recursive_e2e_plan_runner):
'Test stage.'
num_modules, num_resources, _ = fast_e2e_plan_runner()
num_modules, num_resources = recursive_e2e_plan_runner()
# TODO: to re-enable per-module resource count check print _, then test
assert num_modules > 0 and num_resources > 0

View File

@@ -13,8 +13,8 @@
# limitations under the License.
def test_counts(fast_e2e_plan_runner):
def test_counts(recursive_e2e_plan_runner):
"Test stage."
num_modules, num_resources, _ = fast_e2e_plan_runner()
num_modules, num_resources = recursive_e2e_plan_runner()
# TODO: to re-enable per-module resource count check print _, then test
assert num_modules > 0 and num_resources > 0

View File

@@ -13,8 +13,8 @@
# limitations under the License.
def test_counts(fast_e2e_plan_runner):
def test_counts(recursive_e2e_plan_runner):
"Test stage."
num_modules, num_resources, _ = fast_e2e_plan_runner()
num_modules, num_resources = recursive_e2e_plan_runner()
# TODO: to re-enable per-module resource count check print _, then test
assert num_modules > 0 and num_resources > 0

View File

@@ -13,8 +13,8 @@
# limitations under the License.
def test_counts(fast_e2e_plan_runner):
def test_counts(recursive_e2e_plan_runner):
"Test stage."
num_modules, num_resources, _ = fast_e2e_plan_runner()
num_modules, num_resources = recursive_e2e_plan_runner()
# TODO: to re-enable per-module resource count check print _, then test
assert num_modules > 0 and num_resources > 0

View File

@@ -13,8 +13,8 @@
# limitations under the License.
def test_counts(fast_e2e_plan_runner):
def test_counts(recursive_e2e_plan_runner):
"Test stage."
num_modules, num_resources, _ = fast_e2e_plan_runner()
num_modules, num_resources = recursive_e2e_plan_runner()
# TODO: to re-enable per-module resource count check print _, then test
assert num_modules > 0 and num_resources > 0

View File

@@ -13,8 +13,8 @@
# limitations under the License.
def test_counts(fast_e2e_plan_runner):
def test_counts(recursive_e2e_plan_runner):
"Test stage."
num_modules, num_resources, _ = fast_e2e_plan_runner()
num_modules, num_resources = recursive_e2e_plan_runner()
# TODO: to re-enable per-module resource count check print _, then test
assert num_modules > 0 and num_resources > 0