-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathschema_oracle_test.go
145 lines (125 loc) · 3.23 KB
/
schema_oracle_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
141
142
143
144
145
// +build !travis
package schema_test
import (
"fmt"
// _ "github.com/mattn/go-oci8" // oci8
// _ "gopkg.in/rana/ora.v4" // ora
_ "github.com/godror/godror" // godror
. "github.com/onsi/ginkgo"
// . "github.com/onsi/gomega"
)
// See README.md to learn how to set up Oracle for testing purposes.
// Database/user setup script, run by Docker: docker-db-init-oracle.sql
var _ = Describe("schema", func() {
Context("using github.com/godror/godror (Oracle)", func() {
const (
user = "test_user"
pass = "Password123"
host = "localhost"
port = "41521"
dbs = "xe"
)
var oracle = &testParams{
DriverName: "godror",
// DriverName: "oci8",
// DriverName: "ora",
ConnStr: fmt.Sprintf("%s/%s@%s:%s/%s", user, pass, host, port, dbs),
CreateDDL: []string{`
CREATE TABLE web_resource (
id NUMBER NOT NULL,
url NVARCHAR2(1024) NOT NULL UNIQUE,
content BLOB,
compressed_size NUMBER NOT NULL,
content_length NUMBER NOT NULL,
content_type NVARCHAR2(128) NOT NULL,
etag NVARCHAR2(128) NOT NULL,
last_modified NVARCHAR2(128) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
modified_at TIMESTAMP WITH TIME ZONE,
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 NVARCHAR2(128) NOT NULL,
family_name NVARCHAR2(128) 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{
{"TEST_USER", "PERSON"},
{"TEST_USER", "WEB_RESOURCE"},
},
ViewNamesExpRes: [][2]string{
{"TEST_USER", "WEB_RESOURCE_VIEW"},
},
PrimaryKeysExpRes: []string{"FAMILY_NAME", "GIVEN_NAME"},
}
SchemaTestRunner(oracle)
})
})
// func oraDump(db *sql.DB) error {
// //SELECT table_name FROM user_tables
// rows, err := db.Query(`
// SELECT *
// FROM user_tables
// `)
// if err != nil {
// return err
// }
// defer rows.Close()
// ci, err := rows.ColumnTypes()
// if err != nil {
// return err
// }
// for _, c := range ci {
// log.Printf("%v", c)
// }
// cols, err := rows.Columns()
// if err != nil {
// return err
// }
// vals := make([]interface{}, len(cols))
// for i, _ := range cols {
// vals[i] = new(sql.RawBytes)
// }
// for rows.Next() {
// err = rows.Scan(vals...)
// if err != nil {
// // return err
// log.Printf("%v", err)
// }
// s := ""
// for _, v := range vals {
// s = s + fmt.Sprintf("%s ", v)
// }
// log.Print(s)
// }
// return nil
// }