forked from adlio/schema
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mssql_test.go
59 lines (50 loc) · 1.36 KB
/
mssql_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
package schema
import (
"testing"
// MSSQL Driver
_ "github.com/denisenkom/go-mssqldb"
)
// Interface verification that MSSQL is a valid Dialect
var (
_ Dialect = MSSQL
)
func TestMSSQLQuotedTableName(t *testing.T) {
type qtnTest struct {
schema, table string
expected string
}
tests := []qtnTest{
{"public", "ta[ble", `[public].[ta[ble]`},
{"pu[b]lic", "ta[ble", `[pu[b]]lic].[ta[ble]`},
{"tempdb", "users", `[tempdb].[users]`},
{"schema.with.dot", "table.with.dot", `[schema.with.dot].[table.with.dot]`},
{`public"`, `"; DROP TABLE users`, `[public"].["DROPTABLEusers]`},
}
for _, tc := range tests {
tc := tc
t.Run(tc.expected, func(t *testing.T) {
actual := MSSQL.QuotedTableName(tc.schema, tc.table)
if actual != tc.expected {
t.Errorf("Expected %s, got %s", tc.expected, actual)
}
})
}
}
func TestMSSQLQuotedIdent(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]`,
"table[with]brackets": "[table[with]]brackets]",
}
for ident, expected := range table {
t.Run(expected, func(t *testing.T) {
actual := MSSQL.QuotedIdent(ident)
if expected != actual {
t.Errorf("Expected %s, got %s", expected, actual)
}
})
}
}