@@ -40,11 +40,13 @@ module.exports = (repo) => {
4040 const node = nodes [ 0 ]
4141 expect ( node ) . to . exist ( )
4242
43+ const cid = new CID ( node . multihash )
44+
4345 // Verify multihash has been encoded using hashAlg
44- expect ( mh . decode ( node . multihash ) . name ) . to . equal ( hashAlg )
46+ expect ( mh . decode ( cid . multihash ) . name ) . to . equal ( hashAlg )
4547
4648 // Fetch using hashAlg encoded multihash
47- ipld . get ( new CID ( node . multihash ) , ( err , res ) => {
49+ ipld . get ( cid , ( err , res ) => {
4850 if ( err ) return cb ( err )
4951 const content = UnixFS . unmarshal ( res . value . data ) . data
5052 expect ( content . equals ( inputFile . content ) ) . to . be . true ( )
@@ -77,7 +79,8 @@ module.exports = (repo) => {
7779
7880 try {
7981 expect ( node ) . to . exist ( )
80- expect ( mh . decode ( node . multihash ) . name ) . to . equal ( hashAlg )
82+ const cid = new CID ( node . multihash )
83+ expect ( mh . decode ( cid . multihash ) . name ) . to . equal ( hashAlg )
8184 } catch ( err ) {
8285 return cb ( err )
8386 }
@@ -92,5 +95,41 @@ module.exports = (repo) => {
9295 )
9396 } , done )
9497 } )
98+
99+ it ( 'allows multihash hash algorithm to be specified for a directory' , ( done ) => {
100+ eachSeries ( testMultihashes , ( hashAlg , cb ) => {
101+ const options = { hashAlg, strategy : 'flat' }
102+ const inputFile = {
103+ path : `${ String ( Math . random ( ) + Date . now ( ) ) } -dir` ,
104+ content : null
105+ }
106+
107+ const onCollected = ( err , nodes ) => {
108+ if ( err ) return cb ( err )
109+
110+ const node = nodes [ 0 ]
111+
112+ expect ( node ) . to . exist ( )
113+
114+ const cid = new CID ( node . multihash )
115+
116+ expect ( mh . decode ( cid . multihash ) . name ) . to . equal ( hashAlg )
117+
118+ // Fetch using hashAlg encoded multihash
119+ ipld . get ( cid , ( err , res ) => {
120+ if ( err ) return cb ( err )
121+ const meta = UnixFS . unmarshal ( res . value . data )
122+ expect ( meta . type ) . to . equal ( 'directory' )
123+ cb ( )
124+ } )
125+ }
126+
127+ pull (
128+ pull . values ( [ Object . assign ( { } , inputFile ) ] ) ,
129+ createBuilder ( FixedSizeChunker , ipld , options ) ,
130+ pull . collect ( onCollected )
131+ )
132+ } , done )
133+ } )
95134 } )
96135}
0 commit comments