Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Jan 17, 2023
1 parent cf257af commit 6203279
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mutable_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,19 +385,30 @@ func TestMutableTree_InitialVersion(t *testing.T) {
require.NoError(t, err)
assert.EqualValues(t, 10, version)

// Check `LazyLoadVersion` behaviors the same as `LoadVersion`
version, err = tree.LazyLoadVersion(0)
assert.EqualValues(t, 10, version)

// Reloading the tree with an initial version beyond the lowest should error
tree, err = NewMutableTreeWithOpts(memDB, 0, &Options{InitialVersion: 10}, false)
require.NoError(t, err)
_, err = tree.Load()
require.Error(t, err)

_, err = tree.LazyLoadVersion(0)
require.Error(t, err)

// Reloading the tree with a lower initial version is fine, and new versions can be produced
tree, err = NewMutableTreeWithOpts(memDB, 0, &Options{InitialVersion: 3}, false)
require.NoError(t, err)
version, err = tree.Load()
require.NoError(t, err)
assert.EqualValues(t, 10, version)

version, err = tree.LazyLoadVersion(0)
require.NoError(t, err)
assert.EqualValues(t, 10, version)

_, err = tree.Set([]byte("c"), []byte{0x03})
require.NoError(t, err)
_, version, err = tree.SaveVersion()
Expand Down

0 comments on commit 6203279

Please sign in to comment.