Update circle ci for MySQL tests.

This commit is contained in:
go-jet 2019-08-08 10:51:59 +02:00
parent fbf5fbddbc
commit 4c5584aaae
8 changed files with 77 additions and 53 deletions

View file

@ -14,6 +14,14 @@ jobs:
POSTGRES_PASSWORD: jet POSTGRES_PASSWORD: jet
POSTGRES_DB: jetdb POSTGRES_DB: jetdb
- image: circleci/php:7.1-apache-node-browsers # The primary container where steps are run
- image: circleci/mysql:8.0.4
environment:
MYSQL_ROOT_PASSWORD: rootpw
MYSQL_DATABASE: test_db
MYSQL_USER: user
MYSQL_PASSWORD: passw0rd
working_directory: /go/src/github.com/go-jet/jet working_directory: /go/src/github.com/go-jet/jet
environment: # environment variables for the build itself environment: # environment variables for the build itself
@ -28,6 +36,7 @@ jobs:
command: | command: |
go get github.com/google/uuid go get github.com/google/uuid
go get github.com/lib/pq go get github.com/lib/pq
go get github.com/go-sql-driver/mysql
go get github.com/pkg/profile go get github.com/pkg/profile
go get gotest.tools/assert go get gotest.tools/assert
@ -48,14 +57,29 @@ jobs:
echo Failed waiting for Postgres && exit 1 echo Failed waiting for Postgres && exit 1
- run: - run:
name: Init Postgres database name: Waiting for MySQL to be ready
command: | command: |
cd tests for i in `seq 1 10`;
go run ./init/init.go do
cd .. nc -z 127.0.0.1 3306 && echo Success && exit 0
echo -n .
sleep 1
done
echo Failed waiting for MySQL && exit 1
- run:
name: Install MySQL CLI;
command: |
sudo apt-get install default-mysql-client
- run:
name: Init Postgres and MySQL database
command: |
cd tests
go run ./init/init.go
cd ..
- run: mkdir -p $TEST_RESULTS - run: mkdir -p $TEST_RESULTS
- run: go test -v . ./tests -coverpkg=github.com/go-jet/jet,github.com/go-jet/jet/execution/...,github.com/go-jet/jet/generator/...,github.com/go-jet/jet/internal/... -coverprofile=cover.out 2>&1 | go-junit-report > $TEST_RESULTS/results.xml - run: go test -v ./... -coverpkg=github.com/go-jet/jet/postgres/...,github.com/go-jet/mysql/...,github.com/go-jet/jet/execution/...,github.com/go-jet/jet/generator/...,github.com/go-jet/jet/internal/... -coverprofile=cover.out 2>&1 | go-junit-report > $TEST_RESULTS/results.xml
- run: - run:
name: Upload code coverage name: Upload code coverage

View file

@ -85,7 +85,7 @@ func (c ColumnInfo) GoBaseType() string {
case "uuid": case "uuid":
return "uuid.UUID" return "uuid.UUID"
default: default:
fmt.Println("Unsupported sql type: " + c.DataType + ", " + c.EnumName + ", using string instead for model type.") fmt.Println("Unsupported sql type: " + c.DataType + ", using string instead for model type.")
return "string" return "string"
} }
} }

View file

@ -1,7 +1,6 @@
package jet package jet
import ( import (
"fmt"
"gotest.tools/assert" "gotest.tools/assert"
"testing" "testing"
) )
@ -106,9 +105,6 @@ func assertStatement(t *testing.T, query Statement, expectedQuery string, expect
queryStr, args, err := query.Sql() queryStr, args, err := query.Sql()
assert.NilError(t, err) assert.NilError(t, err)
fmt.Println(queryStr)
//fmt.Println(queryStr)
assert.Equal(t, queryStr, expectedQuery) assert.Equal(t, queryStr, expectedQuery)
assert.DeepEqual(t, args, expectedArgs) assert.DeepEqual(t, args, expectedArgs)
} }

View file

