@@ -53,21 +53,33 @@ module.exports = (common) => {
53
53
describe ( '.add' , ( ) => {
54
54
it ( 'stream' , ( done ) => {
55
55
const buffered = new Buffer ( 'some data' )
56
+ const expectedMultihash = 'QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS'
57
+
56
58
const rs = new Readable ( )
57
59
rs . push ( buffered )
58
60
rs . push ( null )
59
61
60
62
const arr = [ ]
61
- const filePair = { path : 'data.txt' , content : rs }
63
+ const filePair = {
64
+ path : 'data.txt' ,
65
+ content : rs
66
+ }
67
+
62
68
arr . push ( filePair )
63
69
64
70
ipfs . files . add ( arr , ( err , res ) => {
65
71
expect ( err ) . to . not . exist
66
72
expect ( res ) . to . be . length ( 1 )
67
- expect ( res [ 0 ] . path ) . to . equal ( 'data.txt' )
68
- expect ( res [ 0 ] . node . size ( ) ) . to . equal ( 17 )
69
- const mh = 'QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS'
70
- expect ( bs58 . encode ( res [ 0 ] . node . multihash ( ) ) . toString ( ) ) . to . equal ( mh )
73
+ const file = res [ 0 ]
74
+ expect ( file ) . to . be . eql ( {
75
+ path : 'data.txt' ,
76
+ size : 17 ,
77
+ hash : expectedMultihash
78
+ } )
79
+ expect ( file ) . to . eqlk
80
+ expect ( file . path ) . to . equal ( 'data.txt' )
81
+ expect ( file . size ) . to . equal ( 17 )
82
+ expect ( file . hash ) . to . equal ( expectedMultihash )
71
83
done ( )
72
84
} )
73
85
} )
@@ -77,41 +89,40 @@ module.exports = (common) => {
77
89
path : 'testfile.txt' ,
78
90
content : smallFile
79
91
}
92
+ const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
80
93
81
94
ipfs . files . add ( [ file ] , ( err , res ) => {
82
95
expect ( err ) . to . not . exist
83
96
84
- const added = res [ 0 ] != null ? res [ 0 ] : res
85
- const mh = bs58 . encode ( added . node . multihash ( ) ) . toString ( )
86
- expect ( mh ) . to . equal ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' )
87
- expect ( added . path ) . to . equal ( 'testfile.txt' )
88
- expect ( added . node . links ) . to . have . length ( 0 )
97
+ const file = res [ 0 ]
98
+ expect ( file . hash ) . to . equal ( expectedMultihash )
99
+ expect ( file . path ) . to . equal ( 'testfile.txt' )
89
100
done ( )
90
101
} )
91
102
} )
92
103
93
104
it ( 'buffer' , ( done ) => {
105
+ const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
106
+
94
107
ipfs . files . add ( smallFile , ( err , res ) => {
95
108
expect ( err ) . to . not . exist
96
-
97
109
expect ( res ) . to . have . length ( 1 )
98
- const mh = bs58 . encode ( res [ 0 ] . node . multihash ( ) ) . toString ( )
99
- expect ( mh ) . to . equal ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' )
100
- expect ( res [ 0 ] . path ) . to . equal ( mh )
101
- expect ( res [ 0 ] . node . links ) . to . have . length ( 0 )
110
+ const file = res [ 0 ]
111
+ expect ( file . hash ) . to . equal ( expectedMultihash )
112
+ expect ( file . path ) . to . equal ( file . hash )
102
113
done ( )
103
114
} )
104
115
} )
105
116
106
117
it ( 'BIG buffer' , ( done ) => {
118
+ const expectedMultihash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq'
119
+
107
120
ipfs . files . add ( bigFile , ( err , res ) => {
108
121
expect ( err ) . to . not . exist
109
-
110
122
expect ( res ) . to . have . length ( 1 )
111
- expect ( res [ 0 ] . node . links ) . to . have . length ( 58 )
112
- const mh = bs58 . encode ( res [ 0 ] . node . multihash ( ) ) . toString ( )
113
- expect ( res [ 0 ] . path ) . to . equal ( mh )
114
- expect ( mh ) . to . equal ( 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' )
123
+ const file = res [ 0 ]
124
+ expect ( file . hash ) . to . equal ( expectedMultihash )
125
+ expect ( file . path ) . to . equal ( file . hash )
115
126
done ( )
116
127
} )
117
128
} )
@@ -121,9 +132,13 @@ module.exports = (common) => {
121
132
path : `test-folder/${ name } ` ,
122
133
content : directoryContent [ name ]
123
134
} )
135
+
124
136
const emptyDir = ( name ) => ( {
125
137
path : `test-folder/${ name } `
126
138
} )
139
+
140
+ const expectedRootMultihash = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
141
+
127
142
const dirs = [
128
143
content ( 'pp.txt' ) ,
129
144
content ( 'holmes.txt' ) ,
@@ -137,13 +152,10 @@ module.exports = (common) => {
137
152
138
153
ipfs . files . add ( dirs , ( err , res ) => {
139
154
expect ( err ) . to . not . exist
155
+ const root = res [ res . length - 1 ]
140
156
141
- const added = res [ res . length - 1 ]
142
- const mh = bs58 . encode ( added . node . multihash ( ) ) . toString ( )
143
- expect ( added . node . links ) . to . have . length ( 6 )
144
- expect ( added . path ) . to . equal ( 'test-folder' )
145
- expect ( mh ) . to . equal ( 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP' )
146
-
157
+ expect ( root . path ) . to . equal ( 'test-folder' )
158
+ expect ( root . hash ) . to . equal ( expectedRootMultihash )
147
159
done ( )
148
160
} )
149
161
} )
@@ -154,9 +166,13 @@ module.exports = (common) => {
154
166
path : `test-folder/${ name } ` ,
155
167
content : directoryContent [ name ]
156
168
} )
169
+
157
170
const emptyDir = ( name ) => ( {
158
171
path : `test-folder/${ name } `
159
172
} )
173
+
174
+ const expectedRootMultihash = 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP'
175
+
160
176
const files = [
161
177
content ( 'pp.txt' ) ,
162
178
content ( 'holmes.txt' ) ,
@@ -171,11 +187,9 @@ module.exports = (common) => {
171
187
ipfs . files . createAddStream ( ( err , stream ) => {
172
188
expect ( err ) . to . not . exist
173
189
174
- stream . on ( 'data' , ( tuple ) => {
175
- if ( tuple . path === 'test-folder' ) {
176
- const mh = bs58 . encode ( tuple . node . multihash ( ) ) . toString ( )
177
- expect ( mh ) . to . equal ( 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP' )
178
- expect ( tuple . node . links ) . to . have . length ( 6 )
190
+ stream . on ( 'data' , ( file ) => {
191
+ if ( file . path === 'test-folder' ) {
192
+ expect ( file . hash ) . to . equal ( expectedRootMultihash )
179
193
}
180
194
} )
181
195
@@ -232,14 +246,14 @@ module.exports = (common) => {
232
246
233
247
describe ( 'promise API' , ( ) => {
234
248
describe ( '.add' , ( ) => {
249
+ const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
250
+
235
251
it ( 'buffer' , ( ) => {
236
252
return ipfs . files . add ( smallFile )
237
253
. then ( ( res ) => {
238
- const added = res [ 0 ] != null ? res [ 0 ] : res
239
- const mh = bs58 . encode ( added . node . multihash ( ) ) . toString ( )
240
- expect ( mh ) . to . equal ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' )
241
- expect ( added . path ) . to . equal ( mh )
242
- expect ( added . node . links ) . to . have . length ( 0 )
254
+ const file = res [ 0 ]
255
+ expect ( file . hash ) . to . equal ( expectedMultihash )
256
+ expect ( file . path ) . to . equal ( file . hash )
243
257
} )
244
258
} )
245
259
} )
0 commit comments