Skip to content

Commit

Permalink
Merge pull request #988 from GoogleCloudPlatform/jccb/merge-function-…
Browse files Browse the repository at this point in the history
…tests

Merge cloud function v1 and v2 tests
  • Loading branch information
juliocc authored Nov 17, 2022
2 parents 4d4bcb2 + ed84bcb commit c709a09
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 117 deletions.
1 change: 1 addition & 0 deletions tests/modules/cloud_function/fixture/main.tf
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.

0 comments on commit c709a09

Please sign in to comment.