Add support for running integration tests with dockerized test databases.
This commit is contained in:
parent
4d5abc85c6
commit
972fc1d9bf
13 changed files with 210 additions and 67 deletions
|
|
@ -31,10 +31,6 @@ func TestAllTypes(t *testing.T) {
|
|||
|
||||
require.Equal(t, len(dest), 2)
|
||||
|
||||
if sourceIsMariaDB() { // MariaDB saves current timestamp in a case of NULL value insert
|
||||
return
|
||||
}
|
||||
|
||||
//testutils.PrintJson(dest)
|
||||
testutils.AssertJSON(t, dest, allTypesJson)
|
||||
}
|
||||
|
|
@ -49,10 +45,6 @@ func TestAllTypesViewSelect(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, len(dest), 2)
|
||||
|
||||
if sourceIsMariaDB() { // MariaDB saves current timestamp in a case of NULL value insert
|
||||
return
|
||||
}
|
||||
|
||||
testutils.AssertJSON(t, dest, allTypesJson)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,18 +25,30 @@ var defaultViewSQLBuilderFilePath = path.Join(tempTestDir, "dvds/view")
|
|||
var defaultEnumSQLBuilderFilePath = path.Join(tempTestDir, "dvds/enum")
|
||||
var defaultActorSQLBuilderFilePath = path.Join(tempTestDir, "dvds/table", "actor.go")
|
||||
|
||||
var dbConnection = mysql2.DBConnection{
|
||||
Host: dbconfig.MySqLHost,
|
||||
Port: dbconfig.MySQLPort,
|
||||
User: dbconfig.MySQLUser,
|
||||
Password: dbconfig.MySQLPassword,
|
||||
DBName: "dvds",
|
||||
func dbConnection(dbName string) mysql2.DBConnection {
|
||||
if sourceIsMariaDB() {
|
||||
return mysql2.DBConnection{
|
||||
Host: dbconfig.MariaDBHost,
|
||||
Port: dbconfig.MariaDBPort,
|
||||
User: dbconfig.MariaDBUser,
|
||||
Password: dbconfig.MariaDBPassword,
|
||||
DBName: dbName,
|
||||
}
|
||||
}
|
||||
|
||||
return mysql2.DBConnection{
|
||||
Host: dbconfig.MySqLHost,
|
||||
Port: dbconfig.MySQLPort,
|
||||
User: dbconfig.MySQLUser,
|
||||
Password: dbconfig.MySQLPassword,
|
||||
DBName: dbName,
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneratorTemplate_Schema_ChangePath(t *testing.T) {
|
||||
err := mysql2.Generate(
|
||||
tempTestDir,
|
||||
dbConnection,
|
||||
dbConnection("dvds"),
|
||||
template.Default(postgres2.Dialect).
|
||||
UseSchema(func(schemaMetaData metadata.Schema) template.Schema {
|
||||
return template.DefaultSchema(schemaMetaData).UsePath("new/schema/path")
|
||||
|
|
@ -54,7 +66,7 @@ func TestGeneratorTemplate_Schema_ChangePath(t *testing.T) {
|
|||
func TestGeneratorTemplate_Model_SkipGeneration(t *testing.T) {
|
||||
err := mysql2.Generate(
|
||||
tempTestDir,
|
||||
dbConnection,
|
||||
dbConnection("dvds"),
|
||||
template.Default(postgres2.Dialect).
|
||||
UseSchema(func(schemaMetaData metadata.Schema) template.Schema {
|
||||
return template.DefaultSchema(schemaMetaData).
|
||||
|
|
@ -75,7 +87,7 @@ func TestGeneratorTemplate_Model_SkipGeneration(t *testing.T) {
|
|||
func TestGeneratorTemplate_SQLBuilder_SkipGeneration(t *testing.T) {
|
||||
err := mysql2.Generate(
|
||||
tempTestDir,
|
||||
dbConnection,
|
||||
dbConnection("dvds"),
|
||||
template.Default(postgres2.Dialect).
|
||||
UseSchema(func(schemaMetaData metadata.Schema) template.Schema {
|
||||
return template.DefaultSchema(schemaMetaData).
|
||||
|
|
@ -98,7 +110,7 @@ func TestGeneratorTemplate_Model_ChangePath(t *testing.T) {
|
|||
|
||||
err := mysql2.Generate(
|
||||
tempTestDir,
|
||||
dbConnection,
|
||||
dbConnection("dvds"),
|
||||
template.Default(postgres2.Dialect).
|
||||
UseSchema(func(schemaMetaData metadata.Schema) template.Schema {
|
||||
return template.DefaultSchema(schemaMetaData).
|
||||
|
|
@ -116,7 +128,7 @@ func TestGeneratorTemplate_SQLBuilder_ChangePath(t *testing.T) {
|
|||
|
||||
err := mysql2.Generate(
|
||||
tempTestDir,
|
||||
dbConnection,
|
||||
dbConnection("dvds"),
|
||||
template.Default(postgres2.Dialect).
|
||||
UseSchema(func(schemaMetaData metadata.Schema) template.Schema {
|
||||
return template.DefaultSchema(schemaMetaData).
|
||||
|
|
@ -137,7 +149,7 @@ func TestGeneratorTemplate_SQLBuilder_ChangePath(t *testing.T) {
|
|||
func TestGeneratorTemplate_Model_RenameFilesAndTypes(t *testing.T) {
|
||||
err := mysql2.Generate(
|
||||
tempTestDir,
|
||||
dbConnection,
|
||||
dbConnection("dvds"),
|
||||
template.Default(postgres2.Dialect).
|
||||
UseSchema(func(schemaMetaData metadata.Schema) template.Schema {
|
||||
return template.DefaultSchema(schemaMetaData).
|
||||
|
|
@ -175,7 +187,7 @@ func TestGeneratorTemplate_Model_RenameFilesAndTypes(t *testing.T) {
|
|||
func TestGeneratorTemplate_Model_SkipTableAndEnum(t *testing.T) {
|
||||
err := mysql2.Generate(
|
||||
tempTestDir,
|
||||
dbConnection,
|
||||
dbConnection("dvds"),
|
||||
template.Default(postgres2.Dialect).
|
||||
UseSchema(func(schemaMetaData metadata.Schema) template.Schema {
|
||||
return template.DefaultSchema(schemaMetaData).
|
||||
|
|
@ -203,7 +215,7 @@ func TestGeneratorTemplate_Model_SkipTableAndEnum(t *testing.T) {
|
|||
func TestGeneratorTemplate_SQLBuilder_SkipTableAndEnum(t *testing.T) {
|
||||
err := mysql2.Generate(
|
||||
tempTestDir,
|
||||
dbConnection,
|
||||
dbConnection("dvds"),
|
||||
template.Default(postgres2.Dialect).
|
||||
UseSchema(func(schemaMetaData metadata.Schema) template.Schema {
|
||||
return template.DefaultSchema(schemaMetaData).
|
||||
|
|
@ -236,7 +248,7 @@ func TestGeneratorTemplate_SQLBuilder_SkipTableAndEnum(t *testing.T) {
|
|||
func TestGeneratorTemplate_SQLBuilder_ChangeTypeAndFileName(t *testing.T) {
|
||||
err := mysql2.Generate(
|
||||
tempTestDir,
|
||||
dbConnection,
|
||||
dbConnection("dvds"),
|
||||
template.Default(postgres2.Dialect).
|
||||
UseSchema(func(schemaMetaData metadata.Schema) template.Schema {
|
||||
return template.DefaultSchema(schemaMetaData).
|
||||
|
|
@ -277,7 +289,7 @@ func TestGeneratorTemplate_Model_AddTags(t *testing.T) {
|
|||
|
||||
err := mysql2.Generate(
|
||||
tempTestDir,
|
||||
dbConnection,
|
||||
dbConnection("dvds"),
|
||||
template.Default(postgres2.Dialect).
|
||||
UseSchema(func(schemaMetaData metadata.Schema) template.Schema {
|
||||
return template.DefaultSchema(schemaMetaData).
|
||||
|
|
@ -318,7 +330,7 @@ func TestGeneratorTemplate_Model_AddTags(t *testing.T) {
|
|||
func TestGeneratorTemplate_Model_ChangeFieldTypes(t *testing.T) {
|
||||
err := mysql2.Generate(
|
||||
tempTestDir,
|
||||
dbConnection,
|
||||
dbConnection("dvds"),
|
||||
template.Default(postgres2.Dialect).
|
||||
UseSchema(func(schemaMetaData metadata.Schema) template.Schema {
|
||||
return template.DefaultSchema(schemaMetaData).
|
||||
|
|
@ -361,7 +373,7 @@ func TestGeneratorTemplate_Model_ChangeFieldTypes(t *testing.T) {
|
|||
func TestGeneratorTemplate_SQLBuilder_ChangeColumnTypes(t *testing.T) {
|
||||
err := mysql2.Generate(
|
||||
tempTestDir,
|
||||
dbConnection,
|
||||
dbConnection("dvds"),
|
||||
template.Default(postgres2.Dialect).
|
||||
UseSchema(func(schemaMetaData metadata.Schema) template.Schema {
|
||||
return template.DefaultSchema(schemaMetaData).
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package mysql
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/go-jet/jet/v2/generator/mysql"
|
||||
|
|
@ -19,13 +19,7 @@ const genTestDir3 = "./.gentestdata3/mysql"
|
|||
func TestGenerator(t *testing.T) {
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
err := mysql.Generate(genTestDir3, mysql.DBConnection{
|
||||
Host: dbconfig.MySqLHost,
|
||||
Port: dbconfig.MySQLPort,
|
||||
User: dbconfig.MySQLUser,
|
||||
Password: dbconfig.MySQLPassword,
|
||||
DBName: "dvds",
|
||||
})
|
||||
err := mysql.Generate(genTestDir3, dbConnection("dvds"))
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -33,17 +27,11 @@ func TestGenerator(t *testing.T) {
|
|||
}
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
dsn := fmt.Sprintf("%[1]s:%[2]s@tcp(%[3]s:%[4]d)/%[5]s",
|
||||
dbconfig.MySQLUser,
|
||||
dbconfig.MySQLPassword,
|
||||
dbconfig.MySqLHost,
|
||||
dbconfig.MySQLPort,
|
||||
"dvds",
|
||||
)
|
||||
dsn := dbconfig.MySQLConnectionString(sourceIsMariaDB(), "dvds")
|
||||
|
||||
err := mysql.GenerateDSN(dsn, genTestDir3)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
assertGeneratedFiles(t)
|
||||
}
|
||||
|
||||
|
|
@ -55,8 +43,27 @@ func TestCmdGenerator(t *testing.T) {
|
|||
err := os.RemoveAll(genTestDir3)
|
||||
require.NoError(t, err)
|
||||
|
||||
cmd := exec.Command("jet", "-source=MySQL", "-dbname=dvds", "-host=localhost", "-port=3306",
|
||||
"-user=jet", "-password=jet", "-path="+genTestDir3)
|
||||
var cmd *exec.Cmd
|
||||
|
||||
if sourceIsMariaDB() {
|
||||
cmd = exec.Command("jet",
|
||||
"-source=MariaDB",
|
||||
"-dbname=dvds",
|
||||
"-host="+dbconfig.MariaDBHost,
|
||||
"-port="+strconv.Itoa(dbconfig.MariaDBPort),
|
||||
"-user="+dbconfig.MariaDBUser,
|
||||
"-password="+dbconfig.MariaDBPassword,
|
||||
"-path="+genTestDir3)
|
||||
} else {
|
||||
cmd = exec.Command("jet",
|
||||
"-source=MySQL",
|
||||
"-dbname=dvds",
|
||||
"-host="+dbconfig.MySqLHost,
|
||||
"-port="+strconv.Itoa(dbconfig.MySQLPort),
|
||||
"-user="+dbconfig.MySQLUser,
|
||||
"-password="+dbconfig.MySQLPassword,
|
||||
"-path="+genTestDir3)
|
||||
}
|
||||
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = os.Stdout
|
||||
|
|
@ -70,13 +77,7 @@ func TestCmdGenerator(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// check that generation via DSN works
|
||||
dsn := fmt.Sprintf("mysql://%[1]s:%[2]s@tcp(%[3]s:%[4]d)/%[5]s",
|
||||
dbconfig.MySQLUser,
|
||||
dbconfig.MySQLPassword,
|
||||
dbconfig.MySqLHost,
|
||||
dbconfig.MySQLPort,
|
||||
"dvds",
|
||||
)
|
||||
dsn := "mysql://" + dbconfig.MySQLConnectionString(sourceIsMariaDB(), "dvds")
|
||||
cmd = exec.Command("jet", "-dsn="+dsn, "-path="+genTestDir3)
|
||||
|
||||
cmd.Stderr = os.Stderr
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ func TestMain(m *testing.M) {
|
|||
defer profile.Start().Stop()
|
||||
|
||||
var err error
|
||||
db, err = sql.Open("mysql", dbconfig.MySQLConnectionString)
|
||||
db, err = sql.Open("mysql", dbconfig.MySQLConnectionString(sourceIsMariaDB(), ""))
|
||||
if err != nil {
|
||||
panic("Failed to connect to test db" + err.Error())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -389,8 +389,6 @@ LIMIT ?;
|
|||
).
|
||||
LIMIT(1000)
|
||||
|
||||
//fmt.Println(query.Sql())
|
||||
|
||||
testutils.AssertStatementSql(t, query, expectedSQL, int64(1000))
|
||||
|
||||
var dest []struct {
|
||||
|
|
@ -414,12 +412,7 @@ LIMIT ?;
|
|||
err := query.Query(db, &dest)
|
||||
|
||||
require.NoError(t, err)
|
||||
//require.Equal(t, len(dest), 1)
|
||||
//require.Equal(t, len(dest[0].Films), 10)
|
||||
//require.Equal(t, len(dest[0].Films[0].Actors), 10)
|
||||
|
||||
//testutils.SaveJsonFile(dest, "./mysql/testdata/lang_film_actor_inventory_rental.json")
|
||||
|
||||
testutils.AssertJSONFile(t, dest, "./testdata/results/mysql/lang_film_actor_inventory_rental.json")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue