@@ -31,9 +31,17 @@ module.exports = (createCommon, options) => {
3131
3232 function populate ( ) {
3333 series ( [
34- cb => ipfs . add ( fixtures . files [ 0 ] . data , { pin : false } , cb ) ,
34+ // two files wrapped in directories, only root CID pinned recursively
35+ cb => {
36+ const dir = fixtures . directory . files . map ( ( file ) => ( { path : file . path , content : file . data } ) )
37+ ipfs . add ( dir , { pin : false , cidVersion : 0 } , cb )
38+ } ,
39+ cb => ipfs . pin . add ( fixtures . directory . cid , { recursive : true } , cb ) ,
40+ // a file (CID pinned recursively)
41+ cb => ipfs . add ( fixtures . files [ 0 ] . data , { pin : false , cidVersion : 0 } , cb ) ,
3542 cb => ipfs . pin . add ( fixtures . files [ 0 ] . cid , { recursive : true } , cb ) ,
36- cb => ipfs . add ( fixtures . files [ 1 ] . data , { pin : false } , cb ) ,
43+ // a single CID (pinned directly)
44+ cb => ipfs . add ( fixtures . files [ 1 ] . data , { pin : false , cidVersion : 0 } , cb ) ,
3745 cb => ipfs . pin . add ( fixtures . files [ 1 ] . cid , { recursive : false } , cb )
3846 ] , done )
3947 }
@@ -42,21 +50,24 @@ module.exports = (createCommon, options) => {
4250 after ( ( done ) => common . teardown ( done ) )
4351
4452 // 1st, because ipfs.add pins automatically
45- it ( 'should list recursive pins' , ( done ) => {
53+ it ( 'should list all recursive pins' , ( done ) => {
4654 ipfs . pin . ls ( { type : 'recursive' } , ( err , pinset ) => {
4755 expect ( err ) . to . not . exist ( )
4856 expect ( pinset ) . to . deep . include ( {
4957 type : 'recursive' ,
5058 hash : fixtures . files [ 0 ] . cid
5159 } )
60+ expect ( pinset ) . to . deep . include ( {
61+ type : 'recursive' ,
62+ hash : fixtures . directory . cid
63+ } )
5264 done ( )
5365 } )
5466 } )
5567
56- it ( 'should list indirect pins' , ( done ) => {
68+ it ( 'should list all indirect pins' , ( done ) => {
5769 ipfs . pin . ls ( { type : 'indirect' } , ( err , pinset ) => {
5870 expect ( err ) . to . not . exist ( )
59- // because the pinned files have no links
6071 expect ( pinset ) . to . not . deep . include ( {
6172 type : 'recursive' ,
6273 hash : fixtures . files [ 0 ] . cid
@@ -65,14 +76,31 @@ module.exports = (createCommon, options) => {
6576 type : 'direct' ,
6677 hash : fixtures . files [ 1 ] . cid
6778 } )
79+ expect ( pinset ) . to . not . deep . include ( {
80+ type : 'recursive' ,
81+ hash : fixtures . directory . cid
82+ } )
83+ expect ( pinset ) . to . deep . include ( {
84+ type : 'indirect' ,
85+ hash : fixtures . directory . files [ 0 ] . cid
86+ } )
87+ expect ( pinset ) . to . deep . include ( {
88+ type : 'indirect' ,
89+ hash : fixtures . directory . files [ 1 ] . cid
90+ } )
6891 done ( )
6992 } )
7093 } )
7194
72- it ( 'should list pins' , ( done ) => {
95+ it ( 'should list all types of pins' , ( done ) => {
7396 ipfs . pin . ls ( ( err , pinset ) => {
7497 expect ( err ) . to . not . exist ( )
7598 expect ( pinset ) . to . not . be . empty ( )
99+ // check the three "roots"
100+ expect ( pinset ) . to . deep . include ( {
101+ type : 'recursive' ,
102+ hash : fixtures . directory . cid
103+ } )
76104 expect ( pinset ) . to . deep . include ( {
77105 type : 'recursive' ,
78106 hash : fixtures . files [ 0 ] . cid
@@ -81,13 +109,27 @@ module.exports = (createCommon, options) => {
81109 type : 'direct' ,
82110 hash : fixtures . files [ 1 ] . cid
83111 } )
112+ expect ( pinset ) . to . deep . include ( {
113+ type : 'indirect' ,
114+ hash : fixtures . directory . files [ 0 ] . cid
115+ } )
116+ expect ( pinset ) . to . deep . include ( {
117+ type : 'indirect' ,
118+ hash : fixtures . directory . files [ 1 ] . cid
119+ } )
84120 done ( )
85121 } )
86122 } )
87123
88- it ( 'should list pins (promised)' , ( ) => {
124+ it ( 'should list all types of pins (promised)' , ( ) => {
89125 return ipfs . pin . ls ( )
90126 . then ( ( pinset ) => {
127+ expect ( pinset ) . to . not . be . empty ( )
128+ // check our three "roots"
129+ expect ( pinset ) . to . deep . include ( {
130+ type : 'recursive' ,
131+ hash : fixtures . directory . cid
132+ } )
91133 expect ( pinset ) . to . deep . include ( {
92134 type : 'recursive' ,
93135 hash : fixtures . files [ 0 ] . cid
@@ -96,12 +138,21 @@ module.exports = (createCommon, options) => {
96138 type : 'direct' ,
97139 hash : fixtures . files [ 1 ] . cid
98140 } )
141+ expect ( pinset ) . to . deep . include ( {
142+ type : 'indirect' ,
143+ hash : fixtures . directory . files [ 0 ] . cid
144+ } )
145+ expect ( pinset ) . to . deep . include ( {
146+ type : 'indirect' ,
147+ hash : fixtures . directory . files [ 1 ] . cid
148+ } )
99149 } )
100150 } )
101151
102- it ( 'should list direct pins' , ( done ) => {
152+ it ( 'should list all direct pins' , ( done ) => {
103153 ipfs . pin . ls ( { type : 'direct' } , ( err , pinset ) => {
104154 expect ( err ) . to . not . exist ( )
155+ expect ( pinset ) . to . have . lengthOf ( 1 )
105156 expect ( pinset ) . to . deep . include ( {
106157 type : 'direct' ,
107158 hash : fixtures . files [ 1 ] . cid
@@ -130,5 +181,45 @@ module.exports = (createCommon, options) => {
130181 } ] )
131182 } )
132183 } )
184+
185+ it ( 'should throw an error on missing direct pins for existing path' , ( done ) => {
186+ // ipfs.txt is an indirect pin, so lookup for direct one should throw an error
187+ ipfs . pin . ls ( `/ipfs/${ fixtures . directory . cid } /files/ipfs.txt` , { type : 'direct' } , ( err , pinset ) => {
188+ expect ( err ) . to . exist ( )
189+ expect ( pinset ) . to . not . exist ( )
190+ expect ( err . message ) . to . be . equal ( `path '/ipfs/${ fixtures . directory . cid } /files/ipfs.txt' is not pinned` )
191+ done ( )
192+ } )
193+ } )
194+
195+ it ( 'should throw an error on missing link for a specific path' , ( done ) => {
196+ ipfs . pin . ls ( `/ipfs/${ fixtures . directory . cid } /I-DONT-EXIST.txt` , { type : 'direct' } , ( err , pinset ) => {
197+ expect ( err ) . to . exist ( )
198+ expect ( pinset ) . to . not . exist ( )
199+ expect ( err . message ) . to . be . equal ( `no link named "I-DONT-EXIST.txt" under ${ fixtures . directory . cid } ` )
200+ done ( )
201+ } )
202+ } )
203+
204+ it ( 'should list indirect pins for a specific path' , ( done ) => {
205+ ipfs . pin . ls ( `/ipfs/${ fixtures . directory . cid } /files/ipfs.txt` , { type : 'indirect' } , ( err , pinset ) => {
206+ expect ( err ) . to . not . exist ( )
207+ expect ( pinset ) . to . deep . include ( {
208+ type : `indirect through ${ fixtures . directory . cid } ` ,
209+ hash : fixtures . directory . files [ 1 ] . cid
210+ } )
211+ done ( )
212+ } )
213+ } )
214+
215+ it ( 'should list recursive pins for a specific hash (promised)' , ( ) => {
216+ return ipfs . pin . ls ( fixtures . files [ 0 ] . cid , { type : 'recursive' } )
217+ . then ( ( pinset ) => {
218+ expect ( pinset ) . to . deep . equal ( [ {
219+ type : 'recursive' ,
220+ hash : fixtures . files [ 0 ] . cid
221+ } ] )
222+ } )
223+ } )
133224 } )
134225}
0 commit comments