mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
ent/integration: enable postgres in json tests
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/133 Reviewed By: alexsn Differential Revision: D18227305 fbshipit-source-id: 33718041db52014f82dad831b5b609c511e0ba9a
This commit is contained in:
committed by
Facebook Github Bot
parent
38fcf995d0
commit
a9d787edf7
@@ -8,17 +8,20 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/facebookincubator/ent/dialect"
|
||||
"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/go-sql-driver/mysql"
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -53,6 +56,33 @@ func TestMySQL(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostgres(t *testing.T) {
|
||||
for version, port := range map[string]int{"10": 5430, "11": 5431, "12": 5432} {
|
||||
t.Run(version, func(t *testing.T) {
|
||||
dsn := fmt.Sprintf("host=localhost port=%d user=postgres password=pass sslmode=disable", port)
|
||||
db, err := sql.Open(dialect.Postgres, dsn)
|
||||
require.NoError(t, err)
|
||||
defer db.Close()
|
||||
_, err = db.Exec("CREATE DATABASE json")
|
||||
require.NoError(t, err, "creating database")
|
||||
defer db.Exec("DROP DATABASE json")
|
||||
|
||||
client, err := ent.Open(dialect.Postgres, dsn+" dbname=json")
|
||||
require.NoError(t, err, "connecting to json database")
|
||||
defer client.Close()
|
||||
err = client.Schema.Create(context.Background(), migrate.WithGlobalUniqueID(true))
|
||||
require.NoError(t, err)
|
||||
|
||||
URL(t, client)
|
||||
Dirs(t, client)
|
||||
Ints(t, client)
|
||||
Floats(t, client)
|
||||
Strings(t, client)
|
||||
RawMessage(t, client)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Ints(t *testing.T, client *ent.Client) {
|
||||
ctx := context.Background()
|
||||
ints := []int{1, 2, 3}
|
||||
|
||||
Reference in New Issue
Block a user