Skip to content

Commit d3fccee

Browse files
committed
fix: add extra test to span the shard/no-shard boundary
1 parent bbf0ec6 commit d3fccee

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

data/builder/dir_test.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ func TestBuildUnixFSRecursive(t *testing.T) {
110110
require.Equal(t, uint64(245), sz)
111111
}
112112

113-
func TestBuildUnixFSRecursiveSharded(t *testing.T) {
113+
func TestBuildUnixFSRecursiveLargeSharded(t *testing.T) {
114114
// only the top CID is of interest, but this tree is correct and can be used for future validation
115115
fixture := fentry{
116116
"rootDir",
117117
"",
118-
mustCidDecode("bafybeiendaawtta62lx2p2e2hecgywmqeq6ekrn2pfypxjkmdzmaeituhe"),
118+
mustCidDecode("bafybeigyvxs6og5jbmpaa43qbhhd5swklqcfzqdrtjgfh53qjon6hpjaye"),
119119
make([]fentry, 0),
120120
}
121121

122-
for i := 0; i < 2048; i++ {
122+
for i := 0; i < 1344; i++ {
123123
name := fmt.Sprintf("long name to fill out bytes to make the sharded directory test flip over the sharded directory limit because link names are included in the directory entry %d", i)
124124
fixture.children = append(fixture.children, fentry{name, name, cid.Undef, nil})
125125
}
@@ -135,7 +135,38 @@ func TestBuildUnixFSRecursiveSharded(t *testing.T) {
135135
lnk, sz, err := BuildUnixFSRecursive(filepath.Join(dir, fixture.name), &ls)
136136
require.NoError(t, err)
137137
require.Equal(t, fixture.expectedLnk.String(), lnk.String())
138-
require.Equal(t, uint64(778128), sz)
138+
require.Equal(t, uint64(515735), sz)
139+
}
140+
141+
// Same as TestBuildUnixFSRecursiveLargeSharded but it's one file less which flips
142+
// it back to the un-sharded format. So we're testing the boundary condition and
143+
// the proper construction of large DAGs.
144+
func TestBuildUnixFSRecursiveLargeUnsharded(t *testing.T) {
145+
// only the top CID is of interest, but this tree is correct and can be used for future validation
146+
fixture := fentry{
147+
"rootDir",
148+
"",
149+
mustCidDecode("bafybeihecq4rpl4nw3cgfb2uiwltgsmw5sutouvuldv5fxn4gfbihvnalq"),
150+
make([]fentry, 0),
151+
}
152+
153+
for i := 0; i < 1343; i++ {
154+
name := fmt.Sprintf("long name to fill out bytes to make the sharded directory test flip over the sharded directory limit because link names are included in the directory entry %d", i)
155+
fixture.children = append(fixture.children, fentry{name, name, cid.Undef, nil})
156+
}
157+
158+
ls := cidlink.DefaultLinkSystem()
159+
storage := cidlink.Memory{}
160+
ls.StorageReadOpener = storage.OpenRead
161+
ls.StorageWriteOpener = storage.OpenWrite
162+
163+
dir := t.TempDir()
164+
makeFixture(t, dir, fixture)
165+
166+
lnk, sz, err := BuildUnixFSRecursive(filepath.Join(dir, fixture.name), &ls)
167+
require.NoError(t, err)
168+
require.Equal(t, fixture.expectedLnk.String(), lnk.String())
169+
require.Equal(t, uint64(490665), sz)
139170
}
140171

141172
type fentry struct {

0 commit comments

Comments
 (0)