diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-01-28 22:50:09 -0500 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-01-28 22:50:09 -0500 |
commit | ef017f0404990ba21c8c5c06af624b47fe58d729 (patch) | |
tree | e82426830dd40ae58ac05848fc3ec205b37187f9 /branch_test.go | |
parent | Refactor leaf.write() / leaf.split(). (diff) | |
download | dedo-ef017f0404990ba21c8c5c06af624b47fe58d729.tar.gz dedo-ef017f0404990ba21c8c5c06af624b47fe58d729.tar.xz |
Add branch.put().
Diffstat (limited to 'branch_test.go')
-rw-r--r-- | branch_test.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/branch_test.go b/branch_test.go new file mode 100644 index 0000000..0687b20 --- /dev/null +++ b/branch_test.go @@ -0,0 +1,48 @@ +package bolt + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +// Ensure that a branch can replace a key. +func TestBranchPutReplace(t *testing.T) { + b := &branch{ + items: branchItems{ + branchItem{pgid: 1, key: []byte("bar")}, + branchItem{pgid: 2, key: []byte("baz")}, + branchItem{pgid: 3, key: []byte("foo")}, + }, + } + b.put(1, 4, []byte("bar"), true) + b.put(2, 5, []byte("boo"), true) + assert.Equal(t, len(b.items), 3) + assert.Equal(t, b.items[0].pgid, pgid(4)) + assert.Equal(t, string(b.items[0].key), "bar") + assert.Equal(t, b.items[1].pgid, pgid(5)) + assert.Equal(t, string(b.items[1].key), "boo") + assert.Equal(t, b.items[2].pgid, pgid(3)) + assert.Equal(t, string(b.items[2].key), "foo") +} + +// Ensure that a branch can insert a key. +func TestBranchPutInsert(t *testing.T) { + b := &branch{ + items: branchItems{ + branchItem{pgid: 1, key: []byte("bar")}, + branchItem{pgid: 2, key: []byte("foo")}, + }, + } + b.put(1, 4, []byte("baz"), false) + b.put(2, 5, []byte("zzz"), false) + assert.Equal(t, len(b.items), 4) + assert.Equal(t, b.items[0].pgid, pgid(1)) + assert.Equal(t, string(b.items[0].key), "bar") + assert.Equal(t, b.items[1].pgid, pgid(4)) + assert.Equal(t, string(b.items[1].key), "baz") + assert.Equal(t, b.items[2].pgid, pgid(2)) + assert.Equal(t, string(b.items[2].key), "foo") + assert.Equal(t, b.items[3].pgid, pgid(5)) + assert.Equal(t, string(b.items[3].key), "zzz") +} |