@ -8,27 +8,14 @@ import (
"github.com/go-jet/jet/internal/jet" "github.com/go-jet/jet/internal/jet"
"gotest.tools/assert" "gotest.tools/assert"
"io/ioutil" "io/ioutil"
"os"
"path/filepath"
"runtime" "runtime"
"strings" "strings"
"testing" "testing"
"time" "time"
) )
func JsonPrint(v interface{}) {
jsonText, _ := json.MarshalIndent(v, "", "\t")
fmt.Println(string(jsonText))
}
func JsonSave(v interface{}, path string) {
jsonText, _ := json.MarshalIndent(v, "", "\t")
err := ioutil.WriteFile(path, jsonText, 0644)
if err != nil {
panic(err)
}
}
func AssertExec(t *testing.T, stmt jet.Statement, db execution.DB, rowsAffected ...int64) { func AssertExec(t *testing.T, stmt jet.Statement, db execution.DB, rowsAffected ...int64) {
res, err := stmt.Exec(db) res, err := stmt.Exec(db)
@ -47,6 +34,16 @@ func AssertExecErr(t *testing.T, stmt jet.Statement, db execution.DB, errorStr s
assert.Error(t, err, errorStr) assert.Error(t, err, errorStr)
} }
func getFullPath(relativePath string) string {
goPath := os.Getenv("GOPATH")
return filepath.Join(goPath, "src/github.com/go-jet/jet/tests", relativePath)
}
func PrintJson(v interface{}) {
jsonText, _ := json.MarshalIndent(v, "", "\t")
fmt.Println(string(jsonText))
}
func AssertJSON(t *testing.T, data interface{}, expectedJSON string) { func AssertJSON(t *testing.T, data interface{}, expectedJSON string) {
jsonData, err := json.MarshalIndent(data, "", "\t") jsonData, err := json.MarshalIndent(data, "", "\t")
assert.NilError(t, err) assert.NilError(t, err)
@ -54,8 +51,21 @@ func AssertJSON(t *testing.T, data interface{}, expectedJSON string) {
assert.Equal(t, "\n"+string(jsonData)+"\n", expectedJSON) assert.Equal(t, "\n"+string(jsonData)+"\n", expectedJSON)
} }
func AssertJSONFile(t *testing.T, data interface{}, jsonFilePath string) { func SaveJsonFile(v interface{}, testRelativePath string) {
fileJSONData, err := ioutil.ReadFile(jsonFilePath) jsonText, _ := json.MarshalIndent(v, "", "\t")
filePath := getFullPath(testRelativePath)
err := ioutil.WriteFile(filePath, jsonText, 0644)
if err != nil {
panic(err)
}
}
func AssertJSONFile(t *testing.T, data interface{}, testRelativePath string) {
filePath := getFullPath(testRelativePath)
fileJSONData, err := ioutil.ReadFile(filePath)
assert.NilError(t, err) assert.NilError(t, err)
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {

View file

@ -1,7 +1,6 @@
package mysql package mysql
import ( import (
"fmt"
"github.com/go-jet/jet/internal/testutils" "github.com/go-jet/jet/internal/testutils"
"github.com/go-jet/jet/tests/.gentestdata/mysql/test_sample/model" "github.com/go-jet/jet/tests/.gentestdata/mysql/test_sample/model"
. "github.com/go-jet/jet/tests/.gentestdata/mysql/test_sample/table" . "github.com/go-jet/jet/tests/.gentestdata/mysql/test_sample/table"
@ -26,7 +25,7 @@ func TestAllTypes(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
//testutils.JsonPrint(dest) //testutils.PrintJson(dest)
testutils.AssertJSON(t, dest, allTypesJson) testutils.AssertJSON(t, dest, allTypesJson)
} }
@ -96,7 +95,7 @@ LIMIT ?;
assert.NilError(t, err) assert.NilError(t, err)
//testutils.JsonPrint(dest) //testutils.PrintJson(dest)
testutils.AssertJSON(t, dest, ` testutils.AssertJSON(t, dest, `
[ [
@ -421,7 +420,7 @@ LIMIT ?;
assert.NilError(t, err) assert.NilError(t, err)
//testutils.JsonPrint(dest) //testutils.PrintJson(dest)
testutils.AssertJSONFile(t, dest, "./testdata/common/int_operators.json") testutils.AssertJSONFile(t, dest, "./testdata/common/int_operators.json")
} }
@ -523,7 +522,7 @@ func TestTimeExpressions(t *testing.T) {
CURRENT_TIME(3), CURRENT_TIME(3),
) )
fmt.Println(query.Sql()) //fmt.Println(query.Sql())
testutils.AssertStatementSql(t, query, ` testutils.AssertStatementSql(t, query, `
SELECT CAST(? AS TIME), SELECT CAST(? AS TIME),
@ -711,7 +710,7 @@ func TestTimestampExpressions(t *testing.T) {
CURRENT_TIMESTAMP(2), CURRENT_TIMESTAMP(2),
) )
fmt.Println(query.DebugSql()) //fmt.Println(query.DebugSql())
testutils.AssertDebugStatementSql(t, query, ` testutils.AssertDebugStatementSql(t, query, `
SELECT all_types.timestamp = all_types.timestamp, SELECT all_types.timestamp = all_types.timestamp,
@ -756,7 +755,7 @@ func TestTimeLiterals(t *testing.T) {
TimestampT(timeT).AS("timestampT"), TimestampT(timeT).AS("timestampT"),
).FROM(AllTypes).LIMIT(1) ).FROM(AllTypes).LIMIT(1)
fmt.Println(query.Sql()) //fmt.Println(query.Sql())
testutils.AssertStatementSql(t, query, ` testutils.AssertStatementSql(t, query, `
SELECT CAST(? AS DATE) AS "date", SELECT CAST(? AS DATE) AS "date",
@ -783,7 +782,7 @@ LIMIT ?;
err = query.Query(db, &dest) err = query.Query(db, &dest)
assert.NilError(t, err) assert.NilError(t, err)
testutils.JsonPrint(dest) //testutils.PrintJson(dest)
testutils.AssertJSON(t, dest, ` testutils.AssertJSON(t, dest, `
{ {

View file

@ -63,8 +63,8 @@ ORDER BY actor.actor_id;
assert.Equal(t, len(dest), 200) assert.Equal(t, len(dest), 200)
assert.DeepEqual(t, dest[0], actor1) assert.DeepEqual(t, dest[0], actor1)
//testutils.JsonPrint(dest) //testutils.PrintJson(dest)
//testutils.JsonSave(dest, "mysql/testdata/all_actors.json") //testutils.SaveJsonFile(dest, "mysql/testdata/all_actors.json")
testutils.AssertJSONFile(t, dest, "mysql/testdata/all_actors.json") testutils.AssertJSONFile(t, dest, "mysql/testdata/all_actors.json")
} }
@ -129,11 +129,11 @@ ORDER BY payment.customer_id, SUM(payment.amount) ASC;
assert.NilError(t, err) assert.NilError(t, err)
//testutils.JsonPrint(dest) //testutils.PrintJson(dest)
assert.Equal(t, len(dest), 174) assert.Equal(t, len(dest), 174)
//testutils.JsonSave(dest, "mysql/testdata/customer_payment_sum.json") //testutils.SaveJsonFile(dest, "mysql/testdata/customer_payment_sum.json")
testutils.AssertJSONFile(t, dest, "mysql/testdata/customer_payment_sum.json") testutils.AssertJSONFile(t, dest, "mysql/testdata/customer_payment_sum.json")
} }
@ -169,7 +169,7 @@ func TestSubQuery(t *testing.T) {
err := query.Query(db, &dest) err := query.Query(db, &dest)
assert.NilError(t, err) assert.NilError(t, err)
//testutils.JsonSave(dest, "mysql/testdata/r_rating_films.json") //testutils.SaveJsonFile(dest, "mysql/testdata/r_rating_films.json")
testutils.AssertJSONFile(t, dest, "mysql/testdata/r_rating_films.json") testutils.AssertJSONFile(t, dest, "mysql/testdata/r_rating_films.json")
} }
@ -317,7 +317,7 @@ LIMIT ?;
//assert.Equal(t, len(dest[0].Films), 10) //assert.Equal(t, len(dest[0].Films), 10)
//assert.Equal(t, len(dest[0].Films[0].Actors), 10) //assert.Equal(t, len(dest[0].Films[0].Actors), 10)
//testutils.JsonSave(dest, "./mysql/testdata/lang_film_actor_inventory_rental.json") //testutils.SaveJsonFile(dest, "./mysql/testdata/lang_film_actor_inventory_rental.json")
testutils.AssertJSONFile(t, dest, "./mysql/testdata/lang_film_actor_inventory_rental.json") testutils.AssertJSONFile(t, dest, "./mysql/testdata/lang_film_actor_inventory_rental.json")
} }

View file

@ -1,7 +1,6 @@
package postgres package postgres
import ( import (
"fmt"
"github.com/go-jet/jet/internal/testutils" "github.com/go-jet/jet/internal/testutils"
"github.com/go-jet/jet/postgres" "github.com/go-jet/jet/postgres"
. "github.com/go-jet/jet/postgres" . "github.com/go-jet/jet/postgres"
@ -94,7 +93,7 @@ LIMIT $5;
assert.NilError(t, err) assert.NilError(t, err)
//testutils.JsonPrint(dest) //testutils.PrintJson(dest)
testutils.AssertJSON(t, dest, ` testutils.AssertJSON(t, dest, `
[ [
@ -233,11 +232,7 @@ func TestStringOperators(t *testing.T) {
TO_HEX(AllTypes.IntegerPtr), TO_HEX(AllTypes.IntegerPtr),
) )
//_, args, _ := query.Sql()
//fmt.Println(query.Sql()) //fmt.Println(query.Sql())
//fmt.Println(args[15])
fmt.Println(query.Sql())
err := query.Query(db, &struct{}{}) err := query.Query(db, &struct{}{})
@ -408,7 +403,7 @@ LIMIT $35;
assert.NilError(t, err) assert.NilError(t, err)
//testutils.JsonPrint(dest) //testutils.PrintJson(dest)
testutils.AssertJSONFile(t, dest, "./testdata/common/float_operators.json") testutils.AssertJSONFile(t, dest, "./testdata/common/float_operators.json")
} }
@ -485,7 +480,7 @@ func TestIntegerOperators(t *testing.T) {
CBRT(ABSi(AllTypes.BigInt)).AS("cbrt"), CBRT(ABSi(AllTypes.BigInt)).AS("cbrt"),
).LIMIT(2) ).LIMIT(2)
fmt.Println(query.Sql()) //fmt.Println(query.Sql())
testutils.AssertStatementSql(t, query, ` testutils.AssertStatementSql(t, query, `
SELECT all_types.big_int AS "all_types.big_int", SELECT all_types.big_int AS "all_types.big_int",
@ -547,8 +542,8 @@ LIMIT $22;
assert.NilError(t, err) assert.NilError(t, err)
//testutils.JsonSave("./testdata/common/int_operators.json", dest) //testutils.SaveJsonFile("./testdata/common/int_operators.json", dest)
//testutils.JsonPrint(dest) //testutils.PrintJson(dest)
testutils.AssertJSONFile(t, dest, "./testdata/common/int_operators.json") testutils.AssertJSONFile(t, dest, "./testdata/common/int_operators.json")
} }

View file

@ -1051,11 +1051,11 @@ ORDER BY customer.customer_id, SUM(payment.amount) ASC;
assert.NilError(t, err) assert.NilError(t, err)
//testutils.JsonPrint(dest) //testutils.PrintJson(dest)
assert.Equal(t, len(dest), 104) assert.Equal(t, len(dest), 104)
//testutils.JsonSave(dest, "postgres/testdata/customer_payment_sum.json") //testutils.SaveJsonFile(dest, "postgres/testdata/customer_payment_sum.json")
testutils.AssertJSONFile(t, dest, "postgres/testdata/customer_payment_sum.json") testutils.AssertJSONFile(t, dest, "postgres/testdata/customer_payment_sum.json")
} }