-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathdb_test.go
52 lines (45 loc) · 1.06 KB
/
db_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
package db
import (
"fmt"
"os"
"testing"
"github.com/auxten/go-sqldb/node"
. "github.com/smartystreets/goconvey/convey"
)
func TestDB(t *testing.T) {
Convey("Open and Close", t, func() {
const testFile = "test.db"
defer func() {
_ = os.Remove(testFile)
}()
table, err := Open(testFile)
So(err, ShouldBeNil)
So(table.Pager.Pages[0].LeafNode.CommonHeader.IsInternal, ShouldBeFalse)
So(err, ShouldBeNil)
So(table, ShouldNotBeNil)
err = table.Insert(&node.Row{
Id: 1,
Sex: 'F',
Age: 35,
Username: [32]byte{'a', 'u', 'x', 't', 'e', 'n'},
Email: [128]byte{'a', 'u', 'x', 't', 'e', 'n', '@'},
Phone: [64]byte{'1', '2', '3', '4', '5', '6', '0'},
})
So(err, ShouldBeNil)
err = table.Insert(&node.Row{
Id: 1,
})
So(err.Error(), ShouldContainSubstring, "duplicate key 1")
for i := uint32(2); i < 35; i++ {
err = table.Insert(&node.Row{
Id: i,
})
fmt.Println(i)
So(err, ShouldBeNil)
}
err = Close(table)
So(err, ShouldBeNil)
table, err = Open(testFile)
So(err, ShouldBeNil)
})
}