-
Notifications
You must be signed in to change notification settings - Fork 0
/
quoting_test.go
45 lines (41 loc) · 1.15 KB
/
quoting_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
package pgxschema
import "testing"
func TestQuotedTableName(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 := QuotedTableName(test.schema, test.table)
if actual != test.expected {
t.Errorf("Expected %s, got %s", test.expected, actual)
}
}
}
func TestQuotedIdent(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 := QuotedIdent(ident)
if expected != actual {
t.Errorf("Expected %s, got %s", expected, actual)
}
}
}
func TestLockIdentifierForTable(t *testing.T) {
id := LockIdentifierForTable(DefaultTableName)
expected := int64(2254546236185297208)
if id != expected {
t.Errorf("Expected %v, got %v", expected, id)
}
}