ent/circleci: store go tests metadata (#63)

Summary:
Pull Request resolved: https://github.com/facebookincubator/ent/pull/63

Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1527

See https://circleci.com/blog/level-up-go-test-with-gotestsum/ for more info

Reviewed By: a8m

Differential Revision: D17761305

fbshipit-source-id: d16050b4e1825e8c23be5cc0a4b0dff80936b86a
This commit is contained in:
Alex Snast
2019-10-05 10:14:20 -07:00
committed by Facebook Github Bot
parent d581e01bb6
commit 5c93cb823c
4 changed files with 55 additions and 25 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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()))

View File

@@ -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)