Update circle.ci

This commit is contained in:
go-jet 2021-12-18 13:55:40 +01:00
parent 972fc1d9bf
commit b92af7ca6e
9 changed files with 128 additions and 127 deletions

View file

@ -14,14 +14,28 @@ checkout-testdata:
docker-compose-up:
docker-compose up
init-all:
go run ./init/init.go -testsuite all
init-postgres:
go run ./init/init.go -testsuite postgres
init-mysql:
go run ./init/init.go -testsuite mysql
init-mariadb:
go run ./init/init.go -testsuite mariadb
init-sqlite:
go run ./init/init.go -testsuite sqlite
# jet-gen will call generator on each of the test databases to generate sql builder and model files need to run the tests.
jet-gen: install-jet-gen jet-gen-pg jet-gen-mysql jet-gen-mariadb jet-gen-sqlite
jet-gen-all: install-jet-gen jet-gen-postgres jet-gen-mysql jet-gen-mariadb jet-gen-sqlite
install-jet-gen:
go build -o ${GOPATH}/bin/jet ../cmd/jet/
jet-gen-pg:
jet-gen-postgres:
jet -dsn=postgres://jet:jet@localhost:50901/jetdb?sslmode=disable -schema=dvds -path=./.gentestdata/
jet -dsn=postgres://jet:jet@localhost:50901/jetdb?sslmode=disable -schema=chinook -path=./.gentestdata/
jet -dsn=postgres://jet:jet@localhost:50901/jetdb?sslmode=disable -schema=chinook2 -path=./.gentestdata/
@ -44,7 +58,5 @@ jet-gen-sqlite:
# docker-compose-cleanup will stop and remove test containers, volumes, and images.
# If temp .docker/ folder is still not empty, use 'sudo rm -rf .docker' to remove it.
cleanup:
docker-compose down --volumes
$(info INFO: If the ./.docker folder is still not empty, use 'sudo rm -rf .docker/' to remove it.)

View file

