diff --git a/.circleci/config.yml b/.circleci/config.yml index 16409d3a6..e086cedf7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,33 +7,41 @@ jobs: unit: docker: - image: circleci/golang - working_directory: /go/src/github.com/facebookincubator/ent steps: - checkout + - run: &mktestdir + name: Create results directory + command: mkdir -p ~/test-results - run: name: Dialect tests - command: go test -v ./dialect/... + command: gotestsum --junitfile ~/test-results/dialect.xml + working_directory: dialect - run: name: Schema tests - command: go test -v ./schema/... + command: gotestsum --junitfile ~/test-results/schema.xml + working_directory: schema - run: name: Loader tests - command: go test -v ./entc/load/... + command: gotestsum --junitfile ~/test-results/load.xml + working_directory: entc/load - run: name: Codegen tests - command: go test -v ./entc/gen/... + command: gotestsum --junitfile ~/test-results/gen.xml + working_directory: entc/gen + - store_test_results: + path: ~/test-results integration: docker: - image: circleci/golang - - image: mysql:5.6.35 + - image: circleci/mysql:5.6.35 environment: &mysql_env MYSQL_DATABASE: test MYSQL_ROOT_PASSWORD: pass - - image: mysql:5.7.26 + - image: circleci/mysql:5.7.26 environment: <<: *mysql_env MYSQL_TCP_PORT: 3307 - - image: mysql:8 + - image: circleci/mysql:8 environment: <<: *mysql_env MYSQL_TCP_PORT: 3308 @@ -42,10 +50,21 @@ jobs: command: conf/gremlin-server.yaml steps: - checkout + - run: + name: Wait for databases + command: >- + dockerize -timeout 1m + -wait tcp://localhost:3306 + -wait tcp://localhost:3307 + -wait tcp://localhost:3308 + -wait tcp://localhost:8182 + - run: *mktestdir - run: name: Run integration tests working_directory: entc/integration - command: go test -v -race ./... + command: gotestsum --junitfile ~/test-results/integration.xml -- -race ./... + - store_test_results: + path: ~/test-results docs: docker: - image: circleci/node diff --git a/entc/integration/compose/Dockerfile b/entc/integration/compose/Dockerfile index 10d120d53..fc89c59a0 100644 --- a/entc/integration/compose/Dockerfile +++ b/entc/integration/compose/Dockerfile @@ -3,7 +3,7 @@ # in the LICENSE file in the root directory of this source tree. # Application base -FROM golang:1.13 +FROM golang:1.13-alpine # Install tools required to build the project RUN apk add --no-cache git gcc musl-dev diff --git a/entc/integration/integration_test.go b/entc/integration/integration_test.go index eec47fafc..c774a36e8 100644 --- a/entc/integration/integration_test.go +++ b/entc/integration/integration_test.go @@ -8,9 +8,11 @@ import ( "context" "fmt" "math" + "net" "reflect" "runtime" "sort" + "strconv" "strings" "testing" "time" @@ -23,8 +25,8 @@ import ( "github.com/facebookincubator/ent/entc/integration/ent/node" "github.com/facebookincubator/ent/entc/integration/ent/pet" "github.com/facebookincubator/ent/entc/integration/ent/user" + "github.com/go-sql-driver/mysql" - _ "github.com/go-sql-driver/mysql" _ "github.com/mattn/go-sqlite3" "github.com/stretchr/testify/require" ) @@ -45,8 +47,12 @@ func TestSQLite(t *testing.T) { func TestMySQL(t *testing.T) { for version, port := range map[string]int{"56": 3306, "57": 3307, "8": 3308} { + addr := net.JoinHostPort("localhost", strconv.Itoa(port)) t.Run(version, func(t *testing.T) { - client, err := ent.Open("mysql", fmt.Sprintf("root:pass@tcp(localhost:%d)/test?parseTime=True", port)) + client, err := ent.Open("mysql", (&mysql.Config{ + User: "root", Passwd: "pass", Net: "tcp", Addr: addr, + DBName: "test", ParseTime: true, AllowNativePasswords: true, + }).FormatDSN()) require.NoError(t, err) defer client.Close() require.NoError(t, client.Schema.Create(context.Background())) diff --git a/entc/integration/json/json_test.go b/entc/integration/json/json_test.go index 0054f0e3e..800cd1749 100644 --- a/entc/integration/json/json_test.go +++ b/entc/integration/json/json_test.go @@ -6,37 +6,42 @@ package json import ( "context" + "database/sql" "encoding/json" - "fmt" + "net" "net/http" "net/url" + "strconv" "testing" "github.com/facebookincubator/ent/entc/integration/json/ent" "github.com/facebookincubator/ent/entc/integration/json/ent/migrate" "github.com/facebookincubator/ent/entc/integration/json/ent/user" - "github.com/facebookincubator/ent/dialect/sql" - - _ "github.com/go-sql-driver/mysql" + "github.com/go-sql-driver/mysql" "github.com/stretchr/testify/require" ) func TestMySQL(t *testing.T) { for version, port := range map[string]int{"56": 3306, "57": 3307, "8": 3308} { + addr := net.JoinHostPort("localhost", strconv.Itoa(port)) t.Run(version, func(t *testing.T) { - root, err := sql.Open("mysql", fmt.Sprintf("root:pass@tcp(localhost:%d)/", port)) + cfg := mysql.Config{ + User: "root", Passwd: "pass", Net: "tcp", Addr: addr, + AllowNativePasswords: true, ParseTime: true, + } + db, err := sql.Open("mysql", cfg.FormatDSN()) require.NoError(t, err) - defer root.Close() - ctx := context.Background() - err = root.Exec(ctx, "CREATE DATABASE IF NOT EXISTS json", []interface{}{}, new(sql.Result)) + defer db.Close() + _, err = db.Exec("CREATE DATABASE IF NOT EXISTS json") require.NoError(t, err, "creating database") - defer root.Exec(ctx, "DROP DATABASE IF EXISTS json", []interface{}{}, new(sql.Result)) + defer db.Exec("DROP DATABASE IF EXISTS json") - drv, err := sql.Open("mysql", fmt.Sprintf("root:pass@tcp(localhost:%d)/json?parseTime=True", port)) - require.NoError(t, err, "connecting to migrate database") - client := ent.NewClient(ent.Driver(drv)) - require.NoError(t, client.Schema.Create(ctx, migrate.WithGlobalUniqueID(true))) + cfg.DBName = "json" + client, err := ent.Open("mysql", cfg.FormatDSN()) + require.NoError(t, err, "connecting to json database") + err = client.Schema.Create(context.Background(), migrate.WithGlobalUniqueID(true)) + require.NoError(t, err) URL(t, client) Dirs(t, client)