From c819305a42aab60876c2c95a8ac746c186829db8 Mon Sep 17 00:00:00 2001 From: Julio Castillo Date: Thu, 20 Apr 2023 11:48:14 +0200 Subject: [PATCH] Migrate apigee tests --- tests/modules/apigee/__init__.py | 13 --- .../{fixture/test.all.tfvars => all.tfvars} | 0 tests/modules/apigee/all.yaml | 83 ++++++++++++++ ...tfvars => endpoint_attachment_only.tfvars} | 0 .../apigee/endpoint_attachment_only.yaml} | 12 +- .../test.env_only.tfvars => env_only.tfvars} | 0 tests/modules/apigee/env_only.yaml | 32 ++++++ ...rs => env_only_with_api_proxy_type.tfvars} | 0 .../apigee/env_only_with_api_proxy_type.yaml | 31 ++++++ ...s => env_only_with_deployment_type.tfvars} | 0 .../apigee/env_only_with_deployment_type.yaml | 34 ++++++ ...group_only.tfvars => envgroup_only.tfvars} | 0 .../apigee/envgroup_only.yaml} | 12 +- tests/modules/apigee/fixture/main.tf | 25 ----- tests/modules/apigee/fixture/variables.tf | 81 -------------- ...tance_only.tfvars => instance_only.tfvars} | 0 .../apigee/instance_only.yaml} | 15 ++- ...o_instances.tfvars => no_instances.tfvars} | 0 tests/modules/apigee/no_instances.yaml | 51 +++++++++ ...n_only.tfvars => organization_only.tfvars} | 0 .../apigee/organization_only.yaml} | 17 ++- tests/modules/apigee/test_plan.py | 95 ---------------- .../test_plan.py => apigee/tftest.yaml} | 22 ++-- tests/modules/binauthz/__init__.py | 13 --- tests/modules/binauthz/fixture/main.tf | 23 ---- tests/modules/binauthz/fixture/variables.tf | 103 ------------------ 26 files changed, 295 insertions(+), 367 deletions(-) delete mode 100644 tests/modules/apigee/__init__.py rename tests/modules/apigee/{fixture/test.all.tfvars => all.tfvars} (100%) create mode 100644 tests/modules/apigee/all.yaml rename tests/modules/apigee/{fixture/test.endpoint_attachment_only.tfvars => endpoint_attachment_only.tfvars} (100%) rename tests/{fast/stages_multitenant/__init__.py => modules/apigee/endpoint_attachment_only.yaml} (60%) rename tests/modules/apigee/{fixture/test.env_only.tfvars => env_only.tfvars} (100%) create mode 100644 tests/modules/apigee/env_only.yaml rename tests/modules/apigee/{fixture/test.env_only_with_api_proxy_type.tfvars => env_only_with_api_proxy_type.tfvars} (100%) create mode 100644 tests/modules/apigee/env_only_with_api_proxy_type.yaml rename tests/modules/apigee/{fixture/test.env_only_with_deployment_type.tfvars => env_only_with_deployment_type.tfvars} (100%) create mode 100644 tests/modules/apigee/env_only_with_deployment_type.yaml rename tests/modules/apigee/{fixture/test.envgroup_only.tfvars => envgroup_only.tfvars} (100%) rename tests/{blueprints/factories/__init__.py => modules/apigee/envgroup_only.yaml} (72%) delete mode 100644 tests/modules/apigee/fixture/main.tf delete mode 100644 tests/modules/apigee/fixture/variables.tf rename tests/modules/apigee/{fixture/test.instance_only.tfvars => instance_only.tfvars} (100%) rename tests/{fast/stages_multitenant/s1_resman_tenant/__init__.py => modules/apigee/instance_only.yaml} (54%) rename tests/modules/apigee/{fixture/test.no_instances.tfvars => no_instances.tfvars} (100%) create mode 100644 tests/modules/apigee/no_instances.yaml rename tests/modules/apigee/{fixture/test.organization_only.tfvars => organization_only.tfvars} (100%) rename tests/{fast/stages_multitenant/s0_bootstrap_tenant/__init__.py => modules/apigee/organization_only.yaml} (57%) delete mode 100644 tests/modules/apigee/test_plan.py rename tests/modules/{binauthz/test_plan.py => apigee/tftest.yaml} (69%) delete mode 100644 tests/modules/binauthz/__init__.py delete mode 100644 tests/modules/binauthz/fixture/main.tf delete mode 100644 tests/modules/binauthz/fixture/variables.tf diff --git a/tests/modules/apigee/__init__.py b/tests/modules/apigee/__init__.py deleted file mode 100644 index 6d6d1266c..000000000 --- a/tests/modules/apigee/__init__.py +++ /dev/null @@ -1,13 +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. diff --git a/tests/modules/apigee/fixture/test.all.tfvars b/tests/modules/apigee/all.tfvars similarity index 100% rename from tests/modules/apigee/fixture/test.all.tfvars rename to tests/modules/apigee/all.tfvars diff --git a/tests/modules/apigee/all.yaml b/tests/modules/apigee/all.yaml new file mode 100644 index 000000000..587d6ff58 --- /dev/null +++ b/tests/modules/apigee/all.yaml @@ -0,0 +1,83 @@ +# Copyright 2023 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. + +values: + google_apigee_endpoint_attachment.endpoint_attachments["endpoint-backend-1"]: + endpoint_attachment_id: endpoint-backend-1 + location: europe-west1 + service_attachment: projects/my-project-1/serviceAttachments/gkebackend1 + google_apigee_endpoint_attachment.endpoint_attachments["endpoint-backend-2"]: + endpoint_attachment_id: endpoint-backend-2 + location: europe-west1 + service_attachment: projects/my-project-2/serviceAttachments/gkebackend2 + google_apigee_envgroup.envgroups["prod"]: + hostnames: + - prod.example.com + name: prod + google_apigee_envgroup.envgroups["test"]: + hostnames: + - test.example.com + name: test + google_apigee_envgroup_attachment.envgroup_attachments["apis-prod-prod"]: + environment: apis-prod + google_apigee_envgroup_attachment.envgroup_attachments["apis-test-test"]: + environment: apis-test + google_apigee_environment.environments["apis-prod"]: + description: APIs prod + display_name: APIs prod + name: apis-prod + google_apigee_environment.environments["apis-test"]: + description: APIs Test + display_name: APIs test + name: apis-test + google_apigee_environment_iam_binding.binding["apis-prod-roles/viewer"]: + condition: [] + env_id: apis-prod + members: + - group:devops@myorg.com + role: roles/viewer + google_apigee_instance.instances["instance-prod-ew3"]: + description: Terraform-managed + disk_encryption_key_name: null + display_name: null + ip_range: 10.0.6.0/22,10.1.0.16/28 + location: europe-west3 + name: instance-prod-ew3 + google_apigee_instance.instances["instance-test-ew1"]: + description: Terraform-managed + disk_encryption_key_name: null + display_name: null + ip_range: 10.0.4.0/22,10.1.0.0/28 + location: europe-west1 + name: instance-test-ew1 + google_apigee_organization.organization[0]: + analytics_region: europe-west1 + authorized_network: my-vpc + billing_type: Pay-as-you-go + description: null + display_name: null + project_id: my-project + retention: DELETION_RETENTION_UNSPECIFIED + runtime_database_encryption_key_name: '123456789' + runtime_type: CLOUD + +counts: + google_apigee_endpoint_attachment: 2 + google_apigee_envgroup: 2 + google_apigee_envgroup_attachment: 2 + google_apigee_environment: 2 + google_apigee_environment_iam_binding: 1 + google_apigee_instance: 2 + google_apigee_instance_attachment: 2 + google_apigee_organization: 1 diff --git a/tests/modules/apigee/fixture/test.endpoint_attachment_only.tfvars b/tests/modules/apigee/endpoint_attachment_only.tfvars similarity index 100% rename from tests/modules/apigee/fixture/test.endpoint_attachment_only.tfvars rename to tests/modules/apigee/endpoint_attachment_only.tfvars diff --git a/tests/fast/stages_multitenant/__init__.py b/tests/modules/apigee/endpoint_attachment_only.yaml similarity index 60% rename from tests/fast/stages_multitenant/__init__.py rename to tests/modules/apigee/endpoint_attachment_only.yaml index 6d6d1266c..aa67380f4 100644 --- a/tests/fast/stages_multitenant/__init__.py +++ b/tests/modules/apigee/endpoint_attachment_only.yaml @@ -1,4 +1,4 @@ -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,3 +11,13 @@ # 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. + +values: + google_apigee_endpoint_attachment.endpoint_attachments["endpoint-backend-1"]: + endpoint_attachment_id: endpoint-backend-1 + location: europe-west1 + org_id: organizations/my-project + service_attachment: projects/my-project-1/serviceAttachments/gkebackend1 + +counts: + google_apigee_endpoint_attachment: 1 diff --git a/tests/modules/apigee/fixture/test.env_only.tfvars b/tests/modules/apigee/env_only.tfvars similarity index 100% rename from tests/modules/apigee/fixture/test.env_only.tfvars rename to tests/modules/apigee/env_only.tfvars diff --git a/tests/modules/apigee/env_only.yaml b/tests/modules/apigee/env_only.yaml new file mode 100644 index 000000000..3a5e1ec23 --- /dev/null +++ b/tests/modules/apigee/env_only.yaml @@ -0,0 +1,32 @@ +# Copyright 2023 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. + +values: + google_apigee_envgroup_attachment.envgroup_attachments["apis-test-test"]: + envgroup_id: test + environment: apis-test + timeouts: null + google_apigee_environment.environments["apis-test"]: + description: APIs Test + display_name: APIs test + name: apis-test + node_config: + - max_node_count: '5' + min_node_count: '2' + org_id: organizations/my-project + timeouts: null + +counts: + google_apigee_envgroup_attachment: 1 + google_apigee_environment: 1 diff --git a/tests/modules/apigee/fixture/test.env_only_with_api_proxy_type.tfvars b/tests/modules/apigee/env_only_with_api_proxy_type.tfvars similarity index 100% rename from tests/modules/apigee/fixture/test.env_only_with_api_proxy_type.tfvars rename to tests/modules/apigee/env_only_with_api_proxy_type.tfvars diff --git a/tests/modules/apigee/env_only_with_api_proxy_type.yaml b/tests/modules/apigee/env_only_with_api_proxy_type.yaml new file mode 100644 index 000000000..ba9371ab2 --- /dev/null +++ b/tests/modules/apigee/env_only_with_api_proxy_type.yaml @@ -0,0 +1,31 @@ +# Copyright 2023 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. + +values: + google_apigee_envgroup_attachment.envgroup_attachments["apis-test-test"]: + envgroup_id: test + environment: apis-test + google_apigee_environment.environments["apis-test"]: + api_proxy_type: PROGRAMMABLE + description: APIs Test + display_name: APIs test + name: apis-test + node_config: + - max_node_count: '5' + min_node_count: '2' + org_id: organizations/my-project + +counts: + google_apigee_envgroup_attachment: 1 + google_apigee_environment: 1 diff --git a/tests/modules/apigee/fixture/test.env_only_with_deployment_type.tfvars b/tests/modules/apigee/env_only_with_deployment_type.tfvars similarity index 100% rename from tests/modules/apigee/fixture/test.env_only_with_deployment_type.tfvars rename to tests/modules/apigee/env_only_with_deployment_type.tfvars diff --git a/tests/modules/apigee/env_only_with_deployment_type.yaml b/tests/modules/apigee/env_only_with_deployment_type.yaml new file mode 100644 index 000000000..f315f4633 --- /dev/null +++ b/tests/modules/apigee/env_only_with_deployment_type.yaml @@ -0,0 +1,34 @@ +# Copyright 2023 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. + +values: + google_apigee_envgroup_attachment.envgroup_attachments["apis-test-test"]: + envgroup_id: test + environment: apis-test + timeouts: null + google_apigee_environment.environments["apis-test"]: + deployment_type: ARCHIVE + description: APIs Test + display_name: APIs test + name: apis-test + node_config: + - max_node_count: '5' + min_node_count: '2' + org_id: organizations/my-project + timeouts: null + +counts: + google_apigee_envgroup_attachment: 1 + google_apigee_environment: 1 + diff --git a/tests/modules/apigee/fixture/test.envgroup_only.tfvars b/tests/modules/apigee/envgroup_only.tfvars similarity index 100% rename from tests/modules/apigee/fixture/test.envgroup_only.tfvars rename to tests/modules/apigee/envgroup_only.tfvars diff --git a/tests/blueprints/factories/__init__.py b/tests/modules/apigee/envgroup_only.yaml similarity index 72% rename from tests/blueprints/factories/__init__.py rename to tests/modules/apigee/envgroup_only.yaml index 6d6d1266c..58ee34c08 100644 --- a/tests/blueprints/factories/__init__.py +++ b/tests/modules/apigee/envgroup_only.yaml @@ -1,4 +1,4 @@ -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,3 +11,13 @@ # 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. + +values: + google_apigee_envgroup.envgroups["test"]: + hostnames: + - test.example.com + name: test + org_id: organizations/my-project + +counts: + google_apigee_envgroup: 1 diff --git a/tests/modules/apigee/fixture/main.tf b/tests/modules/apigee/fixture/main.tf deleted file mode 100644 index 7ab25f733..000000000 --- a/tests/modules/apigee/fixture/main.tf +++ /dev/null @@ -1,25 +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. - */ - -module "test" { - source = "../../../../modules/apigee" - project_id = var.project_id - organization = var.organization - envgroups = var.envgroups - environments = var.environments - instances = var.instances - endpoint_attachments = var.endpoint_attachments -} diff --git a/tests/modules/apigee/fixture/variables.tf b/tests/modules/apigee/fixture/variables.tf deleted file mode 100644 index 00961aac2..000000000 --- a/tests/modules/apigee/fixture/variables.tf +++ /dev/null @@ -1,81 +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. - */ - -variable "endpoint_attachments" { - description = "Endpoint attachments." - type = map(object({ - region = string - service_attachment = string - })) - default = null -} - -variable "envgroups" { - description = "Environment groups (NAME => [HOSTNAMES])." - type = map(list(string)) - default = null -} - -variable "environments" { - description = "Environments." - type = map(object({ - display_name = optional(string) - description = optional(string, "Terraform-managed") - deployment_type = optional(string) - api_proxy_type = optional(string) - node_config = optional(object({ - min_node_count = optional(number) - max_node_count = optional(number) - })) - iam = optional(map(list(string))) - envgroups = list(string) - })) - default = null -} - -variable "instances" { - description = "Instances." - type = map(object({ - display_name = optional(string) - description = optional(string, "Terraform-managed") - region = string - environments = list(string) - runtime_ip_cidr_range = string - troubleshooting_ip_cidr_range = string - disk_encryption_key = optional(string) - consumer_accept_list = optional(list(string)) - })) - default = null -} - -variable "organization" { - description = "Apigee organization. If set to null the organization must already exist." - type = object({ - display_name = optional(string) - description = optional(string, "Terraform-managed") - authorized_network = optional(string) - runtime_type = optional(string, "CLOUD") - billing_type = optional(string) - database_encryption_key = optional(string) - analytics_region = optional(string, "europe-west1") - }) - default = null -} - -variable "project_id" { - description = "Project ID." - type = string -} diff --git a/tests/modules/apigee/fixture/test.instance_only.tfvars b/tests/modules/apigee/instance_only.tfvars similarity index 100% rename from tests/modules/apigee/fixture/test.instance_only.tfvars rename to tests/modules/apigee/instance_only.tfvars diff --git a/tests/fast/stages_multitenant/s1_resman_tenant/__init__.py b/tests/modules/apigee/instance_only.yaml similarity index 54% rename from tests/fast/stages_multitenant/s1_resman_tenant/__init__.py rename to tests/modules/apigee/instance_only.yaml index 6d6d1266c..5150e979c 100644 --- a/tests/fast/stages_multitenant/s1_resman_tenant/__init__.py +++ b/tests/modules/apigee/instance_only.yaml @@ -1,4 +1,4 @@ -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,3 +11,16 @@ # 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. + +values: + google_apigee_instance.instances["instance-test-ew1"]: + ip_range: 10.0.4.0/22,10.1.1.0.0/28 + location: europe-west1 + name: instance-test-ew1 + org_id: organizations/my-project + google_apigee_instance_attachment.instance_attachments["instance-test-ew1-apis-test"]: + environment: organizations/my-project/environments/apis-test + +counts: + google_apigee_instance: 1 + google_apigee_instance_attachment: 1 diff --git a/tests/modules/apigee/fixture/test.no_instances.tfvars b/tests/modules/apigee/no_instances.tfvars similarity index 100% rename from tests/modules/apigee/fixture/test.no_instances.tfvars rename to tests/modules/apigee/no_instances.tfvars diff --git a/tests/modules/apigee/no_instances.yaml b/tests/modules/apigee/no_instances.yaml new file mode 100644 index 000000000..ce509047b --- /dev/null +++ b/tests/modules/apigee/no_instances.yaml @@ -0,0 +1,51 @@ +# Copyright 2023 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. + +values: + google_apigee_envgroup.envgroups["prod"]: + hostnames: + - prod.example.com + name: prod + google_apigee_envgroup.envgroups["test"]: + hostnames: + - test.example.com + name: test + google_apigee_envgroup_attachment.envgroup_attachments["apis-prod-prod"]: + environment: apis-prod + google_apigee_envgroup_attachment.envgroup_attachments["apis-test-test"]: + environment: apis-test + google_apigee_environment.environments["apis-prod"]: + description: APIs prod + display_name: APIs prod + name: apis-prod + google_apigee_environment.environments["apis-test"]: + description: APIs Test + display_name: APIs test + name: apis-test + google_apigee_organization.organization[0]: + analytics_region: europe-west1 + authorized_network: my-vpc + billing_type: PAYG + description: null + display_name: null + project_id: my-project + retention: DELETION_RETENTION_UNSPECIFIED + runtime_database_encryption_key_name: '123456789' + runtime_type: CLOUD + +counts: + google_apigee_envgroup: 2 + google_apigee_envgroup_attachment: 2 + google_apigee_environment: 2 + google_apigee_organization: 1 diff --git a/tests/modules/apigee/fixture/test.organization_only.tfvars b/tests/modules/apigee/organization_only.tfvars similarity index 100% rename from tests/modules/apigee/fixture/test.organization_only.tfvars rename to tests/modules/apigee/organization_only.tfvars diff --git a/tests/fast/stages_multitenant/s0_bootstrap_tenant/__init__.py b/tests/modules/apigee/organization_only.yaml similarity index 57% rename from tests/fast/stages_multitenant/s0_bootstrap_tenant/__init__.py rename to tests/modules/apigee/organization_only.yaml index 6d6d1266c..8eee04fcc 100644 --- a/tests/fast/stages_multitenant/s0_bootstrap_tenant/__init__.py +++ b/tests/modules/apigee/organization_only.yaml @@ -1,4 +1,4 @@ -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,3 +11,18 @@ # 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. + +values: + google_apigee_organization.organization[0]: + analytics_region: europe-west1 + authorized_network: my-vpc + billing_type: PAYG + description: null + display_name: null + project_id: my-project + retention: DELETION_RETENTION_UNSPECIFIED + runtime_database_encryption_key_name: '123456789' + runtime_type: CLOUD + +counts: + google_apigee_organization: 1 diff --git a/tests/modules/apigee/test_plan.py b/tests/modules/apigee/test_plan.py deleted file mode 100644 index d16ef2963..000000000 --- a/tests/modules/apigee/test_plan.py +++ /dev/null @@ -1,95 +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. - -import collections - -def test_all(plan_runner): - "Test that creates all resources." - _, resources = plan_runner(tf_var_file='test.all.tfvars') - counts = collections.Counter(f'{r["type"]}.{r["name"]}' for r in resources) - assert counts == { - 'google_apigee_organization.organization': 1, - 'google_apigee_envgroup.envgroups': 2, - 'google_apigee_environment.environments': 2, - 'google_apigee_envgroup_attachment.envgroup_attachments': 2, - 'google_apigee_instance.instances': 2, - 'google_apigee_instance_attachment.instance_attachments': 2, - 'google_apigee_endpoint_attachment.endpoint_attachments': 2, - 'google_apigee_environment_iam_binding.binding': 1 - } - -def test_organization_only(plan_runner): - "Test that creates only an organization." - _, resources = plan_runner(tf_var_file='test.organization_only.tfvars') - counts = collections.Counter(f'{r["type"]}.{r["name"]}' for r in resources) - assert counts == { - 'google_apigee_organization.organization': 1 - } - -def test_envgroup_only(plan_runner): - "Test that creates only an environment group in an existing organization." - _, resources = plan_runner(tf_var_file='test.envgroup_only.tfvars') - counts = collections.Counter(f'{r["type"]}.{r["name"]}' for r in resources) - assert counts == { - 'google_apigee_envgroup.envgroups': 1, - } - -def test_env_only(plan_runner): - "Test that creates an environment in an existing environment group." - _, resources = plan_runner(tf_var_file='test.env_only.tfvars') - counts = collections.Counter(f'{r["type"]}.{r["name"]}' for r in resources) - assert counts == { - 'google_apigee_environment.environments': 1, - 'google_apigee_envgroup_attachment.envgroup_attachments': 1, - } - -def test_env_only_with_deployment_type(plan_runner): - "Test that creates an environment in an existing environment group, with deployment_type set." - _, resources = plan_runner(tf_var_file='test.env_only_with_deployment_type.tfvars') - assert [r['values'].get('deployment_type') for r in resources - ] == [None, 'ARCHIVE'] - -def test_env_only_with_api_proxy_type(plan_runner): - "Test that creates an environment in an existing environment group, with api_proxy_type set." - _, resources = plan_runner(tf_var_file='test.env_only_with_api_proxy_type.tfvars') - assert [r['values'].get('api_proxy_type') for r in resources - ] == [None, 'PROGRAMMABLE'] - -def test_instance_only(plan_runner): - "Test that creates only an instance." - _, resources = plan_runner(tf_var_file='test.instance_only.tfvars') - counts = collections.Counter(f'{r["type"]}.{r["name"]}' for r in resources) - assert counts == { - 'google_apigee_instance.instances': 1, - 'google_apigee_instance_attachment.instance_attachments': 1 - } - -def test_endpoint_attachment_only(plan_runner): - "Test that creates only an instance." - _, resources = plan_runner(tf_var_file='test.endpoint_attachment_only.tfvars') - counts = collections.Counter(f'{r["type"]}.{r["name"]}' for r in resources) - assert counts == { - 'google_apigee_endpoint_attachment.endpoint_attachments': 1, - } - -def test_no_instances(plan_runner): - "Test that creates everything but the instances." - _, resources = plan_runner(tf_var_file='test.no_instances.tfvars') - counts = collections.Counter(f'{r["type"]}.{r["name"]}' for r in resources) - assert counts == { - 'google_apigee_organization.organization': 1, - 'google_apigee_envgroup.envgroups': 2, - 'google_apigee_environment.environments': 2, - 'google_apigee_envgroup_attachment.envgroup_attachments': 2, - } diff --git a/tests/modules/binauthz/test_plan.py b/tests/modules/apigee/tftest.yaml similarity index 69% rename from tests/modules/binauthz/test_plan.py rename to tests/modules/apigee/tftest.yaml index 955504258..9b381d15d 100644 --- a/tests/modules/binauthz/test_plan.py +++ b/tests/modules/apigee/tftest.yaml @@ -1,4 +1,4 @@ -# Copyright 2022 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,13 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest +module: modules/apigee -@pytest.fixture -def resources(plan_runner): - _, resources = plan_runner() - return resources - -def test_resource_count(resources): - "Test number of resources created." - assert len(resources) == 4 +tests: + all: + endpoint_attachment_only: + env_only: + env_only_with_api_proxy_type: + env_only_with_deployment_type: + envgroup_only: + instance_only: + no_instances: + organization_only: diff --git a/tests/modules/binauthz/__init__.py b/tests/modules/binauthz/__init__.py deleted file mode 100644 index 6d6d1266c..000000000 --- a/tests/modules/binauthz/__init__.py +++ /dev/null @@ -1,13 +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. diff --git a/tests/modules/binauthz/fixture/main.tf b/tests/modules/binauthz/fixture/main.tf deleted file mode 100644 index 95f76d634..000000000 --- a/tests/modules/binauthz/fixture/main.tf +++ /dev/null @@ -1,23 +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. - */ - -module "test" { - source = "../../../../modules/binauthz" - project_id = var.project_id - global_policy_evaluation_mode = var.global_policy_evaluation_mode - default_admission_rule = var.default_admission_rule - attestors_config = var.attestors_config -} diff --git a/tests/modules/binauthz/fixture/variables.tf b/tests/modules/binauthz/fixture/variables.tf deleted file mode 100644 index 327ced252..000000000 --- a/tests/modules/binauthz/fixture/variables.tf +++ /dev/null @@ -1,103 +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. - */ - -variable "project_id" { - type = string - default = "my_project" -} - -variable "global_policy_evaluation_mode" { - type = string - default = null -} - -variable "admission_whitelist_patterns" { - type = list(string) - default = [ - "gcr.io/google_containers/*" - ] -} - -variable "default_admission_rule" { - type = object({ - evaluation_mode = string - enforcement_mode = string - attestors = list(string) - }) - default = { - evaluation_mode = "ALWAYS_ALLOW" - enforcement_mode = "ENFORCED_BLOCK_AND_AUDIT_LOG" - attestors = null - } -} - -variable "cluster_admission_rules" { - type = map(object({ - evaluation_mode = string - enforcement_mode = string - attestors = list(string) - })) - default = { - "europe-west1-c.cluster" = { - evaluation_mode = "REQUIRE_ATTESTATION" - enforcement_mode = "ENFORCED_BLOCK_AND_AUDIT_LOG" - attestors = ["test"] - } - } -} - -variable "attestors_config" { - description = "Attestors configuration" - type = map(object({ - note_reference = string - iam = map(list(string)) - pgp_public_keys = list(string) - pkix_public_keys = list(object({ - id = string - public_key_pem = string - signature_algorithm = string - })) - })) - default = { - "test" : { - note_reference = null - pgp_public_keys = [ - <