-
Notifications
You must be signed in to change notification settings - Fork 3
/
tx_test.go
51 lines (46 loc) · 1.59 KB
/
tx_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
package neoql
import (
"bytes"
"gopkg.in/packstream.v1"
"testing"
)
func TestTx_Commit(t *testing.T) {
var (
wr bytes.Buffer
rd bytes.Buffer
txx *tx
)
c := testMockConn(t, &rd, &wr)
txx = new(tx)
txx.conn = c
defer c.Close()
rd.Write(testGetEncodedMessage(t, packstream.NewStructure(byteSuccess, map[string]interface{}{"fields": []interface{}{}})))
rd.Write(testGetEncodedMessage(t, packstream.NewStructure(byteSuccess, map[string]interface{}{})))
data := testGetEncodedMessage(t, packstream.NewStructure(byteRun, "COMMIT", map[string]interface{}{}))
data = append(data, testGetEncodedMessage(t, packstream.NewStructure(bytePullAll))...)
if err := txx.Commit(); err != nil {
t.Error(err)
} else if !bytes.Equal(wr.Bytes(), data) {
t.Errorf("Unexpected commit message, expected %# x got %# x.", data, wr.Bytes())
}
}
func TestTx_Rollback(t *testing.T) {
var (
wr bytes.Buffer
rd bytes.Buffer
txx *tx
)
c := testMockConn(t, &rd, &wr)
txx = new(tx)
txx.conn = c
defer c.Close()
rd.Write(testGetEncodedMessage(t, packstream.NewStructure(byteSuccess, map[string]interface{}{"fields": []interface{}{}})))
rd.Write(testGetEncodedMessage(t, packstream.NewStructure(byteSuccess, map[string]interface{}{})))
data := testGetEncodedMessage(t, packstream.NewStructure(byteRun, "ROLLBACK", map[string]interface{}{}))
data = append(data, testGetEncodedMessage(t, packstream.NewStructure(bytePullAll))...)
if err := txx.Rollback(); err != nil {
t.Error(err)
} else if !bytes.Equal(wr.Bytes(), data) {
t.Errorf("Unexpected rollback message, expected %# x got %# x.", data, wr.Bytes())
}
}