@ -14,8 +14,8 @@ To simplify the process there is a Makefile with a list of helper commands.
# Note that on the first run this command might take a couple of minutes.
make setup
# When databases are ready, we can generate sql builder and model types needed to compile the tests.
make jet-gen
# When databases are ready, we can generate sql builder and model types for each of the test databases
make jet-gen-all
```
Then we can run the tests the usual way:
@ -26,5 +26,4 @@ go test -v ./...
To removes test containers, volumes, and images:
```shell
make cleanup
# If temp ./.docker folder is still not empty, use 'sudo rm -rf .docker' to remove it.
```

View file

@ -19,12 +19,12 @@ var PostgresConnectString = fmt.Sprintf("host=%s port=%d user=%s password=%s dbn
// MySQL test database connection parameters
const (
MySqLHost = "localhost"
MySqLHost = "127.0.0.1"
MySQLPort = 50902
MySQLUser = "jet"
MySQLPassword = "jet"
MariaDBHost = "localhost"
MariaDBHost = "127.0.0.1"
MariaDBPort = 50903
MariaDBUser = "jet"
MariaDBPassword = "jet"

View file

@ -11,7 +11,6 @@ services:
- '50901:5432'
volumes:
- ./testdata/init/postgres:/docker-entrypoint-initdb.d
- ./.docker/postgres-data:/var/lib/postgresql/data
mysql:
image: mysql:8.0.27
@ -25,7 +24,6 @@ services:
- '50902:3306'
volumes:
- ./testdata/init/mysql:/docker-entrypoint-initdb.d
- ./.docker/mysql-data:/var/lib/mysql
mariadb:
image: mariadb:10.3.32
@ -39,4 +37,3 @@ services:
- '50903:3306'
volumes:
- ./testdata/init/mysql:/docker-entrypoint-initdb.d
- ./.docker/mariadb-data:/var/lib/mysql

View file

@ -4,6 +4,7 @@ import (
"database/sql"
"flag"
"fmt"
"github.com/go-jet/jet/v2/generator/mysql"
"github.com/go-jet/jet/v2/generator/sqlite"
"github.com/go-jet/jet/v2/tests/internal/utils/repo"
"io/ioutil"
@ -11,7 +12,6 @@ import (
"os/exec"
"strings"
"github.com/go-jet/jet/v2/generator/mysql"
"github.com/go-jet/jet/v2/generator/postgres"
"github.com/go-jet/jet/v2/internal/utils/throw"
"github.com/go-jet/jet/v2/tests/dbconfig"
@ -39,7 +39,7 @@ func main() {
}
if testSuite == "mysql" || testSuite == "mariadb" {
initMySQLDB()
initMySQLDB(testSuite == "mariadb")
return
}
@ -48,8 +48,9 @@ func main() {
return
}
initMySQLDB()
initPostgresDB()
initMySQLDB(false)
initMySQLDB(true)
initSQLiteDB()
}
@ -62,7 +63,7 @@ func initSQLiteDB() {
throw.OnError(err)
}
func initMySQLDB() {
func initMySQLDB(isMariaDB bool) {
mySQLDBs := []string{
"dvds",
@ -71,12 +72,19 @@ func initMySQLDB() {
}
for _, dbName := range mySQLDBs {
cmdLine := fmt.Sprintf("mysql -h %s -P%d -u %s -p%s %s < %s",
dbconfig.MySqLHost,
dbconfig.MySQLPort,
dbconfig.MySQLUser,
dbconfig.MySQLPassword,
dbName,
host := dbconfig.MySqLHost
port := dbconfig.MySQLPort
user := dbconfig.MySQLUser
pass := dbconfig.MySQLPassword
if isMariaDB {
host = dbconfig.MariaDBHost
port = dbconfig.MariaDBPort
user = dbconfig.MariaDBUser
pass = dbconfig.MariaDBPassword
}
cmdLine := fmt.Sprintf("mysql -h %s -P %d -u %s -p%s %s < %s", host, port, user, pass, dbName,
"./testdata/init/mysql/"+dbName+".sql")
fmt.Println(cmdLine)
@ -90,10 +98,10 @@ func initMySQLDB() {
throw.OnError(err)
err = mysql.Generate("./.gentestdata/mysql", mysql.DBConnection{
Host: dbconfig.MySqLHost,
Port: dbconfig.MySQLPort,
User: dbconfig.MySQLUser,
Password: dbconfig.MySQLPassword,
Host: host,
Port: port,
User: user,
Password: pass,
DBName: dbName,
})
@ -104,7 +112,7 @@ func initMySQLDB() {
func initPostgresDB() {
db, err := sql.Open("postgres", dbconfig.PostgresConnectString)
if err != nil {
panic("Failed to connect to test db")
panic("Failed to connect to test db: " + err.Error())
}
defer func() {
err := db.Close()

View file

@ -27,7 +27,7 @@ var defaultActorSQLBuilderFilePath = path.Join(tempTestDir, "jetdb/dvds/table",
var dbConnection = postgres.DBConnection{
Host: dbconfig.PgHost,
Port: 5432,
Port: dbconfig.PgPort,
User: dbconfig.PgUser,
Password: dbconfig.PgPassword,
DBName: dbconfig.PgDBName,

View file

@ -7,6 +7,7 @@ import (
"os/exec"
"path/filepath"
"reflect"
"strconv"
"testing"
"github.com/go-jet/jet/v2/generator/postgres"
@ -52,8 +53,13 @@ func TestCmdGenerator(t *testing.T) {
err := os.RemoveAll(genTestDir2)
require.NoError(t, err)
cmd := exec.Command("jet", "-source=PostgreSQL", "-dbname=jetdb", "-host=localhost", "-port=5432",
"-user=jet", "-password=jet", "-schema=dvds", "-path="+genTestDir2)
cmd := exec.Command("jet", "-source=PostgreSQL", "-dbname=jetdb", "-host=localhost",
"-port="+strconv.Itoa(dbconfig.PgPort),
"-user=jet",
"-password=jet",
"-schema=dvds",
"-path="+genTestDir2)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout