@@ -110,16 +110,16 @@ func TestBuildUnixFSRecursive(t *testing.T) {
110
110
require .Equal (t , uint64 (245 ), sz )
111
111
}
112
112
113
- func TestBuildUnixFSRecursiveSharded (t * testing.T ) {
113
+ func TestBuildUnixFSRecursiveLargeSharded (t * testing.T ) {
114
114
// only the top CID is of interest, but this tree is correct and can be used for future validation
115
115
fixture := fentry {
116
116
"rootDir" ,
117
117
"" ,
118
- mustCidDecode ("bafybeiendaawtta62lx2p2e2hecgywmqeq6ekrn2pfypxjkmdzmaeituhe " ),
118
+ mustCidDecode ("bafybeigyvxs6og5jbmpaa43qbhhd5swklqcfzqdrtjgfh53qjon6hpjaye " ),
119
119
make ([]fentry , 0 ),
120
120
}
121
121
122
- for i := 0 ; i < 2048 ; i ++ {
122
+ for i := 0 ; i < 1344 ; i ++ {
123
123
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 )
124
124
fixture .children = append (fixture .children , fentry {name , name , cid .Undef , nil })
125
125
}
@@ -135,7 +135,38 @@ func TestBuildUnixFSRecursiveSharded(t *testing.T) {
135
135
lnk , sz , err := BuildUnixFSRecursive (filepath .Join (dir , fixture .name ), & ls )
136
136
require .NoError (t , err )
137
137
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 )
139
170
}
140
171
141
172
type fentry struct {
0 commit comments