diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75661b7662..6fe3470972 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,8 +55,6 @@ jobs: with: go-version: '1.21.1' - - run: curl -I https://debug.fly.dev - - name: install gotestsum run: go install gotest.tools/gotestsum@latest diff --git a/internal/endtoend/ddl_test.go b/internal/endtoend/ddl_test.go index 33085926aa..123a503ce1 100644 --- a/internal/endtoend/ddl_test.go +++ b/internal/endtoend/ddl_test.go @@ -23,6 +23,7 @@ func TestValidSchema(t *testing.T) { projectID := os.Getenv("CI_SQLC_PROJECT_ID") authToken := os.Getenv("CI_SQLC_AUTH_TOKEN") + if projectID == "" || authToken == "" { if os.Getenv("CI") == "" { t.Skip("skiping ddl tests outside of CI") @@ -106,11 +107,11 @@ func TestValidSchema(t *testing.T) { resp, err := client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{ Engine: "postgresql", - Region: "iad", + Region: quickdb.GetClosestRegion(), Migrations: sqls, }) if err != nil { - t.Fatal(err) + t.Fatalf("region %s: %s", quickdb.GetClosestRegion(), err) } t.Cleanup(func() { diff --git a/internal/quickdb/region.go b/internal/quickdb/region.go new file mode 100644 index 0000000000..bc03e3b3f7 --- /dev/null +++ b/internal/quickdb/region.go @@ -0,0 +1,19 @@ +package quickdb + +import ( + "net/http" + "sync" +) + +var region string +var once sync.Once + +func GetClosestRegion() string { + once.Do(func() { + resp, err := http.Get("https://debug.fly.dev") + if err == nil { + region = resp.Header.Get("Fly-Region") + } + }) + return region +} diff --git a/internal/sqltest/hosted/db.go b/internal/sqltest/hosted/db.go index c7829a607f..4d2fe8dc84 100644 --- a/internal/sqltest/hosted/db.go +++ b/internal/sqltest/hosted/db.go @@ -58,11 +58,11 @@ func PostgreSQL(t *testing.T, migrations []string) string { resp, err := client.CreateEphemeralDatabase(ctx, &pb.CreateEphemeralDatabaseRequest{ Engine: "postgresql", - Region: "iad", + Region: quickdb.GetClosestRegion(), Migrations: seed, }) if err != nil { - t.Fatal(err) + t.Fatalf("region %s: %s", quickdb.GetClosestRegion(), err) } t.Cleanup(func() {