@@ -15,6 +15,7 @@ import (
1515 dagpb "github.com/ipld/go-codec-dagpb"
1616 "github.com/ipld/go-ipld-prime"
1717 cidlink "github.com/ipld/go-ipld-prime/linking/cid"
18+ "github.com/multiformats/go-multihash"
1819 "github.com/stretchr/testify/require"
1920)
2021
@@ -67,6 +68,40 @@ func TestBuildUnixFSFileWrappedInDirectory_Reference(t *testing.T) {
6768 }
6869}
6970
71+ // Cross-impl reference test: directory of files with single character
72+ // names, starting from ' ' and ending with '~', but excluding the special
73+ // characters '/' and '.'. Each file should contain a single byte with the
74+ // same value as the character in its name. Files are added to a sharded
75+ // directory with a fanout of 16, using CIDv1 throughout, and should result
76+ // in the root CID of:
77+ //
78+ // bafybeihnipspiyy3dctpcx7lv655qpiuy52d7b2fzs52dtrjqwmvbiux44
79+ func TestBuildUnixFSDirectoryShardAltFanout_Reference (t * testing.T ) {
80+ ls := cidlink .DefaultLinkSystem ()
81+ storage := cidlink.Memory {}
82+ ls .StorageReadOpener = storage .OpenRead
83+ ls .StorageWriteOpener = storage .OpenWrite
84+ entries := make ([]dagpb.PBLink , 0 )
85+ for ch := ' ' ; ch <= '~' ; ch ++ {
86+ if ch == '/' || ch == '.' {
87+ continue
88+ }
89+ s := string (ch )
90+ r := bytes .NewBuffer ([]byte (s ))
91+ e , err := mkEntry (r , s , & ls )
92+ require .NoError (t , err )
93+ entries = append (entries , e )
94+ }
95+ lnk , sz , err := BuildUnixFSShardedDirectory (16 , multihash .MURMUR3X64_64 , entries , & ls )
96+ require .NoError (t , err )
97+ var totStored int
98+ for _ , blk := range storage .Bag {
99+ totStored += len (blk )
100+ }
101+ require .Equal (t , totStored , int (sz ))
102+ require .Equal (t , "bafybeihnipspiyy3dctpcx7lv655qpiuy52d7b2fzs52dtrjqwmvbiux44" , lnk .String ())
103+ }
104+
70105func TestBuildUnixFSDirectory (t * testing.T ) {
71106 ls := cidlink .DefaultLinkSystem ()
72107 storage := cidlink.Memory {}
0 commit comments