From c4763740979b40f3056d888872854ba83e3a9968 Mon Sep 17 00:00:00 2001 From: abhishek kumar tiwari Date: Mon, 12 Aug 2024 13:18:05 +0000 Subject: [PATCH] Use blueprint test instead of ruby tests (#4) * Use blueprint test instead of ruby tests * Add validation for variable type of serverless_neg_backends --- autogen/main.tf.tmpl | 2 + autogen/variables.tf.tmpl | 16 +++++++- build/int.cloudbuild.yaml | 21 ++++++++++ .../README.md | 4 -- .../cloudrun-implicit-serverless-neg/main.tf | 23 +++-------- .../variables.tf | 20 ---------- examples/cloudrun/main.tf | 3 +- kitchen.yml | 11 ------ modules/serverless_negs/README.md | 2 +- modules/serverless_negs/main.tf | 2 + modules/serverless_negs/metadata.yaml | 4 +- modules/serverless_negs/variables.tf | 14 ++++++- .../cloudrun-implicit-serverless-neg/main.tf | 22 ----------- .../outputs.tf | 24 ------------ .../variables.tf | 20 ---------- .../versions.tf | 19 --------- .../cloudrun_implicit_test.go | 38 ++++++++++++++++++ .../controls/http.rb | 21 ---------- .../inspec.yml | 22 ----------- test/integration/testhelper.go | 39 +++++++++++++++++++ 20 files changed, 138 insertions(+), 189 deletions(-) delete mode 100644 test/fixtures/cloudrun-implicit-serverless-neg/main.tf delete mode 100644 test/fixtures/cloudrun-implicit-serverless-neg/outputs.tf delete mode 100644 test/fixtures/cloudrun-implicit-serverless-neg/variables.tf delete mode 100644 test/fixtures/cloudrun-implicit-serverless-neg/versions.tf create mode 100644 test/integration/cloudrun-implicit-serverless-neg/cloudrun_implicit_test.go delete mode 100644 test/integration/cloudrun-implicit-serverless-neg/controls/http.rb delete mode 100644 test/integration/cloudrun-implicit-serverless-neg/inspec.yml create mode 100644 test/integration/testhelper.go diff --git a/autogen/main.tf.tmpl b/autogen/main.tf.tmpl index d0491473..632f78dd 100644 --- a/autogen/main.tf.tmpl +++ b/autogen/main.tf.tmpl @@ -358,6 +358,8 @@ resource "google_compute_region_network_endpoint_group" "serverless_negs" { } ]...) + provider = google-beta + project = var.project name = "${each.key}" network_endpoint_type = "SERVERLESS" region = each.value.region diff --git a/autogen/variables.tf.tmpl b/autogen/variables.tf.tmpl index 21d036de..b3187295 100644 --- a/autogen/variables.tf.tmpl +++ b/autogen/variables.tf.tmpl @@ -83,6 +83,18 @@ variable "target_service_accounts" { variable "backends" { description = "Map backend indices to list of backend maps." + {% if serverless %} + validation { + condition = alltrue([ + for backend_key, backend_value in var.backends : + alltrue([ + for neg_backend in backend_value.serverless_neg_backends : + contains(["cloud-run", "cloud-function", "app-engine"], neg_backend.type) + ]) + ]) + error_message = "serverless_neg_backend type should be either 'cloud-run' or 'cloud-function' or 'app-engine'." + } + {% endif %} type = map(object({ {% if not serverless %}{# not necessary for serverless as default port_name=http, protocol=HTTP #} port = optional(number) @@ -152,11 +164,11 @@ variable "backends" { // serverless_neg_backends is mutually exclusive to groups.There can only be one serverless neg per region // with one of cloud-run, cloud-functions and app-engine as service. - serverless_neg_backends = list(object({ + serverless_neg_backends = optional(list(object({ region = string, type = string, // cloud-run, cloud-function and app-engine service = object({ name : string, version : optional(string) }) - })) + })), []) {% endif %} iap_config = object({ diff --git a/build/int.cloudbuild.yaml b/build/int.cloudbuild.yaml index c5449e18..75645e24 100644 --- a/build/int.cloudbuild.yaml +++ b/build/int.cloudbuild.yaml @@ -24,6 +24,27 @@ steps: - 'TF_VAR_org_id=$_ORG_ID' - 'TF_VAR_folder_id=$_FOLDER_ID' - 'TF_VAR_billing_account=$_BILLING_ACCOUNT' +# cloudrun implicit serverless negs +- id: init-all + waitFor: + - prepare + name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' + args: ['/bin/bash', '-c', 'cft test run all --stage init --verbose'] +- id: apply cloudrun-implicit + waitFor: + - init-all + name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' + args: ['/bin/bash', '-c', 'cft test run TestCloudrunImplicit --stage apply --verbose'] +- id: verify cloudrun-implicit + waitFor: + - apply cloudrun-implicit + name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' + args: ['/bin/bash', '-c', 'sleep 720 && cft test run TestCloudrunImplicit --stage verify --verbose'] +- id: teardown cloudrun-implicit + waitFor: + - verify cloudrun-implicit + name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' + args: ['/bin/bash', '-c', 'cft test run TestCloudrunImplicit --stage teardown --verbose'] - id: create name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS' args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && kitchen_do create'] diff --git a/examples/cloudrun-implicit-serverless-neg/README.md b/examples/cloudrun-implicit-serverless-neg/README.md index 8ab0fcc4..7f826749 100644 --- a/examples/cloudrun-implicit-serverless-neg/README.md +++ b/examples/cloudrun-implicit-serverless-neg/README.md @@ -96,11 +96,7 @@ redirect HTTP traffic to HTTPS. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| -| domain | Domain name to run the load balancer on. Used if `ssl` is `true`. | `string` | n/a | yes | -| lb\_name | Name for load balancer and associated resources | `string` | `"tf-cr-lb-1"` | no | | project\_id | n/a | `string` | n/a | yes | -| region | Location for load balancer and Cloud Run resources | `string` | `"us-central1"` | no | -| ssl | Run load balancer on HTTPS and provision managed certificate with provided `domain`. | `bool` | `true` | no | ## Outputs diff --git a/examples/cloudrun-implicit-serverless-neg/main.tf b/examples/cloudrun-implicit-serverless-neg/main.tf index f8aa620d..724b2d8f 100644 --- a/examples/cloudrun-implicit-serverless-neg/main.tf +++ b/examples/cloudrun-implicit-serverless-neg/main.tf @@ -14,32 +14,22 @@ * limitations under the License. */ -provider "google" { - project = var.project_id -} - -provider "google-beta" { - project = var.project_id -} - -# [START cloudloadbalancing_ext_http_cloudrun] module "lb-http" { source = "terraform-google-modules/lb-http/google//modules/serverless_negs" version = "~> 10.0" - name = var.lb_name + name = "tf-cr-lb-1" project = var.project_id - ssl = var.ssl - managed_ssl_certificate_domains = [var.domain] - https_redirect = var.ssl - labels = { "example-label" = "cloud-run-example" } + ssl = false + https_redirect = false + labels = { "example-label" = "cloud-run-example" } backends = { default = { description = null groups = [] - serverless_neg_backends = [{ region : var.region, type : "cloud-run", service : { name : google_cloud_run_service.default.name } }] + serverless_neg_backends = [{ region : "us-central1", type : "cloud-run", service : { name : google_cloud_run_service.default.name } }] enable_cdn = false iap_config = { @@ -54,7 +44,7 @@ module "lb-http" { resource "google_cloud_run_service" "default" { name = "example-1" - location = var.region + location = "us-central1" project = var.project_id template { @@ -80,4 +70,3 @@ resource "google_cloud_run_service_iam_member" "public-access" { role = "roles/run.invoker" member = "allUsers" } -# [END cloudloadbalancing_ext_http_cloudrun] diff --git a/examples/cloudrun-implicit-serverless-neg/variables.tf b/examples/cloudrun-implicit-serverless-neg/variables.tf index 147e0ccb..47b5cda7 100644 --- a/examples/cloudrun-implicit-serverless-neg/variables.tf +++ b/examples/cloudrun-implicit-serverless-neg/variables.tf @@ -18,23 +18,3 @@ variable "project_id" { type = string } -variable "region" { - description = "Location for load balancer and Cloud Run resources" - default = "us-central1" -} - -variable "ssl" { - description = "Run load balancer on HTTPS and provision managed certificate with provided `domain`." - type = bool - default = true -} - -variable "domain" { - description = "Domain name to run the load balancer on. Used if `ssl` is `true`." - type = string -} - -variable "lb_name" { - description = "Name for load balancer and associated resources" - default = "tf-cr-lb-1" -} diff --git a/examples/cloudrun/main.tf b/examples/cloudrun/main.tf index 92773b2f..34e59559 100644 --- a/examples/cloudrun/main.tf +++ b/examples/cloudrun/main.tf @@ -43,8 +43,7 @@ module "lb-http" { group = google_compute_region_network_endpoint_group.serverless_neg.id } ] - serverless_neg_backends = [] - enable_cdn = false + enable_cdn = false iap_config = { enable = false diff --git a/kitchen.yml b/kitchen.yml index eb794430..20cb636b 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -37,17 +37,6 @@ suites: backend: local controls: - http - - name: cloudrun-implicit-serverless-neg - driver: - root_module_directory: test/fixtures/cloudrun-implicit-serverless-neg - verify_version: false - verifier: - color: false - systems: - - name: cloudrun-implicit-serverless-neg - backend: local - controls: - - http - name: mig_nat driver: root_module_directory: test/fixtures/mig_nat/ diff --git a/modules/serverless_negs/README.md b/modules/serverless_negs/README.md index 166b7118..03b8e2fd 100644 --- a/modules/serverless_negs/README.md +++ b/modules/serverless_negs/README.md @@ -72,7 +72,7 @@ module "lb-http" { | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | address | Existing IPv4 address to use (the actual IP address value) | `string` | `null` | no | -| backends | Map backend indices to list of backend maps. |
map(object({
project = optional(string)
protocol = optional(string)
port_name = optional(string)
description = optional(string)
enable_cdn = optional(bool)
compression_mode = optional(string)
security_policy = optional(string, null)
edge_security_policy = optional(string, null)
custom_request_headers = optional(list(string))
custom_response_headers = optional(list(string))

connection_draining_timeout_sec = optional(number)
session_affinity = optional(string)
affinity_cookie_ttl_sec = optional(number)
locality_lb_policy = optional(string)


log_config = object({
enable = optional(bool)
sample_rate = optional(number)
})

groups = list(object({
group = string
description = optional(string)

}))

// serverless_neg_backends is mutually exclusive to groups.There can only be one serverless neg per region
// with one of cloud-run, cloud-functions and app-engine as service.
serverless_neg_backends = list(object({
region = string,
type = string, // cloud-run, cloud-function and app-engine
service = object({ name : string, version : optional(string) })
}))

iap_config = object({
enable = bool
oauth2_client_id = optional(string)
oauth2_client_secret = optional(string)
})
cdn_policy = optional(object({
cache_mode = optional(string)
signed_url_cache_max_age_sec = optional(string)
default_ttl = optional(number)
max_ttl = optional(number)
client_ttl = optional(number)
negative_caching = optional(bool)
negative_caching_policy = optional(object({
code = optional(number)
ttl = optional(number)
}))
serve_while_stale = optional(number)
cache_key_policy = optional(object({
include_host = optional(bool)
include_protocol = optional(bool)
include_query_string = optional(bool)
query_string_blacklist = optional(list(string))
query_string_whitelist = optional(list(string))
include_http_headers = optional(list(string))
include_named_cookies = optional(list(string))
}))
bypass_cache_on_request_headers = optional(list(string))
}))
outlier_detection = optional(object({
base_ejection_time = optional(object({
seconds = number
nanos = optional(number)
}))
consecutive_errors = optional(number)
consecutive_gateway_failure = optional(number)
enforcing_consecutive_errors = optional(number)
enforcing_consecutive_gateway_failure = optional(number)
enforcing_success_rate = optional(number)
interval = optional(object({
seconds = number
nanos = optional(number)
}))
max_ejection_percent = optional(number)
success_rate_minimum_hosts = optional(number)
success_rate_request_volume = optional(number)
success_rate_stdev_factor = optional(number)
}))
}))
| n/a | yes | +| backends | Map backend indices to list of backend maps. |
map(object({
project = optional(string)
protocol = optional(string)
port_name = optional(string)
description = optional(string)
enable_cdn = optional(bool)
compression_mode = optional(string)
security_policy = optional(string, null)
edge_security_policy = optional(string, null)
custom_request_headers = optional(list(string))
custom_response_headers = optional(list(string))

connection_draining_timeout_sec = optional(number)
session_affinity = optional(string)
affinity_cookie_ttl_sec = optional(number)
locality_lb_policy = optional(string)


log_config = object({
enable = optional(bool)
sample_rate = optional(number)
})

groups = list(object({
group = string
description = optional(string)

}))

// serverless_neg_backends is mutually exclusive to groups.There can only be one serverless neg per region
// with one of cloud-run, cloud-functions and app-engine as service.
serverless_neg_backends = optional(list(object({
region = string,
type = string, // cloud-run, cloud-function and app-engine
service = object({ name : string, version : optional(string) })
})), [])

iap_config = object({
enable = bool
oauth2_client_id = optional(string)
oauth2_client_secret = optional(string)
})
cdn_policy = optional(object({
cache_mode = optional(string)
signed_url_cache_max_age_sec = optional(string)
default_ttl = optional(number)
max_ttl = optional(number)
client_ttl = optional(number)
negative_caching = optional(bool)
negative_caching_policy = optional(object({
code = optional(number)
ttl = optional(number)
}))
serve_while_stale = optional(number)
cache_key_policy = optional(object({
include_host = optional(bool)
include_protocol = optional(bool)
include_query_string = optional(bool)
query_string_blacklist = optional(list(string))
query_string_whitelist = optional(list(string))
include_http_headers = optional(list(string))
include_named_cookies = optional(list(string))
}))
bypass_cache_on_request_headers = optional(list(string))
}))
outlier_detection = optional(object({
base_ejection_time = optional(object({
seconds = number
nanos = optional(number)
}))
consecutive_errors = optional(number)
consecutive_gateway_failure = optional(number)
enforcing_consecutive_errors = optional(number)
enforcing_consecutive_gateway_failure = optional(number)
enforcing_success_rate = optional(number)
interval = optional(object({
seconds = number
nanos = optional(number)
}))
max_ejection_percent = optional(number)
success_rate_minimum_hosts = optional(number)
success_rate_request_volume = optional(number)
success_rate_stdev_factor = optional(number)
}))
}))
| n/a | yes | | certificate | Content of the SSL certificate. Requires `ssl` to be set to `true` and `create_ssl_certificate` set to `true` | `string` | `null` | no | | certificate\_map | Certificate Map ID in format projects/{project}/locations/global/certificateMaps/{name}. Identifies a certificate map associated with the given target proxy. Requires `ssl` to be set to `true` | `string` | `null` | no | | create\_address | Create a new global IPv4 address | `bool` | `true` | no | diff --git a/modules/serverless_negs/main.tf b/modules/serverless_negs/main.tf index 9b6225af..addac23e 100644 --- a/modules/serverless_negs/main.tf +++ b/modules/serverless_negs/main.tf @@ -324,6 +324,8 @@ resource "google_compute_region_network_endpoint_group" "serverless_negs" { } ]...) + provider = google-beta + project = var.project name = each.key network_endpoint_type = "SERVERLESS" region = each.value.region diff --git a/modules/serverless_negs/metadata.yaml b/modules/serverless_negs/metadata.yaml index d43bb92b..d65830e9 100644 --- a/modules/serverless_negs/metadata.yaml +++ b/modules/serverless_negs/metadata.yaml @@ -103,11 +103,11 @@ spec: // serverless_neg_backends is mutually exclusive to groups.There can only be one serverless neg per region // with one of cloud-run, cloud-functions and app-engine as service. - serverless_neg_backends = list(object({ + serverless_neg_backends = optional(list(object({ region = string, type = string, // cloud-run, cloud-function and app-engine service = object({ name : string, version : optional(string) }) - })) + })), []) iap_config = object({ enable = bool diff --git a/modules/serverless_negs/variables.tf b/modules/serverless_negs/variables.tf index 1ec4441b..9f81445e 100644 --- a/modules/serverless_negs/variables.tf +++ b/modules/serverless_negs/variables.tf @@ -57,6 +57,16 @@ variable "ipv6_address" { variable "backends" { description = "Map backend indices to list of backend maps." + validation { + condition = alltrue([ + for backend_key, backend_value in var.backends : + alltrue([ + for neg_backend in backend_value.serverless_neg_backends : + contains(["cloud-run", "cloud-function", "app-engine"], neg_backend.type) + ]) + ]) + error_message = "serverless_neg_backend type should be either 'cloud-run' or 'cloud-function' or 'app-engine'." + } type = map(object({ project = optional(string) protocol = optional(string) @@ -88,11 +98,11 @@ variable "backends" { // serverless_neg_backends is mutually exclusive to groups.There can only be one serverless neg per region // with one of cloud-run, cloud-functions and app-engine as service. - serverless_neg_backends = list(object({ + serverless_neg_backends = optional(list(object({ region = string, type = string, // cloud-run, cloud-function and app-engine service = object({ name : string, version : optional(string) }) - })) + })), []) iap_config = object({ enable = bool diff --git a/test/fixtures/cloudrun-implicit-serverless-neg/main.tf b/test/fixtures/cloudrun-implicit-serverless-neg/main.tf deleted file mode 100644 index 9ebaa5ba..00000000 --- a/test/fixtures/cloudrun-implicit-serverless-neg/main.tf +++ /dev/null @@ -1,22 +0,0 @@ -/** - * Copyright 2020 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 "example" { - source = "../../../examples/cloudrun-implicit-serverless-neg" - project_id = var.project_id - ssl = false - domain = null -} diff --git a/test/fixtures/cloudrun-implicit-serverless-neg/outputs.tf b/test/fixtures/cloudrun-implicit-serverless-neg/outputs.tf deleted file mode 100644 index 11cb9747..00000000 --- a/test/fixtures/cloudrun-implicit-serverless-neg/outputs.tf +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright 2020 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. - */ - -output "project_id" { - description = "The ID of the project in which resources are provisioned." - value = var.project_id -} - -output "lb_ip" { - value = module.example.load-balancer-ip -} diff --git a/test/fixtures/cloudrun-implicit-serverless-neg/variables.tf b/test/fixtures/cloudrun-implicit-serverless-neg/variables.tf deleted file mode 100644 index bba35006..00000000 --- a/test/fixtures/cloudrun-implicit-serverless-neg/variables.tf +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright 2020 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" { - description = "The ID of the project in which to provision resources." - type = string -} diff --git a/test/fixtures/cloudrun-implicit-serverless-neg/versions.tf b/test/fixtures/cloudrun-implicit-serverless-neg/versions.tf deleted file mode 100644 index 2a088552..00000000 --- a/test/fixtures/cloudrun-implicit-serverless-neg/versions.tf +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright 2020 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. - */ - -terraform { - required_version = ">= 0.13.0" -} diff --git a/test/integration/cloudrun-implicit-serverless-neg/cloudrun_implicit_test.go b/test/integration/cloudrun-implicit-serverless-neg/cloudrun_implicit_test.go new file mode 100644 index 00000000..6b167f1d --- /dev/null +++ b/test/integration/cloudrun-implicit-serverless-neg/cloudrun_implicit_test.go @@ -0,0 +1,38 @@ +// Copyright 2024 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. + +package cloudrun + +import ( + "testing" + + "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft" + "github.com/stretchr/testify/assert" + + test "github.com/terraform-google-modules/terraform-google-lb-http/test/integration" +) + +func TestCloudrunImplicit(t *testing.T) { + bpt := tft.NewTFBlueprintTest(t) + + bpt.DefineVerify(func(assert *assert.Assertions) { + bpt.DefaultVerify(assert) + + loadBalancerIp := bpt.GetStringOutput("load-balancer-ip") + + test.AssertResponseStatus(assert, "http://"+loadBalancerIp, 200) + }) + + bpt.Test() +} diff --git a/test/integration/cloudrun-implicit-serverless-neg/controls/http.rb b/test/integration/cloudrun-implicit-serverless-neg/controls/http.rb deleted file mode 100644 index c7f63b70..00000000 --- a/test/integration/cloudrun-implicit-serverless-neg/controls/http.rb +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2019 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 -# -# https://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. - -control "http" do - title "HTTP Check" - - describe http("http://#{attribute("lb_ip")}") do - its('status') { should eq 200 } - end -end diff --git a/test/integration/cloudrun-implicit-serverless-neg/inspec.yml b/test/integration/cloudrun-implicit-serverless-neg/inspec.yml deleted file mode 100644 index 2b5821ed..00000000 --- a/test/integration/cloudrun-implicit-serverless-neg/inspec.yml +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2021 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. - -name: cloudrun-implicit-serverless-neg -attributes: - - name: project_id - required: true - type: string - - name: lb_ip - required: true - type: string diff --git a/test/integration/testhelper.go b/test/integration/testhelper.go new file mode 100644 index 00000000..316240bb --- /dev/null +++ b/test/integration/testhelper.go @@ -0,0 +1,39 @@ +// Copyright 2024 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. + +package test + +import ( + "io" + "net/http" + + "github.com/stretchr/testify/assert" +) + +func AssertResponseStatus(assert *assert.Assertions, url string, statusCode int) { + var resStatusCode int + resStatusCode, _, _ = httpGetRequest(url) + assert.Equal(statusCode, resStatusCode) +} + +func httpGetRequest(url string) (statusCode int, body string, err error) { + res, err := http.Get(url) + if err != nil { + return 0, "", err + } + defer res.Body.Close() + + buffer, err := io.ReadAll(res.Body) + return res.StatusCode, string(buffer), err +}