Skip to content

Commit

Permalink
test: Run vet against local database server (#3101)
Browse files Browse the repository at this point in the history
* test: Use local database server for vet tests

* Remove last use of hosted
  • Loading branch information
kyleconroy authored Jan 3, 2024
1 parent 2328c81 commit 5e7977b
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/authors/mysql/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (

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

"github.com/sqlc-dev/sqlc/internal/sqltest/hosted"
"github.com/sqlc-dev/sqlc/internal/sqltest/local"
)

func TestAuthors(t *testing.T) {
ctx := context.Background()
uri := hosted.MySQL(t, []string{"schema.sql"})
uri := local.MySQL(t, []string{"schema.sql"})
sdb, err := sql.Open("mysql", uri)
if err != nil {
t.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions examples/authors/sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sql:
queries: postgresql/query.sql
engine: postgresql
database:
managed: true
uri: "${VET_TEST_EXAMPLES_POSTGRES_AUTHORS}"
analyzer:
database: false
rules:
Expand All @@ -23,7 +23,7 @@ sql:
queries: mysql/query.sql
engine: mysql
database:
managed: true
uri: "${VET_TEST_EXAMPLES_MYSQL_AUTHORS}"
rules:
- sqlc/db-prepare
# - mysql-query-too-costly
Expand Down
2 changes: 1 addition & 1 deletion examples/batch/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"queries": "postgresql/query.sql",
"engine": "postgresql",
"database": {
"managed": true
"uri": "${VET_TEST_EXAMPLES_POSTGRES_BATCH}"
},
"analyzer": {
"database": false
Expand Down
4 changes: 2 additions & 2 deletions examples/booktest/mysql/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (

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

"github.com/sqlc-dev/sqlc/internal/sqltest/hosted"
"github.com/sqlc-dev/sqlc/internal/sqltest/local"
)

func TestBooks(t *testing.T) {
ctx := context.Background()
uri := hosted.MySQL(t, []string{"schema.sql"})
uri := local.MySQL(t, []string{"schema.sql"})
db, err := sql.Open("mysql", uri)
if err != nil {
t.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions examples/booktest/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"engine": "postgresql",
"sql_package": "pgx/v5",
"database": {
"managed": true
"uri": "${VET_TEST_EXAMPLES_POSTGRES_BOOKTEST}"
},
"analyzer": {
"database": false
Expand All @@ -28,7 +28,7 @@
"queries": "mysql/query.sql",
"engine": "mysql",
"database": {
"managed": true
"uri": "${VET_TEST_EXAMPLES_MYSQL_BOOKTEST}"
},
"rules": [
"sqlc/db-prepare"
Expand Down
2 changes: 1 addition & 1 deletion examples/jets/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"engine": "postgresql",
"sql_package": "pgx/v5",
"database": {
"managed": true
"uri": "${VET_TEST_EXAMPLES_POSTGRES_JETS}"
},
"analyzer": {
"database": false
Expand Down
4 changes: 2 additions & 2 deletions examples/ondeck/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"engine": "postgresql",
"sql_package": "database/sql",
"database": {
"managed": true
"uri": "${VET_TEST_EXAMPLES_POSTGRES_ONDECK}"
},
"analyzer": {
"database": false
Expand All @@ -31,7 +31,7 @@
"queries": "mysql/query",
"engine": "mysql",
"database": {
"managed": true
"uri": "${VET_TEST_EXAMPLES_MYSQL_ONDECK}"
},
"rules": [
"sqlc/db-prepare"
Expand Down
15 changes: 10 additions & 5 deletions internal/endtoend/vet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/sqlc-dev/sqlc/internal/cmd"
"github.com/sqlc-dev/sqlc/internal/sqltest"
"github.com/sqlc-dev/sqlc/internal/sqltest/local"
)

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

authToken := os.Getenv("SQLC_AUTH_TOKEN")
if authToken == "" {
t.Skip("missing auth token")
}

examples, err := filepath.Abs(filepath.Join("..", "..", "examples"))
if err != nil {
t.Fatal(err)
Expand All @@ -62,6 +59,14 @@ func TestExamplesVet(t *testing.T) {
defer db.Close()
defer cleanup()
}
if s, found := findSchema(t, filepath.Join(path, "mysql")); found {
uri := local.MySQL(t, []string{s})
os.Setenv(fmt.Sprintf("VET_TEST_EXAMPLES_MYSQL_%s", strings.ToUpper(tc)), uri)
}
if s, found := findSchema(t, filepath.Join(path, "postgresql")); found {
uri := local.PostgreSQL(t, []string{s})
os.Setenv(fmt.Sprintf("VET_TEST_EXAMPLES_POSTGRES_%s", strings.ToUpper(tc)), uri)
}
}

var stderr bytes.Buffer
Expand Down

0 comments on commit 5e7977b

Please sign in to comment.