@@ -9,7 +9,8 @@ const expect = chai.expect
9
9
chai . use ( dirtyChai )
10
10
const loadFixture = require ( 'aegir/fixtures' )
11
11
12
- const testfile = loadFixture ( __dirname , '../test/fixtures/testfile.txt' , 'interface-ipfs-core' )
12
+ const testFile = loadFixture ( __dirname , '../test/fixtures/testfile.txt' , 'interface-ipfs-core' )
13
+ const testHash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
13
14
14
15
module . exports = ( common ) => {
15
16
describe ( '.pin' , function ( ) {
@@ -28,14 +29,11 @@ module.exports = (common) => {
28
29
} )
29
30
30
31
function populate ( ) {
31
- const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
32
-
33
- ipfs . files . add ( testfile , ( err , res ) => {
32
+ ipfs . files . add ( testFile , ( err , res ) => {
34
33
expect ( err ) . to . not . exist ( )
35
-
36
34
expect ( res ) . to . have . length ( 1 )
37
- expect ( res [ 0 ] . hash ) . to . equal ( expectedMultihash )
38
- expect ( res [ 0 ] . path ) . to . equal ( expectedMultihash )
35
+ expect ( res [ 0 ] . hash ) . to . equal ( testHash )
36
+ expect ( res [ 0 ] . path ) . to . equal ( testHash )
39
37
done ( )
40
38
} )
41
39
}
@@ -47,109 +45,130 @@ module.exports = (common) => {
47
45
48
46
describe ( 'callback API' , ( ) => {
49
47
// 1st, because ipfs.files.add pins automatically
50
- it ( '.rm' , ( done ) => {
51
- const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
52
-
53
- ipfs . pin . rm ( hash , { recursive : true } , ( err , pinset ) => {
48
+ it ( '.ls type recursive' , ( done ) => {
49
+ ipfs . pin . ls ( { type : 'recursive' } , ( err , pinset ) => {
54
50
expect ( err ) . to . not . exist ( )
55
- expect ( pinset ) . to . exist ( )
56
- ipfs . pin . ls ( { type : 'direct' } , ( err , pinset ) => {
57
- expect ( err ) . to . not . exist ( )
58
- expect ( pinset ) . to . be . empty ( )
59
- done ( )
51
+ expect ( pinset ) . to . deep . include ( {
52
+ hash : testHash ,
53
+ type : 'recursive'
60
54
} )
55
+ done ( )
61
56
} )
62
57
} )
63
58
64
- it ( '.add' , ( done ) => {
65
- const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
66
-
67
- ipfs . pin . add ( hash , { recursive : false } , ( err , pinset ) => {
59
+ it . skip ( '.ls type indirect' , ( done ) => {
60
+ ipfs . pin . ls ( { type : 'indirect' } , ( err , pinset ) => {
68
61
expect ( err ) . to . not . exist ( )
69
- expect ( pinset [ 0 ] ) . to . be . equal ( hash )
62
+ // because the pinned file has no links
63
+ expect ( pinset ) . to . be . empty ( )
70
64
done ( )
71
65
} )
72
66
} )
73
67
74
- it ( '.ls ' , ( done ) => {
75
- ipfs . pin . ls ( ( err , pinset ) => {
68
+ it ( '.rm ' , ( done ) => {
69
+ ipfs . pin . rm ( testHash , { recursive : true } , ( err , pinset ) => {
76
70
expect ( err ) . to . not . exist ( )
77
- expect ( pinset ) . to . not . be . empty ( )
78
- done ( )
71
+ expect ( pinset ) . to . deep . equal ( [ {
72
+ hash : testHash
73
+ } ] )
74
+ ipfs . pin . ls ( { type : 'direct' } , ( err , pinset ) => {
75
+ expect ( err ) . to . not . exist ( )
76
+ expect ( pinset ) . to . not . deep . include ( {
77
+ hash : testHash ,
78
+ type : 'recursive'
79
+ } )
80
+ done ( )
81
+ } )
79
82
} )
80
83
} )
81
84
82
- it ( '.ls type direct ' , ( done ) => {
83
- ipfs . pin . ls ( { type : 'direct' } , ( err , pinset ) => {
85
+ it ( '.add ' , ( done ) => {
86
+ ipfs . pin . add ( testHash , { recursive : false } , ( err , pinset ) => {
84
87
expect ( err ) . to . not . exist ( )
85
- expect ( pinset ) . to . not . be . empty ( )
88
+ expect ( pinset ) . to . deep . equal ( [ {
89
+ hash : testHash
90
+ } ] )
86
91
done ( )
87
92
} )
88
93
} )
89
94
90
- it ( '.ls type indirect ' , ( done ) => {
91
- ipfs . pin . ls ( { type : 'indirect' } , ( err , pinset ) => {
95
+ it ( '.ls' , ( done ) => {
96
+ ipfs . pin . ls ( ( err , pinset ) => {
92
97
expect ( err ) . to . not . exist ( )
93
98
expect ( pinset ) . to . not . be . empty ( )
99
+ expect ( pinset ) . to . deep . include ( {
100
+ hash : testHash ,
101
+ type : 'direct'
102
+ } )
94
103
done ( )
95
104
} )
96
105
} )
97
106
98
- it ( '.ls type recursive ' , ( done ) => {
99
- ipfs . pin . ls ( { type : 'recursive ' } , ( err , pinset ) => {
107
+ it ( '.ls type direct ' , ( done ) => {
108
+ ipfs . pin . ls ( { type : 'direct ' } , ( err , pinset ) => {
100
109
expect ( err ) . to . not . exist ( )
101
- expect ( pinset ) . to . not . be . empty ( )
110
+ expect ( pinset ) . to . deep . include ( {
111
+ hash : testHash ,
112
+ type : 'direct'
113
+ } )
102
114
done ( )
103
115
} )
104
116
} )
105
117
106
118
it ( '.ls for a specific hash' , ( done ) => {
107
- const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
108
-
109
- ipfs . pin . ls ( hash , ( err , pinset ) => {
119
+ ipfs . pin . ls ( testHash , ( err , pinset ) => {
110
120
expect ( err ) . to . not . exist ( )
111
- expect ( pinset ) . to . exist ( )
121
+ expect ( pinset ) . to . deep . equal ( [ {
122
+ hash : testHash ,
123
+ type : 'direct'
124
+ } ] )
112
125
done ( )
113
126
} )
114
127
} )
115
128
} )
116
129
117
130
describe ( 'promise API' , ( ) => {
118
131
it ( '.add' , ( ) => {
119
- const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
120
-
121
- return ipfs . pin . add ( hash , { recursive : false } )
132
+ return ipfs . pin . add ( testHash , { recursive : false } )
122
133
. then ( ( pinset ) => {
123
- expect ( pinset [ 0 ] ) . to . be . equal ( hash )
134
+ expect ( pinset ) . to . deep . equal ( [ {
135
+ hash : testHash
136
+ } ] )
124
137
} )
125
138
} )
126
139
127
140
it ( '.ls' , ( ) => {
128
141
return ipfs . pin . ls ( )
129
142
. then ( ( pinset ) => {
130
- expect ( pinset ) . to . exist ( )
131
- expect ( pinset ) . to . not . be . empty ( )
143
+ expect ( pinset ) . to . deep . include ( {
144
+ hash : testHash ,
145
+ type : 'direct'
146
+ } )
132
147
} )
133
148
} )
134
149
135
150
it ( '.ls hash' , ( ) => {
136
- const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
137
-
138
- return ipfs . pin . ls ( hash )
151
+ return ipfs . pin . ls ( testHash )
139
152
. then ( ( pinset ) => {
140
- expect ( pinset ) . to . exist ( )
153
+ expect ( pinset ) . to . deep . equal ( [ {
154
+ hash : testHash ,
155
+ type : 'direct'
156
+ } ] )
141
157
} )
142
158
} )
143
159
144
160
it ( '.rm' , ( ) => {
145
- const hash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
146
-
147
- return ipfs . pin . rm ( hash , { recursive : false } )
161
+ return ipfs . pin . rm ( testHash , { recursive : false } )
148
162
. then ( ( pinset ) => {
163
+ expect ( pinset ) . to . deep . equal ( [ {
164
+ hash : testHash
165
+ } ] )
149
166
return ipfs . pin . ls ( { type : 'direct' } )
150
167
} )
151
168
. then ( ( pinset ) => {
152
- expect ( pinset ) . to . be . empty ( )
169
+ expect ( pinset ) . to . not . deep . include ( {
170
+ hash : testHash
171
+ } )
153
172
} )
154
173
} )
155
174
} )
0 commit comments