@@ -7,7 +7,7 @@ const chai = require('chai')
7
7
const dirtyChai = require ( 'dirty-chai' )
8
8
const expect = chai . expect
9
9
chai . use ( dirtyChai )
10
- const loadFixture = require ( 'aegir/fixtures ' )
10
+ const { fixtures } = require ( './utils ' )
11
11
const Readable = require ( 'readable-stream' ) . Readable
12
12
const pull = require ( 'pull-stream' )
13
13
const path = require ( 'path' )
@@ -24,28 +24,6 @@ module.exports = (createCommon, options) => {
24
24
25
25
let ipfs
26
26
27
- const smallFile = {
28
- cid : 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ,
29
- data : loadFixture ( 'js/test/fixtures/testfile.txt' , 'interface-ipfs-core' )
30
- }
31
-
32
- const bigFile = {
33
- cid : 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' ,
34
- data : loadFixture ( 'js/test/fixtures/15mb.random' , 'interface-ipfs-core' )
35
- }
36
-
37
- const directory = {
38
- cid : 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP' ,
39
- files : {
40
- 'pp.txt' : loadFixture ( 'js/test/fixtures/test-folder/pp.txt' , 'interface-ipfs-core' ) ,
41
- 'holmes.txt' : loadFixture ( 'js/test/fixtures/test-folder/holmes.txt' , 'interface-ipfs-core' ) ,
42
- 'jungle.txt' : loadFixture ( 'js/test/fixtures/test-folder/jungle.txt' , 'interface-ipfs-core' ) ,
43
- 'alice.txt' : loadFixture ( 'js/test/fixtures/test-folder/alice.txt' , 'interface-ipfs-core' ) ,
44
- 'files/hello.txt' : loadFixture ( 'js/test/fixtures/test-folder/files/hello.txt' , 'interface-ipfs-core' ) ,
45
- 'files/ipfs.txt' : loadFixture ( 'js/test/fixtures/test-folder/files/ipfs.txt' , 'interface-ipfs-core' )
46
- }
47
- }
48
-
49
27
before ( function ( done ) {
50
28
// CI takes longer to instantiate the daemon, so we need to increase the
51
29
// timeout for the before step
@@ -64,38 +42,38 @@ module.exports = (createCommon, options) => {
64
42
after ( ( done ) => common . teardown ( done ) )
65
43
66
44
it ( 'should add a Buffer' , ( done ) => {
67
- ipfs . files . add ( smallFile . data , ( err , filesAdded ) => {
45
+ ipfs . files . add ( fixtures . smallFile . data , ( err , filesAdded ) => {
68
46
expect ( err ) . to . not . exist ( )
69
47
70
48
expect ( filesAdded ) . to . have . length ( 1 )
71
49
const file = filesAdded [ 0 ]
72
- expect ( file . hash ) . to . equal ( smallFile . cid )
73
- expect ( file . path ) . to . equal ( smallFile . cid )
50
+ expect ( file . hash ) . to . equal ( fixtures . smallFile . cid )
51
+ expect ( file . path ) . to . equal ( fixtures . smallFile . cid )
74
52
// file.size counts the overhead by IPLD nodes and unixfs protobuf
75
- expect ( file . size ) . greaterThan ( smallFile . data . length )
53
+ expect ( file . size ) . greaterThan ( fixtures . smallFile . data . length )
76
54
done ( )
77
55
} )
78
56
} )
79
57
80
58
it ( 'should add a Buffer (promised)' , ( ) => {
81
- return ipfs . files . add ( smallFile . data )
59
+ return ipfs . files . add ( fixtures . smallFile . data )
82
60
. then ( ( filesAdded ) => {
83
61
const file = filesAdded [ 0 ]
84
- expect ( file . hash ) . to . equal ( smallFile . cid )
85
- expect ( file . path ) . to . equal ( smallFile . cid )
62
+ expect ( file . hash ) . to . equal ( fixtures . smallFile . cid )
63
+ expect ( file . path ) . to . equal ( fixtures . smallFile . cid )
86
64
} )
87
65
} )
88
66
89
67
it ( 'should add a BIG Buffer' , ( done ) => {
90
- ipfs . files . add ( bigFile . data , ( err , filesAdded ) => {
68
+ ipfs . files . add ( fixtures . bigFile . data , ( err , filesAdded ) => {
91
69
expect ( err ) . to . not . exist ( )
92
70
93
71
expect ( filesAdded ) . to . have . length ( 1 )
94
72
const file = filesAdded [ 0 ]
95
- expect ( file . hash ) . to . equal ( bigFile . cid )
96
- expect ( file . path ) . to . equal ( bigFile . cid )
73
+ expect ( file . hash ) . to . equal ( fixtures . bigFile . cid )
74
+ expect ( file . path ) . to . equal ( fixtures . bigFile . cid )
97
75
// file.size counts the overhead by IPLD nodes and unixfs protobuf
98
- expect ( file . size ) . greaterThan ( bigFile . data . length )
76
+ expect ( file . size ) . greaterThan ( fixtures . bigFile . data . length )
99
77
done ( )
100
78
} )
101
79
} )
@@ -108,22 +86,22 @@ module.exports = (createCommon, options) => {
108
86
accumProgress = p
109
87
}
110
88
111
- ipfs . files . add ( bigFile . data , { progress : handler } , ( err , filesAdded ) => {
89
+ ipfs . files . add ( fixtures . bigFile . data , { progress : handler } , ( err , filesAdded ) => {
112
90
expect ( err ) . to . not . exist ( )
113
91
114
92
expect ( filesAdded ) . to . have . length ( 1 )
115
93
const file = filesAdded [ 0 ]
116
- expect ( file . hash ) . to . equal ( bigFile . cid )
117
- expect ( file . path ) . to . equal ( bigFile . cid )
94
+ expect ( file . hash ) . to . equal ( fixtures . bigFile . cid )
95
+ expect ( file . path ) . to . equal ( fixtures . bigFile . cid )
118
96
119
97
expect ( progCalled ) . to . be . true ( )
120
- expect ( accumProgress ) . to . equal ( bigFile . data . length )
98
+ expect ( accumProgress ) . to . equal ( fixtures . bigFile . data . length )
121
99
done ( )
122
100
} )
123
101
} )
124
102
125
103
it ( 'should add a Buffer as tuple' , ( done ) => {
126
- const tuple = { path : 'testfile.txt' , content : smallFile . data }
104
+ const tuple = { path : 'testfile.txt' , content : fixtures . smallFile . data }
127
105
128
106
ipfs . files . add ( [
129
107
tuple
@@ -132,7 +110,7 @@ module.exports = (createCommon, options) => {
132
110
133
111
expect ( filesAdded ) . to . have . length ( 1 )
134
112
const file = filesAdded [ 0 ]
135
- expect ( file . hash ) . to . equal ( smallFile . cid )
113
+ expect ( file . hash ) . to . equal ( fixtures . smallFile . cid )
136
114
expect ( file . path ) . to . equal ( 'testfile.txt' )
137
115
138
116
done ( )
@@ -222,7 +200,7 @@ module.exports = (createCommon, options) => {
222
200
it ( 'should add a nested directory as array of tupples' , function ( done ) {
223
201
const content = ( name ) => ( {
224
202
path : `test-folder/${ name } ` ,
225
- content : directory . files [ name ]
203
+ content : fixtures . directory . files [ name ]
226
204
} )
227
205
228
206
const emptyDir = ( name ) => ( { path : `test-folder/${ name } ` } )
@@ -243,15 +221,15 @@ module.exports = (createCommon, options) => {
243
221
const root = res [ res . length - 1 ]
244
222
245
223
expect ( root . path ) . to . equal ( 'test-folder' )
246
- expect ( root . hash ) . to . equal ( directory . cid )
224
+ expect ( root . hash ) . to . equal ( fixtures . directory . cid )
247
225
done ( )
248
226
} )
249
227
} )
250
228
251
229
it ( 'should add a nested directory as array of tupples with progress' , function ( done ) {
252
230
const content = ( name ) => ( {
253
231
path : `test-folder/${ name } ` ,
254
- content : directory . files [ name ]
232
+ content : fixtures . directory . files [ name ]
255
233
} )
256
234
257
235
const emptyDir = ( name ) => ( { path : `test-folder/${ name } ` } )
@@ -285,7 +263,7 @@ module.exports = (createCommon, options) => {
285
263
expect ( progCalled ) . to . be . true ( )
286
264
expect ( accumProgress ) . to . be . at . least ( total )
287
265
expect ( root . path ) . to . equal ( 'test-folder' )
288
- expect ( root . hash ) . to . equal ( directory . cid )
266
+ expect ( root . hash ) . to . equal ( fixtures . directory . cid )
289
267
done ( )
290
268
} )
291
269
} )
@@ -300,14 +278,14 @@ module.exports = (createCommon, options) => {
300
278
} )
301
279
302
280
it ( 'should wrap content in a directory' , ( done ) => {
303
- const data = { path : 'testfile.txt' , content : smallFile . data }
281
+ const data = { path : 'testfile.txt' , content : fixtures . smallFile . data }
304
282
305
283
ipfs . files . add ( data , { wrapWithDirectory : true } , ( err , filesAdded ) => {
306
284
expect ( err ) . to . not . exist ( )
307
285
expect ( filesAdded ) . to . have . length ( 2 )
308
286
const file = filesAdded [ 0 ]
309
287
const wrapped = filesAdded [ 1 ]
310
- expect ( file . hash ) . to . equal ( smallFile . cid )
288
+ expect ( file . hash ) . to . equal ( fixtures . smallFile . cid )
311
289
expect ( file . path ) . to . equal ( 'testfile.txt' )
312
290
expect ( wrapped . path ) . to . equal ( '' )
313
291
done ( )
0 commit comments