-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
connection_details_test.go
105 lines (91 loc) · 2.37 KB
/
connection_details_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package pop
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_ConnectionDetails_Finalize(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
URL: "postgres://user:pass%23@host:1234/database",
}
err := cd.Finalize()
r.NoError(err)
r.Equal("database", cd.Database)
r.Equal("postgres", cd.Dialect)
r.Equal("host", cd.Host)
r.Equal("pass#", cd.Password)
r.Equal("1234", cd.Port)
r.Equal("user", cd.User)
}
func Test_ConnectionDetails_Finalize_MySQL_Standard(t *testing.T) {
r := require.New(t)
url := "mysql://user:pass#@(host:1337)/database?param1=value1¶m2=value2"
cd := &ConnectionDetails{
URL: url,
}
err := cd.Finalize()
r.NoError(err)
r.Equal(url, cd.URL)
r.Equal("mysql", cd.Dialect)
r.Equal("user", cd.User)
r.Equal("pass#", cd.Password)
r.Equal("host", cd.Host)
r.Equal("1337", cd.Port)
r.Equal("database", cd.Database)
}
func Test_ConnectionDetails_Finalize_Cockroach(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "cockroach",
URL: "postgres://user:pass%23@host:1234/database?sslmode=require&sslrootcert=certs/ca.crt&sslkey=certs/client.key&sslcert=certs/client.crt",
}
err := cd.Finalize()
r.NoError(err)
r.Equal("cockroach", cd.Dialect)
r.Equal("database", cd.Database)
r.Equal("host", cd.Host)
r.Equal("1234", cd.Port)
r.Equal("user", cd.User)
r.Equal("pass#", cd.Password)
}
func Test_ConnectionDetails_Finalize_UnknownSchemeURL(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
URL: "unknown://user:pass@host:1337/database",
}
err := cd.Finalize()
r.Error(err)
}
func Test_ConnectionDetails_Finalize_UnknownDialect(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "unknown",
}
err := cd.Finalize()
r.Error(err)
}
func Test_ConnectionDetails_Finalize_NoDB_NoURL(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "sqlite3",
}
err := cd.Finalize()
r.Error(err)
}
func Test_ConnectionDetails_OptionsString_Postgres(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "postgres",
Database: "database",
Host: "host",
Port: "1234",
User: "user",
Password: "pass",
Options: map[string]string{
"migration_table_name": "migrations",
"sslmode": "require",
},
}
r.Equal("sslmode=require", cd.OptionsString(""))
r.Equal("migrations", cd.MigrationTableName())
}