From a8dd5ae7cc170a02114603e038da324e0f91f653 Mon Sep 17 00:00:00 2001 From: Julio Castillo Date: Tue, 1 Mar 2022 12:20:08 +0100 Subject: [PATCH] Add test to ensure parity between 02-networking-[vpn/peering] --- .../s02_networking_peering/test_plan.py | 29 ++++++++++++++++++- tests/requirements.txt | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/fast/stages/s02_networking_peering/test_plan.py b/tests/fast/stages/s02_networking_peering/test_plan.py index 6189f62e3..887cddecd 100644 --- a/tests/fast/stages/s02_networking_peering/test_plan.py +++ b/tests/fast/stages/s02_networking_peering/test_plan.py @@ -12,9 +12,36 @@ # See the License for the specific language governing permissions and # limitations under the License. +from pathlib import Path + +from deepdiff import DeepDiff + +BASEDIR = Path(__file__).parent +FIXTURE_PEERING = BASEDIR / 'fixture' +FIXTURE_VPN = BASEDIR.parent / 's02_networking_vpn/fixture' + def test_counts(fast_e2e_plan_runner): - "Test stage." + 'Test stage.' num_modules, num_resources, _ = fast_e2e_plan_runner() # TODO: to re-enable per-module resource count check print _, then test assert num_modules > 0 and num_resources > 0 + + +def test_vpn_peering_parity(e2e_plan_runner): + '''Ensure VPN- and peering-based networking stages are identical except + for VPN and VPC peering resources''' + _, plan_peering = e2e_plan_runner(fixture_path=FIXTURE_PEERING) + _, plan_vpn = e2e_plan_runner(fixture_path=FIXTURE_VPN) + ddiff = DeepDiff(plan_vpn, plan_peering, ignore_order=True, + group_by='address', view='tree') + + removed_types = {x.t1['type'] for x in ddiff['dictionary_item_removed']} + added_types = {x.t2['type'] for x in ddiff['dictionary_item_added']} + + assert added_types == {'google_compute_network_peering'} + assert removed_types == { + 'google_compute_ha_vpn_gateway', 'google_compute_router', + 'google_compute_router_interface', 'google_compute_router_peer', + 'google_compute_vpn_tunnel', 'random_id' + } diff --git a/tests/requirements.txt b/tests/requirements.txt index 35fdf3e49..e98216cc8 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -2,3 +2,4 @@ pytest>=6.2.5 PyYAML>=6.0 tftest>=1.6.3 marko>=1.2.0 +deepdiff>=5.7.0