Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 930e8c9

Browse files
committed
add test
1 parent 8c3d5ec commit 930e8c9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

io/directory_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,30 @@ func TestDuplicateAddDir(t *testing.T) {
9898
}
9999
}
100100

101+
func TestUpgradeableDirectory(t *testing.T) {
102+
oldHamtOption := UseHAMTSharding
103+
defer func() {UseHAMTSharding = oldHamtOption}()
104+
105+
ds := mdtest.Mock()
106+
UseHAMTSharding = false // Create a BasicDirectory.
107+
dir := NewDirectory(ds)
108+
if _, ok := dir.(UpgradeableDirectory).Directory.(*BasicDirectory); !ok {
109+
t.Fatal("UpgradeableDirectory doesn't contain BasicDirectory")
110+
}
111+
112+
// Any new directory entry will trigger the upgrade to HAMTDirectory
113+
UseHAMTSharding = true
114+
115+
err := dir.AddChild(context.Background(), "test", ft.EmptyDirNode())
116+
if err != nil {
117+
t.Fatal(err)
118+
}
119+
120+
if _, ok := dir.(UpgradeableDirectory).Directory.(*HAMTDirectory); !ok {
121+
t.Fatal("UpgradeableDirectory wasn't upgraded to HAMTDirectory")
122+
}
123+
}
124+
101125
func TestDirBuilder(t *testing.T) {
102126
ds := mdtest.Mock()
103127
dir := NewDirectory(ds)

0 commit comments

Comments
 (0)