Repository navigation
Expand file tree
/
Copy pathtx_internal_test.go
More file actions
69 lines (63 loc) · 2.47 KB
/
Copy pathtx_internal_test.go
File metadata and controls
69 lines (63 loc) · 2.47 KB
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
package pgx
import "testing"
func TestTxOptionsBeginSQL(t *testing.T) {
t.Parallel()
for _, tt := range []struct {
name string
txOptions TxOptions
want string
}{
{"default", TxOptions{}, "begin"},
{"commit query only", TxOptions{CommitQuery: "commit and chain"}, "begin"},
{"isolation level", TxOptions{IsoLevel: ReadCommitted}, "begin isolation level read committed"},
{"access mode", TxOptions{AccessMode: ReadOnly}, "begin read only"},
{"deferrable mode", TxOptions{DeferrableMode: Deferrable}, "begin deferrable"},
{
"every option",
TxOptions{IsoLevel: Serializable, AccessMode: ReadOnly, DeferrableMode: NotDeferrable},
"begin isolation level serializable read only not deferrable",
},
{"begin query overrides the options", TxOptions{IsoLevel: Serializable, BeginQuery: "begin priority high"}, "begin priority high"},
{"custom isolation level", TxOptions{IsoLevel: "snapshot", AccessMode: ReadWrite}, "begin isolation level snapshot read write"},
{"custom access mode", TxOptions{AccessMode: "read write only"}, "begin read write only"},
{"custom deferrable mode", TxOptions{DeferrableMode: "maybe deferrable"}, "begin maybe deferrable"},
} {
t.Run(tt.name, func(t *testing.T) {
if got := tt.txOptions.beginSQL(); got != tt.want {
t.Errorf("beginSQL() = %q, want %q", got, tt.want)
}
})
}
}
func TestTxOptionsBeginSQLEveryStandardCombination(t *testing.T) {
t.Parallel()
for _, isoLevel := range []TxIsoLevel{"", Serializable, RepeatableRead, ReadCommitted, ReadUncommitted} {
for _, accessMode := range []TxAccessMode{"", ReadWrite, ReadOnly} {
for _, deferrableMode := range []TxDeferrableMode{"", Deferrable, NotDeferrable} {
txOptions := TxOptions{IsoLevel: isoLevel, AccessMode: accessMode, DeferrableMode: deferrableMode}
want := renderBeginSQL(isoLevel, accessMode, deferrableMode)
if got := txOptions.beginSQL(); got != want {
t.Errorf("%+v: beginSQL() = %q, want %q", txOptions, got, want)
}
}
}
}
}
func BenchmarkTxOptionsBeginSQL(b *testing.B) {
for _, bb := range []struct {
name string
txOptions TxOptions
}{
{"default", TxOptions{}},
{"isolation level", TxOptions{IsoLevel: ReadCommitted}},
{"every option", TxOptions{IsoLevel: Serializable, AccessMode: ReadOnly, DeferrableMode: NotDeferrable}},
{"custom isolation level", TxOptions{IsoLevel: "snapshot"}},
} {
b.Run(bb.name, func(b *testing.B) {
b.ReportAllocs()
for b.Loop() {
bb.txOptions.beginSQL()
}
})
}
}