entc/gen: allow opening and testing concurrent enttest clients (#2665)

This commit is contained in:
Ariel Mashraki
2022-06-20 08:32:30 +03:00
committed by GitHub
parent abefaa7f24
commit 311d760679
71 changed files with 783 additions and 614 deletions

View File

@@ -48,6 +48,7 @@ import (
)
func TestSQLite(t *testing.T) {
t.Parallel()
client := enttest.Open(t, dialect.SQLite, "file:ent?mode=memory&cache=shared&_fk=1", opts)
defer client.Close()
for _, tt := range tests {
@@ -63,6 +64,7 @@ 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) {
t.Parallel()
client := enttest.Open(t, dialect.MySQL, fmt.Sprintf("root:pass@tcp(%s)/test?parseTime=True", addr), opts)
defer client.Close()
for _, tt := range tests {
@@ -78,8 +80,9 @@ func TestMySQL(t *testing.T) {
func TestMaria(t *testing.T) {
for version, port := range map[string]int{"10.5": 4306, "10.2": 4307, "10.3": 4308} {
addr := net.JoinHostPort("localhost", strconv.Itoa(port))
t.Run(version, func(t *testing.T) {
addr := net.JoinHostPort("localhost", strconv.Itoa(port))
t.Parallel()
client := enttest.Open(t, dialect.MySQL, fmt.Sprintf("root:pass@tcp(%s)/test?parseTime=True", addr), opts)
defer client.Close()
for _, tt := range tests {
@@ -95,8 +98,10 @@ func TestMaria(t *testing.T) {
func TestPostgres(t *testing.T) {
for version, port := range map[string]int{"10": 5430, "11": 5431, "12": 5432, "13": 5433, "14": 5434} {
addr := fmt.Sprintf("host=localhost port=%d user=postgres dbname=test password=pass sslmode=disable", port)
t.Run(version, func(t *testing.T) {
client := enttest.Open(t, dialect.Postgres, fmt.Sprintf("host=localhost port=%d user=postgres dbname=test password=pass sslmode=disable", port), opts)
t.Parallel()
client := enttest.Open(t, dialect.Postgres, addr, opts)
defer client.Close()
for _, tt := range tests {
name := runtime.FuncForPC(reflect.ValueOf(tt).Pointer()).Name()
@@ -1859,7 +1864,16 @@ func NoSchemaChanges(t *testing.T, client *ent.Client) {
}
return len(p), nil
})
err := client.Schema.WriteTo(context.Background(), w, migrate.WithDropIndex(true), migrate.WithDropColumn(true), sqlschema.WithAtlas(true))
tables, err := sqlschema.CopyTables(migrate.Tables)
require.NoError(t, err)
err = migrate.Create(
context.Background(),
migrate.NewSchema(&sqlschema.WriteDriver{Writer: w, Driver: client.Driver()}),
tables,
migrate.WithDropIndex(true),
migrate.WithDropColumn(true),
sqlschema.WithAtlas(true),
)
require.NoError(t, err)
}