From a9d787edf7d382a3b0fd555783af623c86c6b5e6 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Wed, 30 Oct 2019 12:51:26 -0700 Subject: [PATCH] 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 --- entc/integration/json/json_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/entc/integration/json/json_test.go b/entc/integration/json/json_test.go index 800cd1749..feafefdd0 100644 --- a/entc/integration/json/json_test.go +++ b/entc/integration/json/json_test.go @@ -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}