Skip to content

Commit fe44691

Browse files
committed
add sample terraform test based e2e tests
1 parent eb660c6 commit fe44691

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-0
lines changed

modules/regional-go-service/outputs.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ output "names" {
33
for k, v in google_cloud_run_v2_service.this : k => v.name
44
}
55
}
6+
7+
output "uris" {
8+
value = {
9+
for k, v in google_cloud_run_v2_service.this : k => v.uri
10+
}
11+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
variable "endpoint" {}
2+
3+
data "http" "endpoint" {
4+
url = var.endpoint
5+
method = "GET"
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"html"
6+
"log"
7+
"net/http"
8+
)
9+
10+
func main() {
11+
http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) {
12+
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
13+
})
14+
15+
log.Fatal(http.ListenAndServe(":8080", nil))
16+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
variable "project" {}
2+
3+
resource "random_string" "name" {
4+
numeric = false
5+
upper = false
6+
special = false
7+
length = 6
8+
}
9+
10+
resource "google_service_account" "iam" {
11+
project = var.project
12+
13+
account_id = random_string.name.id
14+
display_name = "test-${random_string.name.id}"
15+
description = "Dedicated service account for ${random_string.name.id}"
16+
}
17+
18+
output "name" {
19+
value = random_string.name.id
20+
}
21+
22+
output "email" {
23+
value = google_service_account.iam.email
24+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
variables {
2+
project = "wolf-chainguard"
3+
}
4+
5+
run "setup" {
6+
module {
7+
source = "./tests/setup/"
8+
}
9+
}
10+
11+
run "create" {
12+
variables {
13+
name = run.setup.name
14+
project_id = var.project
15+
regions = {
16+
"us-central1" = {
17+
network = "default"
18+
subnet = "default"
19+
}
20+
}
21+
22+
service_account = run.setup.email
23+
24+
ingress = "INGRESS_TRAFFIC_ALL"
25+
egress = "ALL_TRAFFIC"
26+
27+
containers = {
28+
"hello" = {
29+
source = {
30+
working_dir = "./tests"
31+
importpath = "./cmd/"
32+
}
33+
ports = [{ container_port = 8080 }]
34+
}
35+
}
36+
37+
notification_channels = []
38+
}
39+
40+
assert {
41+
condition = google_cloud_run_v2_service.this["us-central1"].terminal_condition[0].type == "Ready"
42+
error_message = "Service not ready"
43+
}
44+
}
45+
46+
run "validate" {
47+
module {
48+
source = "./tests/asserts/"
49+
}
50+
51+
variables {
52+
endpoint = "${run.create.uris["us-central1"]}/bar"
53+
}
54+
55+
assert {
56+
condition = data.http.endpoint.status_code == 200
57+
error_message = "Website responded with HTTP status ${data.http.endpoint.status_code}"
58+
}
59+
}

0 commit comments

Comments
 (0)