@@ -31,32 +31,50 @@ module.exports = (createCommon, options) => {
31
31
32
32
function populate ( ) {
33
33
series ( [
34
- cb => ipfs . add ( fixtures . files [ 0 ] . data , { pin : false } , cb ) ,
35
- cb => ipfs . pin . add ( fixtures . files [ 0 ] . cid , { recursive : true } , cb ) ,
36
- cb => ipfs . add ( fixtures . files [ 1 ] . data , { pin : false } , cb ) ,
37
- cb => ipfs . pin . add ( fixtures . files [ 1 ] . cid , { recursive : false } , cb )
34
+ cb => { // two files wrapped in a directory, root CID pinned recursively
35
+ const dir = fixtures . directory . files . map ( ( file ) => ( { path : file . path , content : file . data } ) )
36
+ ipfs . files . add ( dir , { pin : false } , ( err , res ) => {
37
+ if ( err ) return cb ( err )
38
+ ipfs . pin . add ( fixtures . directory . cid , { recursive : true } , cb )
39
+ } )
40
+ } ,
41
+ cb => { // a file (CID pinned recursively)
42
+ ipfs . files . add ( fixtures . files [ 0 ] . data , { pin : false } , ( err , res ) => {
43
+ if ( err ) return cb ( err )
44
+ ipfs . pin . add ( fixtures . files [ 0 ] . cid , { recursive : true } , cb )
45
+ } )
46
+ } ,
47
+ cb => { // a single CID (pinned directly)
48
+ ipfs . files . add ( fixtures . files [ 1 ] . data , { pin : false } , ( err , res ) => {
49
+ if ( err ) return cb ( err )
50
+ ipfs . pin . add ( fixtures . files [ 1 ] . cid , { recursive : false } , cb )
51
+ } )
52
+ }
38
53
] , done )
39
54
}
40
55
} )
41
56
42
57
after ( ( done ) => common . teardown ( done ) )
43
58
44
59
// 1st, because ipfs.add pins automatically
45
- it ( 'should list recursive pins' , ( done ) => {
60
+ it ( 'should list all recursive pins' , ( done ) => {
46
61
ipfs . pin . ls ( { type : 'recursive' } , ( err , pinset ) => {
47
62
expect ( err ) . to . not . exist ( )
48
63
expect ( pinset ) . to . deep . include ( {
49
64
type : 'recursive' ,
50
65
hash : fixtures . files [ 0 ] . cid
51
66
} )
67
+ expect ( pinset ) . to . deep . include ( {
68
+ type : 'recursive' ,
69
+ hash : fixtures . directory . cid
70
+ } )
52
71
done ( )
53
72
} )
54
73
} )
55
74
56
- it ( 'should list indirect pins' , ( done ) => {
75
+ it ( 'should list all indirect pins' , ( done ) => {
57
76
ipfs . pin . ls ( { type : 'indirect' } , ( err , pinset ) => {
58
77
expect ( err ) . to . not . exist ( )
59
- // because the pinned files have no links
60
78
expect ( pinset ) . to . not . deep . include ( {
61
79
type : 'recursive' ,
62
80
hash : fixtures . files [ 0 ] . cid
@@ -65,14 +83,24 @@ module.exports = (createCommon, options) => {
65
83
type : 'direct' ,
66
84
hash : fixtures . files [ 1 ] . cid
67
85
} )
86
+ expect ( pinset ) . to . not . deep . include ( {
87
+ type : 'recursive' ,
88
+ hash : fixtures . directory . cid
89
+ } )
68
90
done ( )
69
91
} )
70
92
} )
71
93
72
- it ( 'should list pins' , ( done ) => {
94
+ it ( 'should list all types of pins' , ( done ) => {
73
95
ipfs . pin . ls ( ( err , pinset ) => {
74
96
expect ( err ) . to . not . exist ( )
75
97
expect ( pinset ) . to . not . be . empty ( )
98
+ expect ( pinset ) . to . have . lengthOf ( 15 )
99
+ // check the three "roots"
100
+ expect ( pinset ) . to . deep . include ( {
101
+ type : 'recursive' ,
102
+ hash : fixtures . directory . cid
103
+ } )
76
104
expect ( pinset ) . to . deep . include ( {
77
105
type : 'recursive' ,
78
106
hash : fixtures . files [ 0 ] . cid
@@ -85,9 +113,16 @@ module.exports = (createCommon, options) => {
85
113
} )
86
114
} )
87
115
88
- it ( 'should list pins (promised)' , ( ) => {
116
+ it ( 'should list all types of pins (promised)' , ( ) => {
89
117
return ipfs . pin . ls ( )
90
118
. then ( ( pinset ) => {
119
+ expect ( pinset ) . to . not . be . empty ( )
120
+ expect ( pinset ) . to . have . lengthOf ( 15 )
121
+ // check our three "roots"
122
+ expect ( pinset ) . to . deep . include ( {
123
+ type : 'recursive' ,
124
+ hash : fixtures . directory . cid
125
+ } )
91
126
expect ( pinset ) . to . deep . include ( {
92
127
type : 'recursive' ,
93
128
hash : fixtures . files [ 0 ] . cid
@@ -99,7 +134,7 @@ module.exports = (createCommon, options) => {
99
134
} )
100
135
} )
101
136
102
- it ( 'should list direct pins' , ( done ) => {
137
+ it ( 'should list all direct pins' , ( done ) => {
103
138
ipfs . pin . ls ( { type : 'direct' } , ( err , pinset ) => {
104
139
expect ( err ) . to . not . exist ( )
105
140
expect ( pinset ) . to . deep . include ( {
@@ -130,5 +165,45 @@ module.exports = (createCommon, options) => {
130
165
} ] )
131
166
} )
132
167
} )
168
+
169
+ it ( 'should throw an error on missing direct pins for a specific path' , ( done ) => {
170
+ // alice.txt is an indirect pin, so lookup for direct one should throw an error
171
+ ipfs . pin . ls ( `/ipfs/${ fixtures . directory . cid } /files/ipfs.txt` , { type : 'direct' } , ( err , pinset ) => {
172
+ expect ( pinset ) . to . not . exist ( )
173
+ expect ( err ) . to . not . be . empty ( )
174
+ expect ( err . message ) . to . be . equal ( `path '/ipfs/${ fixtures . directory . cid } /files/ipfs.txt' is not pinned` )
175
+ done ( )
176
+ } )
177
+ } )
178
+
179
+ it ( 'should throw an error on missing link for a specific path' , ( done ) => {
180
+ ipfs . pin . ls ( `/ipfs/${ fixtures . directory . cid } /I-DONT-EXIST.txt` , { type : 'direct' } , ( err , pinset ) => {
181
+ expect ( pinset ) . to . not . exist ( )
182
+ expect ( err ) . to . not . be . empty ( )
183
+ expect ( err . message ) . to . be . equal ( 'no link by that name' )
184
+ done ( )
185
+ } )
186
+ } )
187
+
188
+ it ( 'should list indirect pins for a specific path' , ( done ) => {
189
+ ipfs . pin . ls ( `/ipfs/${ fixtures . directory . cid } /files/ipfs.txt` , { type : 'indirect' } , ( err , pinset ) => {
190
+ expect ( err ) . to . not . exist ( )
191
+ expect ( pinset ) . to . deep . include ( {
192
+ type : `indirect through ${ fixtures . directory . cid } ` ,
193
+ hash : fixtures . directory . files [ 1 ] . cid
194
+ } )
195
+ done ( )
196
+ } )
197
+ } )
198
+
199
+ it ( 'should list recursive pins for a specific hash (promised)' , ( ) => {
200
+ return ipfs . pin . ls ( fixtures . files [ 0 ] . cid , { type : 'recursive' } )
201
+ . then ( ( pinset ) => {
202
+ expect ( pinset ) . to . deep . equal ( [ {
203
+ type : 'recursive' ,
204
+ hash : fixtures . files [ 0 ] . cid
205
+ } ] )
206
+ } )
207
+ } )
133
208
} )
134
209
}
0 commit comments