diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-01-28 19:52:37 -0500 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-01-28 19:52:37 -0500 |
commit | 7dd512ef077bfb1ab412a8a101d0650f5db2032e (patch) | |
tree | c5ca1390e800b7e39c76e41fbbb8ce81cb627d95 /tpage_test.go | |
parent | gofmt (diff) | |
download | dedo-7dd512ef077bfb1ab412a8a101d0650f5db2032e.tar.gz dedo-7dd512ef077bfb1ab412a8a101d0650f5db2032e.tar.xz |
Add full test coverage to tpage.
Diffstat (limited to 'tpage_test.go')
-rw-r--r-- | tpage_test.go | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/tpage_test.go b/tpage_test.go index 389a176..ace4c53 100644 --- a/tpage_test.go +++ b/tpage_test.go @@ -79,7 +79,65 @@ func TestTpageWrite(t *testing.T) { assert.Equal(t, p2.nodes[2].value, []byte("que")) } +// Ensure that an error that an allocation error during writing is returned. +func TestTpageWriteError(t *testing.T) { + // Create a temp page. + p := &tpage{nodes: make(tnodes, 0)} + p.put([]byte("susy"), []byte("que")) + + // Write it to a page. + exp := &Error{} + allocate := func(size int) (*page, error) { + return nil, exp + } + pages, err := p.write(4096, allocate) + assert.Nil(t, pages) + assert.Equal(t, err, exp) +} + // Ensure that a temporary page can split into appropriate subgroups. func TestTpageSplit(t *testing.T) { - t.Skip("pending") + // Create a temp page. + p := &tpage{nodes: make(tnodes, 0)} + p.put([]byte("00000001"), []byte("0123456701234567")) + p.put([]byte("00000002"), []byte("0123456701234567")) + p.put([]byte("00000003"), []byte("0123456701234567")) + p.put([]byte("00000004"), []byte("0123456701234567")) + p.put([]byte("00000005"), []byte("0123456701234567")) + + // Split between 3 & 4. + pages := p.split(100) + + assert.Equal(t, len(pages), 2) + assert.Equal(t, len(pages[0]), 2) + assert.Equal(t, len(pages[1]), 3) +} + +// Ensure that a temporary page with the minimum number of nodes just returns a single split group. +func TestTpageSplitWithMinKeys(t *testing.T) { + // Create a temp page. + p := &tpage{nodes: make(tnodes, 0)} + p.put([]byte("00000001"), []byte("0123456701234567")) + p.put([]byte("00000002"), []byte("0123456701234567")) + + // Split. + pages := p.split(20) + assert.Equal(t, len(pages), 1) + assert.Equal(t, len(pages[0]), 2) +} + +// Ensure that a temporary page that has keys that all fit on a page just returns one split group. +func TestTpageSplitFitsInPage(t *testing.T) { + // Create a temp page. + p := &tpage{nodes: make(tnodes, 0)} + p.put([]byte("00000001"), []byte("0123456701234567")) + p.put([]byte("00000002"), []byte("0123456701234567")) + p.put([]byte("00000003"), []byte("0123456701234567")) + p.put([]byte("00000004"), []byte("0123456701234567")) + p.put([]byte("00000005"), []byte("0123456701234567")) + + // Split. + pages := p.split(4096) + assert.Equal(t, len(pages), 1) + assert.Equal(t, len(pages[0]), 5) } |