Skip to content

Commit a4893b1

Browse files
committed
Use the new Docker package
1 parent 768369f commit a4893b1

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

internal/sqltest/local/mysql.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,27 @@ import (
1313

1414
migrate "github.com/sqlc-dev/sqlc/internal/migrations"
1515
"github.com/sqlc-dev/sqlc/internal/sql/sqlpath"
16+
"github.com/sqlc-dev/sqlc/internal/sqltest/docker"
1617
)
1718

1819
var mysqlSync sync.Once
1920
var mysqlPool *sql.DB
2021

21-
func MySQLServer() string {
22-
return os.Getenv("MYSQL_SERVER_URI")
23-
}
24-
2522
func MySQL(t *testing.T, migrations []string) string {
2623
ctx := context.Background()
2724
t.Helper()
2825

2926
dburi := os.Getenv("MYSQL_SERVER_URI")
3027
if dburi == "" {
31-
t.Skip("MYSQL_SERVER_URI is empty")
28+
if ierr := docker.Installed(); ierr == nil {
29+
u, err := docker.StartMySQLServer(ctx)
30+
if err != nil {
31+
t.Fatal(err)
32+
}
33+
dburi = u
34+
} else {
35+
t.Skip("MYSQL_SERVER_URI is empty")
36+
}
3237
}
3338

3439
mysqlSync.Do(func() {

internal/sqltest/local/postgres.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
migrate "github.com/sqlc-dev/sqlc/internal/migrations"
1616
"github.com/sqlc-dev/sqlc/internal/pgx/poolcache"
1717
"github.com/sqlc-dev/sqlc/internal/sql/sqlpath"
18+
"github.com/sqlc-dev/sqlc/internal/sqltest/docker"
1819
)
1920

2021
var flight singleflight.Group
@@ -28,17 +29,21 @@ func ReadOnlyPostgreSQL(t *testing.T, migrations []string) string {
2829
return postgreSQL(t, migrations, false)
2930
}
3031

31-
func PostgreSQLServer() string {
32-
return os.Getenv("POSTGRESQL_SERVER_URI")
33-
}
34-
3532
func postgreSQL(t *testing.T, migrations []string, rw bool) string {
3633
ctx := context.Background()
3734
t.Helper()
3835

3936
dburi := os.Getenv("POSTGRESQL_SERVER_URI")
4037
if dburi == "" {
41-
t.Skip("POSTGRESQL_SERVER_URI is empty")
38+
if ierr := docker.Installed(); ierr == nil {
39+
u, err := docker.StartPostgreSQLServer(ctx)
40+
if err != nil {
41+
t.Fatal(err)
42+
}
43+
dburi = u
44+
} else {
45+
t.Skip("POSTGRESQL_SERVER_URI is empty")
46+
}
4247
}
4348

4449
postgresPool, err := cache.Open(ctx, dburi)

0 commit comments

Comments
 (0)