This repository has been archived by the owner on May 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
tidb_test.go
84 lines (78 loc) · 1.67 KB
/
tidb_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
package main
import (
"github.com/pingcap/goleveldb/leveldb"
"reflect"
"testing"
"time"
)
const testtablepath = "../test/table"
func TestUpdateAndLoadTables(t *testing.T) {
time.Sleep(time.Second)
tables.LeveldbStorage, _ = NewLeveldbStorage(testtablepath)
updateTables()
tablesBefore := loadTables()
tables.Close()
db, err := leveldb.OpenFile(testtablepath, nil)
perr(err)
tables.LeveldbStorage = &LeveldbStorage{db}
tablesAfter := loadTables()
if !reflect.DeepEqual(tablesBefore, tablesAfter) {
t.Fatalf("expect\n%v\nbut got\n%v", tablesBefore, tablesAfter)
}
tables.LeveldbStorage.Close()
}
func TestTableSlice_Len(t *testing.T) {
var tableSlice TableSlice
tableSlice = append(tableSlice, &Table{
Name: "aa",
DB: "a",
ID: 0,
Indices: nil,
})
tableSlice = append(tableSlice, &Table{
Name: "ab",
DB: "b",
ID: 1,
Indices: nil,
})
if tableSlice.Len() != 2 {
t.Fatalf("error len, expect 2 but get %d", tableSlice.Len())
}
}
func TestTableSlice_Swap(t *testing.T) {
var tableSlice TableSlice
tableSlice = append(tableSlice, &Table{
Name: "aa",
DB: "a",
ID: 0,
Indices: nil,
})
tableSlice = append(tableSlice, &Table{
Name: "ab",
DB: "b",
ID: 1,
Indices: nil,
})
tableSlice.Swap(0, 1)
if tableSlice[0].ID != 1 {
t.Fatalf("error swap")
}
}
func TestTableSlice_Less(t *testing.T) {
var tableSlice TableSlice
tableSlice = append(tableSlice, &Table{
Name: "aa",
DB: "a",
ID: 0,
Indices: nil,
})
tableSlice = append(tableSlice, &Table{
Name: "ab",
DB: "b",
ID: 1,
Indices: nil,
})
if tableSlice.Less(0, 1) != true {
t.Fatalf("error less")
}
}