-
Notifications
You must be signed in to change notification settings - Fork 22
/
schema_postgres_test.go
93 lines (81 loc) · 2.24 KB
/
schema_postgres_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
package schema_test
import (
"fmt"
_ "github.com/lib/pq" // postgres
// _ "github.com/jackc/pgx/stdlib" // pgx
// _ "github.com/jbarham/gopgsqldriver" // postgres
. "github.com/onsi/ginkgo"
// . "github.com/onsi/gomega"
)
// Database/user setup not needed: default database and schema are empty on Postgres.
var _ = Describe("schema", func() {
Context("using github.com/lib/pq (Postgres)", func() {
const (
user = "postgres"
host = "localhost"
port = "45432"
)
var postgres = &testParams{
DriverName: "postgres",
// DriverName: "pgx",
ConnStr: fmt.Sprintf("user=%s host=%s port=%s sslmode=disable", user, host, port),
CreateDDL: []string{`
CREATE TABLE web_resource (
id INTEGER NOT NULL,
url TEXT NOT NULL UNIQUE,
content BYTEA,
compressed_size INTEGER NOT NULL,
content_length INTEGER NOT NULL,
content_type TEXT NOT NULL,
etag TEXT NOT NULL,
last_modified TEXT NOT NULL,
created_at TIMESTAMP NOT NULL,
modified_at TIMESTAMP,
PRIMARY KEY (id)
)`,
`CREATE INDEX idx_web_resource_url ON web_resource(url)`,
`CREATE INDEX idx_web_resource_created_at ON web_resource(created_at)`,
`CREATE INDEX idx_web_resource_modified_at ON web_resource(modified_at)`,
`CREATE VIEW web_resource_view AS SELECT id, url FROM web_resource`,
`CREATE TABLE person (
given_name TEXT NOT NULL,
family_name TEXT NOT NULL,
PRIMARY KEY (family_name, given_name)
)`,
},
DropDDL: []string{
`DROP TABLE person`,
`DROP VIEW web_resource_view`,
`DROP INDEX idx_web_resource_modified_at`,
`DROP INDEX idx_web_resource_created_at`,
`DROP INDEX idx_web_resource_url`,
`DROP TABLE web_resource`,
},
TableExpRes: []string{
"id",
"url",
"content",
"compressed_size",
"content_length",
"content_type",
"etag",
"last_modified",
"created_at",
"modified_at",
},
ViewExpRes: []string{
"id",
"url",
},
TableNamesExpRes: [][2]string{
{"public", "person"},
{"public", "web_resource"},
},
ViewNamesExpRes: [][2]string{
{"public", "web_resource_view"},
},
PrimaryKeysExpRes: []string{"family_name", "given_name"},
}
SchemaTestRunner(postgres)
})
})