-
Notifications
You must be signed in to change notification settings - Fork 8
/
box_test.go
58 lines (46 loc) · 1.31 KB
/
box_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
package tnt
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestBox(t *testing.T) {
config := `
space[0].enabled = 1
space[0].index[0].type = "HASH"
space[0].index[0].unique = 1
space[0].index[0].key_field[0].fieldno = 0
space[0].index[0].key_field[0].type = "NUM"
`
box, err := NewBox(config)
require.NoError(t, err)
box.Close()
}
func TestBoxSnapshot(t *testing.T) {
require := require.New(t)
config := `
space[0].enabled = 1
space[0].index[0].type = "HASH"
space[0].index[0].unique = 1
space[0].index[0].key_field[0].fieldno = 0
space[0].index[0].key_field[0].type = "NUM"
`
box, err := NewBox(config)
require.NoError(err)
defer box.Close()
// snapshot has been created already
filename, err := box.Snapshot()
require.NoError(err)
require.Contains(filename, "snap/00000000000000000001.snap")
// try saving new snapshot, but box has no new tuples inserted
filename, err = box.SaveSnapshot()
require.NoError(err)
require.Contains(filename, "snap/00000000000000000001.snap")
// insert new tuples
conn, err := Connect(box.Listen(), nil)
require.NoError(err)
_, err = conn.Execute(&Insert{Space: 0, Tuple: Tuple{PackInt(1)}})
require.NoError(err)
filename, err = box.SaveSnapshot()
require.NoError(err)
require.Contains(filename, "snap/00000000000000000002.snap")
}