-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction_test.go
122 lines (120 loc) · 2.68 KB
/
transaction_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
package sqldb
import (
"database/sql"
"testing"
)
func TestCheckTxOptionsCompatibility(t *testing.T) {
type args struct {
parent *sql.TxOptions
child *sql.TxOptions
defaultIsolation sql.IsolationLevel
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "nil, nil",
args: args{
parent: nil,
child: nil,
},
},
{
name: "nil, default",
args: args{
parent: nil,
child: &sql.TxOptions{},
},
},
{
name: "default, nil",
args: args{
parent: &sql.TxOptions{},
child: nil,
},
},
{
name: "default, default",
args: args{
parent: &sql.TxOptions{},
child: &sql.TxOptions{},
},
},
{
name: "nil, ReadOnly",
args: args{
parent: nil,
child: &sql.TxOptions{ReadOnly: true},
},
},
{
name: "ReadOnly, ReadOnly",
args: args{
parent: nil,
child: &sql.TxOptions{ReadOnly: true},
},
wantErr: false,
},
{
name: "ReadOnly, nil",
args: args{
parent: &sql.TxOptions{ReadOnly: true},
child: nil,
},
wantErr: true,
},
{
name: "ReadCommitted, ReadCommitted",
args: args{
parent: &sql.TxOptions{Isolation: sql.LevelReadCommitted},
child: &sql.TxOptions{Isolation: sql.LevelReadCommitted},
},
},
{
name: "Serializable, ReadCommitted",
args: args{
parent: &sql.TxOptions{Isolation: sql.LevelSerializable},
child: &sql.TxOptions{Isolation: sql.LevelReadCommitted},
},
},
{
name: "ReadCommitted, Serializable",
args: args{
parent: &sql.TxOptions{Isolation: sql.LevelReadCommitted},
child: &sql.TxOptions{Isolation: sql.LevelSerializable},
},
wantErr: true,
},
{
name: "ReadCommitted, Serializable/ReadOnly",
args: args{
parent: &sql.TxOptions{Isolation: sql.LevelReadCommitted},
child: &sql.TxOptions{Isolation: sql.LevelSerializable, ReadOnly: true},
},
wantErr: true,
},
{
name: "ReadCommitted/ReadOnly, ReadCommitted/ReadOnly",
args: args{
parent: &sql.TxOptions{Isolation: sql.LevelReadCommitted, ReadOnly: true},
child: &sql.TxOptions{Isolation: sql.LevelReadCommitted, ReadOnly: true},
},
},
{
name: "Serializable/ReadOnly, ReadCommitted/ReadOnly",
args: args{
parent: &sql.TxOptions{Isolation: sql.LevelSerializable, ReadOnly: true},
child: &sql.TxOptions{Isolation: sql.LevelReadCommitted, ReadOnly: true},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := CheckTxOptionsCompatibility(tt.args.parent, tt.args.child, tt.args.defaultIsolation); (err != nil) != tt.wantErr {
t.Errorf("CheckTxOptionsCompatibility() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}