forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialect_cockroach_test.go
87 lines (73 loc) · 2.49 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
package pop
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func Test_Cockroach_URL_Raw(t *testing.T) {
r := require.New(t)
cd := &ConnectionDetails{
Dialect: "cockroach",
URL: "scheme://user:pass@host:port/database?option1=value1",
}
err := cd.Finalize()
r.NoError(err)
m := &cockroach{commonDialect: commonDialect{ConnectionDetails: cd}}
r.Equal("scheme://user:pass@host:port/database?option1=value1", m.URL())
r.Equal("postgres://user:pass@host:port/?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@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@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@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())
}