mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/integ: move integration tests to enttest (#444)
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
|||||||
|
|
||||||
"github.com/facebookincubator/ent/dialect"
|
"github.com/facebookincubator/ent/dialect"
|
||||||
"github.com/facebookincubator/ent/entc/integration/ent"
|
"github.com/facebookincubator/ent/entc/integration/ent"
|
||||||
|
"github.com/facebookincubator/ent/entc/integration/ent/enttest"
|
||||||
"github.com/facebookincubator/ent/entc/integration/ent/file"
|
"github.com/facebookincubator/ent/entc/integration/ent/file"
|
||||||
"github.com/facebookincubator/ent/entc/integration/ent/group"
|
"github.com/facebookincubator/ent/entc/integration/ent/group"
|
||||||
"github.com/facebookincubator/ent/entc/integration/ent/groupinfo"
|
"github.com/facebookincubator/ent/entc/integration/ent/groupinfo"
|
||||||
@@ -30,17 +31,15 @@ import (
|
|||||||
"github.com/facebookincubator/ent/entc/integration/ent/user"
|
"github.com/facebookincubator/ent/entc/integration/ent/user"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
|
|
||||||
"github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSQLite(t *testing.T) {
|
func TestSQLite(t *testing.T) {
|
||||||
client, err := ent.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")
|
client := enttest.Open(t, dialect.SQLite, "file:ent?mode=memory&cache=shared&_fk=1", opts)
|
||||||
require.NoError(t, err)
|
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
require.NoError(t, client.Schema.Create(context.Background(), migrate.WithDropColumn(true), migrate.WithDropIndex(true)))
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
name := runtime.FuncForPC(reflect.ValueOf(tt).Pointer()).Name()
|
name := runtime.FuncForPC(reflect.ValueOf(tt).Pointer()).Name()
|
||||||
t.Run(name[strings.LastIndex(name, ".")+1:], func(t *testing.T) {
|
t.Run(name[strings.LastIndex(name, ".")+1:], func(t *testing.T) {
|
||||||
@@ -55,13 +54,8 @@ func TestMySQL(t *testing.T) {
|
|||||||
for version, port := range map[string]int{"56": 3306, "57": 3307, "8": 3308} {
|
for version, port := range map[string]int{"56": 3306, "57": 3307, "8": 3308} {
|
||||||
addr := net.JoinHostPort("localhost", strconv.Itoa(port))
|
addr := net.JoinHostPort("localhost", strconv.Itoa(port))
|
||||||
t.Run(version, func(t *testing.T) {
|
t.Run(version, func(t *testing.T) {
|
||||||
client, err := ent.Open("mysql", (&mysql.Config{
|
client := enttest.Open(t, dialect.MySQL, fmt.Sprintf("root:pass@tcp(%s)/test?parseTime=True", addr), opts)
|
||||||
User: "root", Passwd: "pass", Net: "tcp", Addr: addr,
|
|
||||||
DBName: "test", ParseTime: true, AllowNativePasswords: true,
|
|
||||||
}).FormatDSN())
|
|
||||||
require.NoError(t, err)
|
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
require.NoError(t, client.Schema.Create(context.Background(), migrate.WithDropColumn(true), migrate.WithDropIndex(true)))
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
name := runtime.FuncForPC(reflect.ValueOf(tt).Pointer()).Name()
|
name := runtime.FuncForPC(reflect.ValueOf(tt).Pointer()).Name()
|
||||||
t.Run(name[strings.LastIndex(name, ".")+1:], func(t *testing.T) {
|
t.Run(name[strings.LastIndex(name, ".")+1:], func(t *testing.T) {
|
||||||
@@ -76,10 +70,8 @@ func TestMySQL(t *testing.T) {
|
|||||||
func TestPostgres(t *testing.T) {
|
func TestPostgres(t *testing.T) {
|
||||||
for version, port := range map[string]int{"10": 5430, "11": 5431, "12": 5432} {
|
for version, port := range map[string]int{"10": 5430, "11": 5431, "12": 5432} {
|
||||||
t.Run(version, func(t *testing.T) {
|
t.Run(version, func(t *testing.T) {
|
||||||
client, err := ent.Open(dialect.Postgres, fmt.Sprintf("host=localhost port=%d user=postgres dbname=test password=pass sslmode=disable", port))
|
client := enttest.Open(t, dialect.Postgres, fmt.Sprintf("host=localhost port=%d user=postgres dbname=test password=pass sslmode=disable", port), opts)
|
||||||
require.NoError(t, err)
|
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
require.NoError(t, client.Schema.Create(context.Background(), migrate.WithDropColumn(true), migrate.WithDropIndex(true)))
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
name := runtime.FuncForPC(reflect.ValueOf(tt).Pointer()).Name()
|
name := runtime.FuncForPC(reflect.ValueOf(tt).Pointer()).Name()
|
||||||
t.Run(name[strings.LastIndex(name, ".")+1:], func(t *testing.T) {
|
t.Run(name[strings.LastIndex(name, ".")+1:], func(t *testing.T) {
|
||||||
@@ -91,34 +83,39 @@ func TestPostgres(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// tests for all drivers to run.
|
var (
|
||||||
var tests = [...]func(*testing.T, *ent.Client){
|
opts = enttest.WithMigrateOptions(
|
||||||
Tx,
|
migrate.WithDropIndex(true),
|
||||||
Indexes,
|
migrate.WithDropColumn(true),
|
||||||
Types,
|
)
|
||||||
Clone,
|
tests = [...]func(*testing.T, *ent.Client){
|
||||||
Sanity,
|
Tx,
|
||||||
Paging,
|
Indexes,
|
||||||
Select,
|
Types,
|
||||||
Delete,
|
Clone,
|
||||||
Relation,
|
Sanity,
|
||||||
Predicate,
|
Paging,
|
||||||
AddValues,
|
Select,
|
||||||
ClearFields,
|
Delete,
|
||||||
UniqueConstraint,
|
Relation,
|
||||||
O2OTwoTypes,
|
Predicate,
|
||||||
O2OSameType,
|
AddValues,
|
||||||
O2OSelfRef,
|
ClearFields,
|
||||||
O2MTwoTypes,
|
UniqueConstraint,
|
||||||
O2MSameType,
|
O2OTwoTypes,
|
||||||
M2MSelfRef,
|
O2OSameType,
|
||||||
M2MSameType,
|
O2OSelfRef,
|
||||||
M2MTwoTypes,
|
O2MTwoTypes,
|
||||||
DefaultValue,
|
O2MSameType,
|
||||||
ImmutableValue,
|
M2MSelfRef,
|
||||||
Sensitive,
|
M2MSameType,
|
||||||
EagerLoading,
|
M2MTwoTypes,
|
||||||
}
|
DefaultValue,
|
||||||
|
ImmutableValue,
|
||||||
|
Sensitive,
|
||||||
|
EagerLoading,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func Sanity(t *testing.T, client *ent.Client) {
|
func Sanity(t *testing.T, client *ent.Client) {
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|||||||
Reference in New Issue
Block a user