Skip to content

Commit e6c7cb3

Browse files
authored
test(endtoend): Pull region from environment (#2750)
* test(endtoend): Pull region once via HTTP
1 parent e12a1ca commit e6c7cb3

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ jobs:
5555
with:
5656
go-version: '1.21.1'
5757

58-
- run: curl -I https://debug.fly.dev
59-
6058
- name: install gotestsum
6159
run: go install gotest.tools/gotestsum@latest
6260

internal/endtoend/ddl_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestValidSchema(t *testing.T) {
2323

2424
projectID := os.Getenv("CI_SQLC_PROJECT_ID")
2525
authToken := os.Getenv("CI_SQLC_AUTH_TOKEN")
26+
2627
if projectID == "" || authToken == "" {
2728
if os.Getenv("CI") == "" {
2829
t.Skip("skiping ddl tests outside of CI")
@@ -106,11 +107,11 @@ func TestValidSchema(t *testing.T) {
106107

107108
resp, err := client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{
108109
Engine: "postgresql",
109-
Region: "iad",
110+
Region: quickdb.GetClosestRegion(),
110111
Migrations: sqls,
111112
})
112113
if err != nil {
113-
t.Fatal(err)
114+
t.Fatalf("region %s: %s", quickdb.GetClosestRegion(), err)
114115
}
115116

116117
t.Cleanup(func() {

internal/quickdb/region.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package quickdb
2+
3+
import (
4+
"net/http"
5+
"sync"
6+
)
7+
8+
var region string
9+
var once sync.Once
10+
11+
func GetClosestRegion() string {
12+
once.Do(func() {
13+
resp, err := http.Get("https://debug.fly.dev")
14+
if err == nil {
15+
region = resp.Header.Get("Fly-Region")
16+
}
17+
})
18+
return region
19+
}

internal/sqltest/hosted/db.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ func PostgreSQL(t *testing.T, migrations []string) string {
5858

5959
resp, err := client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{
6060
Engine: "postgresql",
61-
Region: "iad",
61+
Region: quickdb.GetClosestRegion(),
6262
Migrations: seed,
6363
})
6464
if err != nil {
65-
t.Fatal(err)
65+
t.Fatalf("region %s: %s", quickdb.GetClosestRegion(), err)
6666
}
6767

6868
t.Cleanup(func() {

0 commit comments

Comments
 (0)