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