Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge cloud function v1 and v2 tests #988

Merged
merged 1 commit into from Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/modules/cloud_function/fixture/main.tf
Expand Up @@ -19,6 +19,7 @@ module "test" {
project_id = "my-project"
name = "test"
bucket_name = var.bucket_name
v2 = var.v2
bundle_config = {
source_dir = "bundle"
output_path = "bundle.zip"
Expand Down
7 changes: 6 additions & 1 deletion tests/modules/cloud_function/fixture/variables.tf
Expand Up @@ -15,6 +15,11 @@
*/

variable "bucket_name" {
type = string
type = any
default = "test"
}

variable "v2" {
type = any
default = false
}
20 changes: 15 additions & 5 deletions tests/modules/cloud_function/test_plan.py
Expand Up @@ -16,19 +16,29 @@


@pytest.fixture
def resources(plan_runner):
_, resources = plan_runner()
def resources(plan_runner, version):
# convert `version` to a boolean suitable for the `v2` variable
v2 = {'v1': 'false', 'v2': 'true'}[version]
_, resources = plan_runner(v2=v2)
return resources


@pytest.mark.parametrize('version', ['v1', 'v2'])
def test_resource_count(resources):
"Test number of resources created."
assert len(resources) == 3


def test_iam(resources):
@pytest.mark.parametrize('version', ['v1', 'v2'])
def test_iam(resources, version):
"Test IAM binding resources."
bindings = [r['values'] for r in resources if r['type']
== 'google_cloudfunctions_function_iam_binding']

types = {
'v1': 'google_cloudfunctions_function_iam_binding',
'v2': 'google_cloudfunctions2_function_iam_binding'
}

bindings = [r['values'] for r in resources if r['type'] == types[version]]
assert len(bindings) == 1
assert bindings[0]['role'] == 'roles/cloudfunctions.invoker'
assert bindings[0]['members'] == ['allUsers']
13 changes: 0 additions & 13 deletions tests/modules/cloud_function_v2/__init__.py

This file was deleted.

13 changes: 0 additions & 13 deletions tests/modules/cloud_function_v2/fixture/bundle/main.py

This file was deleted.

31 changes: 0 additions & 31 deletions tests/modules/cloud_function_v2/fixture/main.tf

This file was deleted.

20 changes: 0 additions & 20 deletions tests/modules/cloud_function_v2/fixture/variables.tf

This file was deleted.

34 changes: 0 additions & 34 deletions tests/modules/cloud_function_v2/test_plan.py

This file was deleted.