-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
dialect_cockroach_test.go
140 lines (115 loc) · 3.84 KB
/
dialect_cockroach_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package pop
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func Test_Cockroach_ConnectionDetails_URL_Finalize(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "cockroach",
URL: "cockroach://user:pass%23@host:1234/database",
}
err := cd.Finalize()
r.NoError(err)
r.Equal("database", cd.Database)
r.Equal("cockroach", cd.Dialect)
r.Equal("host", cd.Host)
r.Equal("pass#", cd.Password)
r.Equal("1234", cd.Port)
r.Equal("user", cd.User)
}
func Test_Cockroach_ConnectionDetails_Values_Finalize(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "cockroach",
Database: "database",
Host: "host",
Port: "1234",
User: "user",
Password: "pass#",
Options: map[string]string{"application_name": "testing"},
}
err := cd.Finalize()
r.NoError(err)
p := &cockroach{commonDialect: commonDialect{ConnectionDetails: cd}}
r.Equal("postgres://user:pass%23@host:1234/database?application_name=testing", p.URL())
}
func Test_Cockroach_URL_Raw(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "cockroach",
URL: "cockroach://user:pass@host:1234/database?option1=value1",
}
err := cd.Finalize()
r.NoError(err)
m := &cockroach{commonDialect: commonDialect{ConnectionDetails: cd}}
r.Equal("postgres://user:pass@host:1234/database?option1=value1", m.URL())
r.Equal("postgres://user:pass@host:1234/?option1=value1", m.urlWithoutDb())
}
func Test_Cockroach_URL_Build(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "cockroach",
Database: "database",
Host: "host",
Port: "port",
User: "user",
Password: "pass#",
Options: map[string]string{
"option1": "value1",
},
}
err := cd.Finalize()
r.NoError(err)
m := &cockroach{commonDialect: commonDialect{ConnectionDetails: cd}}
r.True(strings.HasPrefix(m.URL(), "postgres://user:pass%23@host:port/database?"), "URL() returns %v", m.URL())
r.Contains(m.URL(), "option1=value1")
r.Contains(m.URL(), "application_name=pop.test")
r.True(strings.HasPrefix(m.urlWithoutDb(), "postgres://user:pass%23@host:port/?"), "urlWithoutDb() returns %v", m.urlWithoutDb())
r.Contains(m.urlWithoutDb(), "option1=value1")
r.Contains(m.urlWithoutDb(), "application_name=pop.test")
r.True(strings.HasPrefix(m.MigrationURL(), "postgres://user:pass%23@host:port/database?"), "MigrationURL() returns %v", m.MigrationURL())
}
func Test_Cockroach_URL_UserDefinedAppName(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "cockroach",
Database: "database",
Options: map[string]string{
"application_name": "myapp",
},
}
err := cd.Finalize()
r.NoError(err)
m := &cockroach{commonDialect: commonDialect{ConnectionDetails: cd}}
r.Contains(m.URL(), "database?application_name=myapp")
r.Contains(m.urlWithoutDb(), "/?application_name=myapp")
}
func Test_Cockroach_tableQuery(t *testing.T) {
r := require.New(t)
cr := cockroach{}
cr.info.version = "v1.0.7"
r.Equal(selectTablesQueryCockroachV1, cr.tablesQuery())
cr.info.version = "v1.1.9"
r.Equal(selectTablesQueryCockroachV1, cr.tablesQuery())
cr.info.version = "v2.0.7"
r.Equal(selectTablesQueryCockroach, cr.tablesQuery())
cr.info.version = "v2.1.7"
r.Equal(selectTablesQueryCockroach, cr.tablesQuery())
cr.info.version = "v19.1.1"
r.Equal(selectTablesQueryCockroach, cr.tablesQuery())
cr.info.version = "v20.1.1"
r.Equal(selectTablesQueryCockroach, cr.tablesQuery())
}
func Test_Cockroach_URL_Only(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
URL: "cockroach://user:pass@host:1337/database?option1=value1",
}
err := cd.Finalize()
r.NoError(err)
m := &cockroach{commonDialect: commonDialect{ConnectionDetails: cd}}
r.Equal("postgres://user:pass@host:1337/database?option1=value1", m.URL())
r.Equal("postgres://user:pass@host:1337/?option1=value1", m.urlWithoutDb())
}