Skip to content

Commit 5e7977b

Browse files
authored
test: Run vet against local database server (#3101)
* test: Use local database server for vet tests * Remove last use of hosted
1 parent 2328c81 commit 5e7977b

File tree

8 files changed

+22
-17
lines changed

8 files changed

+22
-17
lines changed

examples/authors/mysql/db_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010

1111
_ "github.com/go-sql-driver/mysql"
1212

13-
"github.com/sqlc-dev/sqlc/internal/sqltest/hosted"
13+
"github.com/sqlc-dev/sqlc/internal/sqltest/local"
1414
)
1515

1616
func TestAuthors(t *testing.T) {
1717
ctx := context.Background()
18-
uri := hosted.MySQL(t, []string{"schema.sql"})
18+
uri := local.MySQL(t, []string{"schema.sql"})
1919
sdb, err := sql.Open("mysql", uri)
2020
if err != nil {
2121
t.Fatal(err)

examples/authors/sqlc.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ sql:
77
queries: postgresql/query.sql
88
engine: postgresql
99
database:
10-
managed: true
10+
uri: "${VET_TEST_EXAMPLES_POSTGRES_AUTHORS}"
1111
analyzer:
1212
database: false
1313
rules:
@@ -23,7 +23,7 @@ sql:
2323
queries: mysql/query.sql
2424
engine: mysql
2525
database:
26-
managed: true
26+
uri: "${VET_TEST_EXAMPLES_MYSQL_AUTHORS}"
2727
rules:
2828
- sqlc/db-prepare
2929
# - mysql-query-too-costly

examples/batch/sqlc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"queries": "postgresql/query.sql",
1212
"engine": "postgresql",
1313
"database": {
14-
"managed": true
14+
"uri": "${VET_TEST_EXAMPLES_POSTGRES_BATCH}"
1515
},
1616
"analyzer": {
1717
"database": false

examples/booktest/mysql/db_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import (
1111

1212
_ "github.com/go-sql-driver/mysql"
1313

14-
"github.com/sqlc-dev/sqlc/internal/sqltest/hosted"
14+
"github.com/sqlc-dev/sqlc/internal/sqltest/local"
1515
)
1616

1717
func TestBooks(t *testing.T) {
1818
ctx := context.Background()
19-
uri := hosted.MySQL(t, []string{"schema.sql"})
19+
uri := local.MySQL(t, []string{"schema.sql"})
2020
db, err := sql.Open("mysql", uri)
2121
if err != nil {
2222
t.Fatal(err)

examples/booktest/sqlc.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"engine": "postgresql",
1313
"sql_package": "pgx/v5",
1414
"database": {
15-
"managed": true
15+
"uri": "${VET_TEST_EXAMPLES_POSTGRES_BOOKTEST}"
1616
},
1717
"analyzer": {
1818
"database": false
@@ -28,7 +28,7 @@
2828
"queries": "mysql/query.sql",
2929
"engine": "mysql",
3030
"database": {
31-
"managed": true
31+
"uri": "${VET_TEST_EXAMPLES_MYSQL_BOOKTEST}"
3232
},
3333
"rules": [
3434
"sqlc/db-prepare"

examples/jets/sqlc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"engine": "postgresql",
1313
"sql_package": "pgx/v5",
1414
"database": {
15-
"managed": true
15+
"uri": "${VET_TEST_EXAMPLES_POSTGRES_JETS}"
1616
},
1717
"analyzer": {
1818
"database": false

examples/ondeck/sqlc.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"engine": "postgresql",
1313
"sql_package": "database/sql",
1414
"database": {
15-
"managed": true
15+
"uri": "${VET_TEST_EXAMPLES_POSTGRES_ONDECK}"
1616
},
1717
"analyzer": {
1818
"database": false
@@ -31,7 +31,7 @@
3131
"queries": "mysql/query",
3232
"engine": "mysql",
3333
"database": {
34-
"managed": true
34+
"uri": "${VET_TEST_EXAMPLES_MYSQL_ONDECK}"
3535
},
3636
"rules": [
3737
"sqlc/db-prepare"

internal/endtoend/vet_test.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import (
99
"fmt"
1010
"os"
1111
"path/filepath"
12+
"strings"
1213
"testing"
1314

1415
"github.com/sqlc-dev/sqlc/internal/cmd"
1516
"github.com/sqlc-dev/sqlc/internal/sqltest"
17+
"github.com/sqlc-dev/sqlc/internal/sqltest/local"
1618
)
1719

1820
func findSchema(t *testing.T, path string) (string, bool) {
@@ -31,11 +33,6 @@ func TestExamplesVet(t *testing.T) {
3133
t.Parallel()
3234
ctx := context.Background()
3335

34-
authToken := os.Getenv("SQLC_AUTH_TOKEN")
35-
if authToken == "" {
36-
t.Skip("missing auth token")
37-
}
38-
3936
examples, err := filepath.Abs(filepath.Join("..", "..", "examples"))
4037
if err != nil {
4138
t.Fatal(err)
@@ -62,6 +59,14 @@ func TestExamplesVet(t *testing.T) {
6259
defer db.Close()
6360
defer cleanup()
6461
}
62+
if s, found := findSchema(t, filepath.Join(path, "mysql")); found {
63+
uri := local.MySQL(t, []string{s})
64+
os.Setenv(fmt.Sprintf("VET_TEST_EXAMPLES_MYSQL_%s", strings.ToUpper(tc)), uri)
65+
}
66+
if s, found := findSchema(t, filepath.Join(path, "postgresql")); found {
67+
uri := local.PostgreSQL(t, []string{s})
68+
os.Setenv(fmt.Sprintf("VET_TEST_EXAMPLES_POSTGRES_%s", strings.ToUpper(tc)), uri)
69+
}
6570
}
6671

6772
var stderr bytes.Buffer

0 commit comments

Comments
 (0)