Migrate cloud-function tests
This commit is contained in:
parent
eab9053e16
commit
cb13d481d6
|
@ -143,6 +143,7 @@ def plan_summary_fixture(request):
|
||||||
**tf_vars):
|
**tf_vars):
|
||||||
if basedir is None:
|
if basedir is None:
|
||||||
basedir = Path(request.fspath).parent
|
basedir = Path(request.fspath).parent
|
||||||
|
print(f"{basedir=}")
|
||||||
return plan_summary(module_path=module_path, basedir=basedir,
|
return plan_summary(module_path=module_path, basedir=basedir,
|
||||||
tf_var_files=tf_var_files, extra_files=extra_files,
|
tf_var_files=tf_var_files, extra_files=extra_files,
|
||||||
**tf_vars)
|
**tf_vars)
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
project_id = "my-project"
|
||||||
|
name = "test"
|
||||||
|
bucket_name = "mybucket"
|
||||||
|
bundle_config = {
|
||||||
|
source_dir = "../../tests/modules/cloud_function/bundle"
|
||||||
|
output_path = "bundle.zip"
|
||||||
|
excludes = null
|
||||||
|
}
|
||||||
|
iam = {
|
||||||
|
"roles/cloudfunctions.invoker" = ["allUsers"]
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
project_id = "my-project"
|
||||||
|
name = "test"
|
||||||
|
bucket_name = var.bucket_name
|
||||||
|
v2 = var.v2
|
||||||
|
bundle_config = {
|
||||||
|
source_dir = "bundle"
|
||||||
|
output_path = "bundle.zip"
|
||||||
|
excludes = null
|
||||||
|
}
|
||||||
|
iam = {
|
||||||
|
"roles/cloudfunctions.invoker" = ["allUsers"]
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
# Copyright 2022 Google LLC
|
# Copyright 2023 Google LLC
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
@ -16,29 +16,29 @@ import pytest
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def resources(plan_runner, version):
|
def resources(plan_summary, plan_runner, version):
|
||||||
# convert `version` to a boolean suitable for the `v2` variable
|
# convert `version` to a boolean suitable for the `v2` variable
|
||||||
v2 = {'v1': 'false', 'v2': 'true'}[version]
|
v2 = {'v1': 'false', 'v2': 'true'}[version]
|
||||||
_, resources = plan_runner(v2=v2)
|
#_, resources = plan_runner(v2=v2)
|
||||||
return resources
|
summary = plan_summary('modules/cloud-function',
|
||||||
|
tf_var_files=['common.tfvars'], v2=v2)
|
||||||
|
return summary
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('version', ['v1', 'v2'])
|
@pytest.mark.parametrize('version', ['v1', 'v2'])
|
||||||
def test_resource_count(resources):
|
def test_resource_count(resources):
|
||||||
"Test number of resources created."
|
"Test number of resources created."
|
||||||
assert len(resources) == 3
|
assert resources.counts['resources'] == 3
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('version', ['v1', 'v2'])
|
@pytest.mark.parametrize('version', ['v1', 'v2'])
|
||||||
def test_iam(resources, version):
|
def test_iam(resources, version):
|
||||||
"Test IAM binding resources."
|
"Test IAM binding resources."
|
||||||
|
type = {
|
||||||
types = {
|
|
||||||
'v1': 'google_cloudfunctions_function_iam_binding',
|
'v1': 'google_cloudfunctions_function_iam_binding',
|
||||||
'v2': 'google_cloudfunctions2_function_iam_binding'
|
'v2': 'google_cloudfunctions2_function_iam_binding'
|
||||||
}
|
}[version]
|
||||||
|
key = f'{type}.default["roles/cloudfunctions.invoker"]'
|
||||||
bindings = [r['values'] for r in resources if r['type'] == types[version]]
|
binding = resources.values[key]
|
||||||
assert len(bindings) == 1
|
assert binding['role'] == 'roles/cloudfunctions.invoker'
|
||||||
assert bindings[0]['role'] == 'roles/cloudfunctions.invoker'
|
assert binding['members'] == ['allUsers']
|
||||||
assert bindings[0]['members'] == ['allUsers']
|
|
||||||
|
|
Loading…
Reference in New Issue