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