-
Notifications
You must be signed in to change notification settings - Fork 5
/
postgres_test.go
48 lines (43 loc) · 1.14 KB
/
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
package schema
import (
"testing"
// Postgres Driver
_ "github.com/lib/pq"
)
// Interface verification that Postgres is a valid Dialect
var (
_ Dialect = Postgres
_ Locker = Postgres
)
func TestPostgreSQLQuotedTableName(t *testing.T) {
type qtnTest struct {
schema, table string
expected string
}
tests := []qtnTest{
{"public", "users", `"public"."users"`},
{"schema.with.dot", "table.with.dot", `"schema.with.dot"."table.with.dot"`},
{`public"`, `"; DROP TABLE users`, `"public"""."""DROPTABLEusers"`},
}
for _, test := range tests {
actual := Postgres.QuotedTableName(test.schema, test.table)
if actual != test.expected {
t.Errorf("Expected %s, got %s", test.expected, actual)
}
}
}
func TestPostgreSQLQuotedIdent(t *testing.T) {
table := map[string]string{
"": "",
"MY_TABLE": `"MY_TABLE"`,
"users_roles": `"users_roles"`,
"table.with.dot": `"table.with.dot"`,
`table"with"quotes`: `"table""with""quotes"`,
}
for ident, expected := range table {
actual := Postgres.QuotedIdent(ident)
if expected != actual {
t.Errorf("Expected %s, got %s", expected, actual)
}
}
}