Allow blueprints to be tested from README files without examples.

This commit is contained in:
Julio Castillo 2023-02-08 19:13:55 +01:00
parent 7bfa2dbd34
commit 71e96dfdee
7 changed files with 33 additions and 106 deletions

View File

@ -22,6 +22,23 @@ Clone this repository or [open it in cloud shell](https://ssh.cloud.google.com/c
curl -v http://<IP_ADDRESS>/hello
Once done testing, you can clean up resources by running `terraform destroy`.
<!--
module "test" {
source = "./fabric/blueprints/serverless/api-gateway"
project_create = {
billing_account_id = "123456789"
parent = "organizations/123456789"
}
project_id = "project-1"
regions = [
"europe-west1",
"europe-west2"
]
}
# tftest modules=8 resources=34
-->
<!-- BEGIN TFDOC -->
## Variables

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,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,22 +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 = "../../../../../blueprints/serverless/api-gateway"
project_create = var.project_create
project_id = var.project_id
regions = var.regions
}

View File

@ -1,39 +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_create" {
type = object({
billing_account_id = string
parent = string
})
default = {
billing_account_id = "123456789"
parent = "organizations/123456789"
}
}
variable "project_id" {
type = string
default = "project-1"
}
variable "regions" {
type = list(string)
default = [
"europe-west1",
"europe-west2"
]
}

View File

@ -1,19 +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_resources(e2e_plan_runner):
"Test that plan works and the numbers of resources is as expected."
modules, resources = e2e_plan_runner()
assert len(modules) == 7
assert len(resources) == 32

View File

@ -68,6 +68,22 @@ def pytest_generate_tests(metafunc):
name += f' {index}'
ids.append(name)
examples.append(Example(name, code, path, files[last_header]))
if isinstance(child, marko.block.HTMLBlock):
# parse tftest blocks from HTML blocks comment (user by
# blueprints to test without having to create wrapper
# modules)
code = child.children
if code.startswith('<!--') and '# tftest' in code:
index += 1
path = module.relative_to(FABRIC_ROOT)
name = f'{path}:comment block'
code = code.removeprefix('<!--').removesuffix('-->\n')
if index > 1:
name += f' {index}'
ids.append(name)
# TODO: examples in HTML comment blocks can't use
# tftest-file
examples.append(Example(name, code, path, {}))
elif isinstance(child, marko.block.Heading):
last_header = child.children[0].children
index = 0