Migrate endpoints tests

This commit is contained in:
Julio Castillo
2023-04-14 17:19:53 +02:00
parent 3dd27b6248
commit 0150e97e51
7 changed files with 33 additions and 106 deletions

View File

@@ -18,7 +18,7 @@ module "endpoint" {
]
}
}
# tftest modules=1 resources=2 files=openapi
# tftest modules=1 resources=2 files=openapi inventory=simple.yaml
```
```yaml

View File

@@ -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.

View File

@@ -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:
module.endpoint.google_endpoints_service.default:
openapi_config: "# tftest-file id=openapi path=configs/endpoints/openapi.yaml\n\
swagger: \"2.0\"\ninfo:\n description: \"A simple Google Cloud Endpoints API\
\ example.\"\n title: \"Endpoints Example\"\n version: \"1.0.0\"\nhost: \"\
echo-api.endpoints.YOUR-PROJECT-ID.cloud.goog\"\n"
project: my-project
service_name: YOUR-API.endpoints.YOUR-PROJECT-ID.cloud.goog
module.endpoint.google_endpoints_service_iam_binding.default["servicemanagement.serviceController"]:
condition: []
members:
- serviceAccount:123456890-compute@developer.gserviceaccount.com
role: servicemanagement.serviceController
service_name: YOUR-API.endpoints.YOUR-PROJECT-ID.cloud.goog
counts:
google_endpoints_service: 1
google_endpoints_service_iam_binding: 1

View File

@@ -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/endpoints"
project_id = "my-project"
service_name = var.service_name
openapi_config = { "yaml_path" = "openapi.yaml" }
iam = {
"roles/servicemanagement.serviceController" = ["user:me@example.com"]
}
}

View File

@@ -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.

View File

@@ -1,20 +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 "service_name" {
type = string
default = "foo.endpoints.test.cloud.goog"
}

View File

@@ -1,34 +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 pytest
@pytest.fixture
def resources(plan_runner):
_, resources = plan_runner()
return resources
def test_resource_count(resources):
"Test number of resources created."
assert len(resources) == 2
def test_iam(resources):
"Test IAM binding resources."
bindings = [r['values'] for r in resources if r['type']
== 'google_endpoints_service_iam_binding']
assert len(bindings) == 1
assert bindings[0]['role'] == 'roles/servicemanagement.serviceController'