aboutsummaryrefslogtreecommitdiff
path: root/branch_test.go
blob: 0687b20d5f74420f9f64cf74d83376f69802c361 (plain) (blame)
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
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")
}