forked from denisenkom/go-mssqldb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mssql_test.go
71 lines (66 loc) · 1.65 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
60
61
62
63
64
65
66
67
68
69
70
71
package mssql
import (
"context"
"database/sql"
"testing"
)
func TestBadOpen(t *testing.T) {
drv := driverWithProcess(t)
_, err := drv.open(context.Background(), "port=bad")
if err == nil {
t.Fail()
}
}
func TestIsProc(t *testing.T) {
list := []struct {
s string
is bool
}{
{"proc", true},
{"select 1;", false},
{"select 1", false},
{"[proc 1]", true},
{"[proc\n1]", false},
{"schema.name", true},
{"[schema].[name]", true},
{"schema.[name]", true},
{"[schema].name", true},
{"schema.[proc name]", true},
}
for _, item := range list {
got := isProc(item.s)
if got != item.is {
t.Errorf("for %q, got %t want %t", item.s, got, item.is)
}
}
}
func TestConvertIsolationLevel(t *testing.T) {
level, err := convertIsolationLevel(sql.LevelReadUncommitted)
if level != isolationReadUncommited || err != nil {
t.Fatal("invalid value returned")
}
level, err = convertIsolationLevel(sql.LevelReadCommitted)
if level != isolationReadCommited || err != nil {
t.Fatal("invalid value returned")
}
level, err = convertIsolationLevel(sql.LevelRepeatableRead)
if level != isolationRepeatableRead || err != nil {
t.Fatal("invalid value returned")
}
level, err = convertIsolationLevel(sql.LevelSnapshot)
if level != isolationSnapshot || err != nil {
t.Fatal("invalid value returned")
}
level, err = convertIsolationLevel(sql.LevelWriteCommitted)
if err == nil {
t.Fatal("must fail but it didn't")
}
level, err = convertIsolationLevel(sql.LevelLinearizable)
if err == nil {
t.Fatal("must fail but it didn't")
}
level, err = convertIsolationLevel(sql.IsolationLevel(1000))
if err == nil {
t.Fatal("must fail but it didn't")
}
}