Migrate source repository tests
This commit is contained in:
parent
f5e1717319
commit
ed49f3db39
|
@ -15,7 +15,7 @@ module "repo" {
|
|||
"roles/source.reader" = ["user:foo@example.com"]
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=2
|
||||
# tftest modules=1 resources=2 inventory=simple.yaml
|
||||
```
|
||||
|
||||
### Repository with Cloud Build trigger
|
||||
|
@ -41,7 +41,7 @@ module "repo" {
|
|||
}
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=2
|
||||
# tftest modules=1 resources=2 inventory=trigger.yaml
|
||||
```
|
||||
|
||||
<!-- TFDOC OPTS files:1 -->
|
||||
|
|
|
@ -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,20 @@
|
|||
# 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.repo.google_sourcerepo_repository.default:
|
||||
name: my-repo
|
||||
project: my-project
|
||||
pubsub_configs: []
|
||||
module.repo.google_sourcerepo_repository_iam_binding.authoritative["roles/source.reader"]:
|
||||
condition: []
|
||||
members:
|
||||
- user:foo@example.com
|
||||
project: my-project
|
||||
repository: my-repo
|
||||
role: roles/source.reader
|
||||
|
||||
counts:
|
||||
google_sourcerepo_repository: 1
|
||||
google_sourcerepo_repository_iam_binding: 1
|
|
@ -0,0 +1,40 @@
|
|||
# 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.repo.google_cloudbuild_trigger.default["foo"]:
|
||||
filename: ci/workflow-foo.yaml
|
||||
included_files:
|
||||
- '**/*tf'
|
||||
location: global
|
||||
name: foo
|
||||
project: my-project
|
||||
substitutions:
|
||||
BAR: '1'
|
||||
trigger_template:
|
||||
- branch_name: main
|
||||
commit_sha: null
|
||||
dir: null
|
||||
invert_regex: null
|
||||
repo_name: my-repo
|
||||
tag_name: null
|
||||
webhook_config: []
|
||||
module.repo.google_sourcerepo_repository.default:
|
||||
name: my-repo
|
||||
project: my-project
|
||||
pubsub_configs: []
|
||||
|
||||
counts:
|
||||
google_cloudbuild_trigger: 1
|
||||
google_sourcerepo_repository: 1
|
|
@ -1,65 +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 "group_iam" {
|
||||
type = any
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "iam" {
|
||||
type = any
|
||||
default = {}
|
||||
nullable = false
|
||||
}
|
||||
|
||||
variable "iam_additive" {
|
||||
type = any
|
||||
default = {}
|
||||
nullable = false
|
||||
}
|
||||
|
||||
variable "iam_additive_members" {
|
||||
type = any
|
||||
default = {}
|
||||
}
|
||||
|
||||
variable "name" {
|
||||
description = "Repository name."
|
||||
type = string
|
||||
default = "test"
|
||||
}
|
||||
|
||||
variable "project_id" {
|
||||
description = "Project used for resources."
|
||||
type = string
|
||||
default = "test"
|
||||
}
|
||||
|
||||
variable "triggers" {
|
||||
type = any
|
||||
default = null
|
||||
}
|
||||
|
||||
module "test" {
|
||||
source = "../../../../modules/source-repository"
|
||||
project_id = var.project_id
|
||||
name = var.name
|
||||
group_iam = var.group_iam
|
||||
iam = var.iam
|
||||
iam_additive = var.iam_additive
|
||||
iam_additive_members = var.iam_additive_members
|
||||
triggers = var.triggers
|
||||
}
|
|
@ -1,60 +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.
|
||||
|
||||
|
||||
def test_resource_count(plan_runner):
|
||||
'Test number of resources created.'
|
||||
_, resources = plan_runner()
|
||||
assert len(resources) == 1
|
||||
|
||||
|
||||
def test_iam(plan_runner):
|
||||
'Test IAM binding resources.'
|
||||
group_iam = '{"fooers@example.org"=["roles/owner"]}'
|
||||
iam = '''{
|
||||
"roles/editor" = ["user:a@example.org", "user:b@example.org"]
|
||||
"roles/owner" = ["user:c@example.org"]
|
||||
}'''
|
||||
_, resources = plan_runner(group_iam=group_iam, iam=iam)
|
||||
bindings = {
|
||||
r['values']['role']: r['values']['members']
|
||||
for r in resources
|
||||
if r['type'] == 'google_sourcerepo_repository_iam_binding'
|
||||
}
|
||||
assert bindings == {
|
||||
'roles/editor': ['user:a@example.org', 'user:b@example.org'],
|
||||
'roles/owner': ['group:fooers@example.org', 'user:c@example.org']
|
||||
}
|
||||
|
||||
|
||||
def test_triggers(plan_runner):
|
||||
'Test trigger resources.'
|
||||
triggers = '''{
|
||||
foo = {
|
||||
filename = "ci/foo.yaml"
|
||||
included_files = ["**/*yaml"]
|
||||
service_account = null
|
||||
substitutions = null
|
||||
template = {
|
||||
branch_name = null
|
||||
project_id = null
|
||||
tag_name = "foo"
|
||||
}
|
||||
}
|
||||
}'''
|
||||
_, resources = plan_runner(triggers=triggers)
|
||||
triggers = [
|
||||
r['index'] for r in resources if r['type'] == 'google_cloudbuild_trigger'
|
||||
]
|
||||
assert triggers == ['foo']
|
Loading…
Reference in New Issue