github.com/naemono/pop@v4.13.1+incompatible/dialect_postgresql_test.go (about) 1 package pop 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/require" 7 ) 8 9 func Test_PostgreSQL_Connection_String(t *testing.T) { 10 r := require.New(t) 11 12 url := "host=host port=port dbname=database user=user password=pass" 13 cd := &ConnectionDetails{ 14 Dialect: "postgres", 15 URL: url, 16 } 17 err := cd.Finalize() 18 r.NoError(err) 19 20 r.Equal(url, cd.URL) 21 r.Equal("postgres", cd.Dialect) 22 r.Equal("host", cd.Host) 23 r.Equal("pass", cd.Password) 24 r.Equal("port", cd.Port) 25 r.Equal("user", cd.User) 26 r.Equal("database", cd.Database) 27 } 28 29 func Test_PostgreSQL_Connection_String_Options(t *testing.T) { 30 r := require.New(t) 31 32 url := "host=host port=port dbname=database user=user password=pass sslmode=disable fallback_application_name=test_app connect_timeout=10 sslcert=/some/location sslkey=/some/other/location sslrootcert=/root/location" 33 cd := &ConnectionDetails{ 34 Dialect: "postgres", 35 URL: url, 36 } 37 err := cd.Finalize() 38 r.NoError(err) 39 40 r.Equal(url, cd.URL) 41 42 r.Equal("disable", cd.Options["sslmode"]) 43 r.Equal("test_app", cd.Options["fallback_application_name"]) 44 r.Equal("10", cd.Options["connect_timeout"]) 45 r.Equal("/some/location", cd.Options["sslcert"]) 46 r.Equal("/some/other/location", cd.Options["sslkey"]) 47 r.Equal("/root/location", cd.Options["sslrootcert"]) 48 } 49 50 func Test_PostgreSQL_Connection_String_Without_User(t *testing.T) { 51 r := require.New(t) 52 53 url := "dbname=database" 54 cd := &ConnectionDetails{ 55 Dialect: "postgres", 56 URL: url, 57 } 58 err := cd.Finalize() 59 r.NoError(err) 60 61 r.Equal(url, cd.URL) 62 r.Equal("postgres", cd.Dialect) 63 r.Equal("", cd.Host) 64 r.Equal("", cd.Password) 65 r.Equal(portPostgreSQL, cd.Port) // fallback 66 r.Equal("", cd.User) 67 r.Equal("database", cd.Database) 68 } 69 70 func Test_PostgreSQL_Connection_String_Failure(t *testing.T) { 71 r := require.New(t) 72 73 url := "abc" 74 cd := &ConnectionDetails{ 75 Dialect: "postgres", 76 URL: url, 77 } 78 err := cd.Finalize() 79 r.Error(err) 80 r.Equal("postgres", cd.Dialect) 81 } 82 83 func Test_PostgreSQL_Quotable(t *testing.T) { 84 r := require.New(t) 85 p := postgresql{} 86 87 r.Equal(`"table_name"`, p.Quote("table_name")) 88 r.Equal(`"schema"."table_name"`, p.Quote("schema.table_name")) 89 r.Equal(`"schema"."table name"`, p.Quote(`"schema"."table name"`)) 90 }