Migrate service-directory tests
This commit is contained in:
@@ -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.
|
||||
35
tests/modules/service_directory/examples/dns.yaml
Normal file
35
tests/modules/service_directory/examples/dns.yaml
Normal file
@@ -0,0 +1,35 @@
|
||||
# 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.dns-sd.google_dns_managed_zone.non-public[0]:
|
||||
dns_name: apps.example.org.
|
||||
visibility: private
|
||||
module.service-directory.google_service_directory_endpoint.default["app1/one"]:
|
||||
address: 127.0.0.1
|
||||
endpoint_id: one
|
||||
port: 80
|
||||
module.service-directory.google_service_directory_namespace.default:
|
||||
location: europe-west1
|
||||
namespace_id: apps
|
||||
project: my-project
|
||||
module.service-directory.google_service_directory_service.default["app1"]:
|
||||
service_id: app1
|
||||
|
||||
counts:
|
||||
google_dns_managed_zone: 1
|
||||
google_service_directory_endpoint: 1
|
||||
google_service_directory_namespace: 1
|
||||
google_service_directory_namespace_iam_binding: 1
|
||||
google_service_directory_service: 1
|
||||
36
tests/modules/service_directory/examples/services.yaml
Normal file
36
tests/modules/service_directory/examples/services.yaml
Normal file
@@ -0,0 +1,36 @@
|
||||
# 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.service-directory.google_service_directory_endpoint.default["one/first"]:
|
||||
address: 127.0.0.1
|
||||
endpoint_id: first
|
||||
port: 80
|
||||
module.service-directory.google_service_directory_endpoint.default["one/second"]:
|
||||
address: 127.0.0.2
|
||||
endpoint_id: second
|
||||
port: 80
|
||||
module.service-directory.google_service_directory_namespace.default:
|
||||
location: europe-west1
|
||||
namespace_id: sd-1
|
||||
project: my-project
|
||||
module.service-directory.google_service_directory_service.default["one"]:
|
||||
metadata: null
|
||||
service_id: one
|
||||
|
||||
counts:
|
||||
google_service_directory_endpoint: 2
|
||||
google_service_directory_namespace: 1
|
||||
google_service_directory_service: 1
|
||||
google_service_directory_service_iam_binding: 1
|
||||
33
tests/modules/service_directory/examples/simple.yaml
Normal file
33
tests/modules/service_directory/examples/simple.yaml
Normal file
@@ -0,0 +1,33 @@
|
||||
# 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.service-directory.google_service_directory_namespace.default:
|
||||
labels: null
|
||||
location: europe-west1
|
||||
namespace_id: sd-1
|
||||
project: my-project
|
||||
module.service-directory.google_service_directory_namespace_iam_binding.default["roles/servicedirectory.editor"]:
|
||||
condition: []
|
||||
members:
|
||||
- serviceAccount:namespace-editor@example.com
|
||||
role: roles/servicedirectory.editor
|
||||
|
||||
counts:
|
||||
google_service_directory_namespace: 1
|
||||
google_service_directory_namespace_iam_binding: 1
|
||||
modules: 1
|
||||
resources: 2
|
||||
|
||||
outputs: {}
|
||||
@@ -1,55 +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/service-directory"
|
||||
project_id = "my-project"
|
||||
location = "europe-west1"
|
||||
name = "ns-test"
|
||||
iam = {
|
||||
"roles/servicedirectory.viewer" = [
|
||||
"serviceAccount:service-editor.example.com"
|
||||
]
|
||||
}
|
||||
services = {
|
||||
srv-one = {
|
||||
endpoints = ["alpha", "beta"]
|
||||
metadata = null
|
||||
}
|
||||
srv-two = {
|
||||
endpoints = ["alpha"]
|
||||
metadata = null
|
||||
}
|
||||
}
|
||||
service_iam = {
|
||||
srv-one = {
|
||||
"roles/servicedirectory.editor" = [
|
||||
"serviceAccount:service-editor.example.com"
|
||||
]
|
||||
}
|
||||
srv-two = {
|
||||
"roles/servicedirectory.admin" = [
|
||||
"serviceAccount:service-editor.example.com"
|
||||
]
|
||||
}
|
||||
}
|
||||
endpoint_config = {
|
||||
"srv-one/alpha" = { address = "127.0.0.1", port = 80, metadata = {} }
|
||||
"srv-one/beta" = { address = "127.0.0.2", port = 80, metadata = {} }
|
||||
"srv-two/alpha" = { address = "127.0.0.3", port = 80, metadata = {} }
|
||||
}
|
||||
labels = var.labels
|
||||
}
|
||||
@@ -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 "labels" {
|
||||
type = map(string)
|
||||
default = {}
|
||||
}
|
||||
@@ -1,52 +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) == 9
|
||||
|
||||
|
||||
def test_iam(resources):
|
||||
"Test IAM binding resources."
|
||||
bindings = [r['values'] for r in resources if r['type']
|
||||
== 'google_service_directory_namespace_iam_binding']
|
||||
assert len(bindings) == 1
|
||||
assert bindings[0]['role'] == 'roles/servicedirectory.viewer'
|
||||
|
||||
|
||||
def test_services(resources):
|
||||
"Test service resources."
|
||||
services = [r['values'] for r in resources if r['type']
|
||||
== 'google_service_directory_service']
|
||||
assert len(services) == 2
|
||||
assert set(s['service_id'] for s in services) == set(['srv-one', 'srv-two'])
|
||||
|
||||
|
||||
def test_service_iam(resources):
|
||||
"Test service IAM binding resources."
|
||||
bindings = [r['values'] for r in resources if r['type']
|
||||
== 'google_service_directory_service_iam_binding']
|
||||
assert len(bindings) == 2
|
||||
assert set(b['role'] for b in bindings) == set([
|
||||
'roles/servicedirectory.admin', 'roles/servicedirectory.editor'
|
||||
])
|
||||
Reference in New Issue
Block a user