This repository has been archived by the owner on Feb 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhamtbuilder_test.go
69 lines (57 loc) · 1.68 KB
/
hamtbuilder_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package hamtcontainer
import (
"testing"
"github.com/simplecoincom/go-ipld-adl-hamt-container/storage"
"github.com/stretchr/testify/assert"
)
func TestBuilderWithNoParams(t *testing.T) {
assert := assert.New(t)
builder := NewHAMTBuilder()
hamtContainer, err := builder.Build()
assert.Nil(err)
assert.NotNil(hamtContainer)
assert.Equal(string(hamtContainer.Key()), "hamt")
}
func TestBuilderWithKeyParam(t *testing.T) {
assert := assert.New(t)
builder := NewHAMTBuilder(WithKey([]byte("root")))
hamtContainer, err := builder.Build()
assert.Nil(err)
assert.Equal(string(hamtContainer.Key()), "root")
}
func TestBuilderWithStorageParam(t *testing.T) {
assert := assert.New(t)
store := storage.NewMemoryStorage()
builder := NewHAMTBuilder(WithStorage(store))
hamtContainer, err := builder.Build()
assert.Nil(err)
assert.Equal(hamtContainer.Storage(), store)
}
func TestBuilderWithParentParam(t *testing.T) {
assert := assert.New(t)
store := storage.NewMemoryStorage()
childContainer, err := NewHAMTBuilder(
WithStorage(store),
WithKey([]byte("child")),
).Build()
assert.Nil(err)
assert.NotNil(childContainer)
assert.Nil(childContainer.MustBuild(func(hamtSetter HAMTSetter) error {
return hamtSetter.Set([]byte("foo"), "bar")
}))
parentContainer, err := NewHAMTBuilder(
WithStorage(store),
WithKey([]byte("parent")),
).Build()
assert.Nil(err)
assert.NotNil(parentContainer)
assert.Nil(parentContainer.MustBuild(func(hamtSetter HAMTSetter) error {
return hamtSetter.Set([]byte("child"), childContainer)
}))
newContainer, err := NewHAMTBuilder(
WithKey([]byte("child")),
WithHAMTContainer(parentContainer),
).Build()
assert.Nil(err)
assert.NotNil(newContainer)
}