@@ -8,212 +8,104 @@ const dirtyChai = require('dirty-chai')
8
8
const expect = chai . expect
9
9
chai . use ( dirtyChai )
10
10
const isNode = require ( 'detect-node' )
11
- const fs = require ( 'fs' )
12
- const concat = require ( 'concat-stream' )
13
- const through = require ( 'through2' )
14
- const streamEqual = require ( 'stream-equal' )
15
- const path = require ( 'path' )
11
+ const series = require ( 'async/series' )
16
12
const loadFixture = require ( 'aegir/fixtures' )
17
13
const FactoryClient = require ( './ipfs-factory/client' )
18
14
19
- const testfile = loadFixture ( __dirname , '/fixtures/testfile.txt' )
20
- let testfileBig
21
- let tfbPath
15
+ describe ( '.get (specific go-ipfs features)' , function ( ) {
16
+ this . timeout ( 20 * 1000 )
22
17
23
- if ( isNode ) {
24
- tfbPath = path . join ( __dirname , '/fixtures/15mb.random' )
25
- testfileBig = fs . createReadStream ( tfbPath , { bufferSize : 128 } )
26
- }
18
+ function fixture ( path ) {
19
+ return loadFixture ( __dirname , path , 'interface-ipfs-core' )
20
+ }
27
21
28
- describe ( '.get' , function ( ) {
29
- this . timeout ( 80 * 1000 )
22
+ const smallFile = {
23
+ cid : 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ,
24
+ data : fixture ( '../test/fixtures/testfile.txt' )
25
+ }
30
26
31
27
let ipfs
32
28
let fc
33
29
34
30
before ( ( done ) => {
35
31
fc = new FactoryClient ( )
36
- fc . spawnNode ( ( err , node ) => {
37
- expect ( err ) . to . not . exist ( )
38
- ipfs = node
39
- done ( )
40
- } )
41
- } )
42
-
43
- after ( ( done ) => fc . dismantle ( done ) )
44
-
45
- describe ( 'Callback API' , ( ) => {
46
- this . timeout ( 80 * 1000 )
47
-
48
- it ( 'add file for testing' , ( done ) => {
49
- const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
50
-
51
- ipfs . files . add ( testfile , ( err , res ) => {
52
- expect ( err ) . to . not . exist ( )
53
-
54
- expect ( res ) . to . have . length ( 1 )
55
- expect ( res [ 0 ] . hash ) . to . equal ( expectedMultihash )
56
- expect ( res [ 0 ] . path ) . to . equal ( expectedMultihash )
57
- done ( )
58
- } )
59
- } )
60
32
61
- it ( 'get with no compression args' , ( done ) => {
62
- ipfs . get ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' , ( err , res ) => {
33
+ series ( [
34
+ ( cb ) => fc . spawnNode ( ( err , node ) => {
63
35
expect ( err ) . to . not . exist ( )
36
+ ipfs = node
37
+ cb ( )
38
+ } ) ,
39
+ ( cb ) => ipfs . files . add ( smallFile . data , cb )
40
+ ] , done )
41
+ } )
64
42
65
- // accumulate the files and their content
66
- var files = [ ]
67
-
68
- res . pipe ( through . obj ( ( file , enc , next ) => {
69
- file . content . pipe ( concat ( ( content ) => {
70
- files . push ( {
71
- path : file . path ,
72
- content : content
73
- } )
74
- next ( )
75
- } ) )
76
- } , ( ) => {
77
- expect ( files ) . to . be . length ( 1 )
78
- expect ( files [ 0 ] . content . toString ( ) ) . to . contain ( testfile . toString ( ) )
79
- done ( )
80
- } ) )
81
- } )
82
- } )
43
+ after ( ( done ) => fc . dismantle ( done ) )
83
44
84
- it ( 'get with archive true' , ( done ) => {
85
- ipfs . get ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' , {
86
- archive : true
87
- } , ( err , res ) => {
88
- expect ( err ) . to . not . exist ( )
45
+ it ( 'no compression args' , ( done ) => {
46
+ ipfs . get ( smallFile . cid , ( err , files ) => {
47
+ expect ( err ) . to . not . exist ( )
89
48
90
- // accumulate the files and their content
91
- var files = [ ]
92
-
93
- res . pipe ( through . obj ( ( file , enc , next ) => {
94
- file . content . pipe ( concat ( ( content ) => {
95
- files . push ( {
96
- path : file . path ,
97
- content : content
98
- } )
99
- next ( )
100
- } ) )
101
- } , ( ) => {
102
- expect ( files ) . to . be . length ( 1 )
103
- expect ( files [ 0 ] . content . toString ( ) ) . to . contain ( testfile . toString ( ) )
104
- done ( )
105
- } ) )
106
- } )
49
+ expect ( files ) . to . be . length ( 1 )
50
+ expect ( files [ 0 ] . content . toString ( ) ) . to . contain ( smallFile . data . toString ( ) )
51
+ done ( )
107
52
} )
53
+ } )
108
54
109
- it ( 'get err with out of range compression level' , ( done ) => {
110
- ipfs . get ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' , {
111
- compress : true ,
112
- 'compression-level' : 10
113
- } , ( err , res ) => {
114
- expect ( err ) . to . exist ( )
115
- expect ( err . toString ( ) ) . to . equal ( 'Error: Compression level must be between 1 and 9' )
116
- done ( )
117
- } )
118
- } )
55
+ it ( 'archive true' , ( done ) => {
56
+ ipfs . get ( smallFile . cid , { archive : true } , ( err , files ) => {
57
+ expect ( err ) . to . not . exist ( )
119
58
120
- it ( 'get with compression level' , ( done ) => {
121
- ipfs . get ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' , {
122
- compress : true ,
123
- 'compression-level' : 1
124
- } , ( err , res ) => {
125
- expect ( err ) . to . not . exist ( )
126
- done ( )
127
- } )
59
+ expect ( files ) . to . be . length ( 1 )
60
+ expect ( files [ 0 ] . content . toString ( ) ) . to . contain ( smallFile . data . toString ( ) )
61
+ done ( )
128
62
} )
63
+ } )
129
64
130
- it ( 'add a BIG file (for testing get)' , ( done ) => {
131
- if ( ! isNode ) { return done ( ) }
132
-
133
- const bigFile = fs . readFileSync ( tfbPath )
134
- const expectedMultihash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq'
135
-
136
- ipfs . files . add ( bigFile , ( err , res ) => {
137
- expect ( err ) . to . not . exist ( )
138
-
139
- expect ( res ) . to . have . length ( 1 )
140
- expect ( res [ 0 ] . path ) . to . equal ( expectedMultihash )
141
- expect ( res [ 0 ] . hash ) . to . equal ( expectedMultihash )
142
- done ( )
143
- } )
65
+ it ( 'err with out of range compression level' , ( done ) => {
66
+ ipfs . get ( smallFile . cid , {
67
+ compress : true ,
68
+ 'compression-level' : 10
69
+ } , ( err , files ) => {
70
+ expect ( err ) . to . exist ( )
71
+ expect ( err . toString ( ) ) . to . equal ( 'Error: Compression level must be between 1 and 9' )
72
+ done ( )
144
73
} )
74
+ } )
145
75
146
- it ( 'get BIG file' , ( done ) => {
147
- if ( ! isNode ) { return done ( ) }
148
-
149
- ipfs . get ( 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq' , ( err , files ) => {
150
- expect ( err ) . to . not . exist ( )
76
+ it ( 'with compression level' , ( done ) => {
77
+ ipfs . get ( smallFile . cid , { compress : true , 'compression-level' : 1 } , done )
78
+ } )
151
79
152
- files . on ( 'data' , ( file ) => {
153
- // Do not blow out the memory of nodejs :)
154
- streamEqual ( file . content , testfileBig , ( err , equal ) => {
155
- expect ( err ) . to . not . exist ( )
156
- expect ( equal ) . to . equal ( true )
157
- done ( )
158
- } )
159
- } )
160
- } )
80
+ it ( 'add path containing "+"s (for testing get)' , ( done ) => {
81
+ if ( ! isNode ) { return done ( ) }
82
+ const filename = 'ti,c64x+mega++mod-pic.txt'
83
+ const subdir = 'tmp/c++files'
84
+ const expectedCid = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
85
+ ipfs . add ( [ {
86
+ path : subdir + '/' + filename ,
87
+ content : Buffer . from ( subdir + '/' + filename , 'utf-8' )
88
+ } ] , ( err , files ) => {
89
+ expect ( err ) . to . not . exist ( )
90
+ expect ( files [ 2 ] . hash ) . to . equal ( expectedCid )
91
+ done ( )
161
92
} )
93
+ } )
162
94
163
- it ( 'add path containing "+"s (for testing get)' , ( done ) => {
164
- if ( ! isNode ) { return done ( ) }
165
- const filename = 'ti,c64x+mega++mod-pic.txt'
166
- const subdir = 'tmp/c++files'
167
- const expectedMultihash = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
168
- ipfs . files . add ( [ {
169
- path : subdir + '/' + filename ,
170
- content : Buffer . from ( subdir + '/' + filename , 'utf-8' )
171
- } ] , ( err , res ) => {
172
- if ( err ) done ( err )
173
- expect ( res [ 2 ] . hash ) . to . equal ( expectedMultihash )
174
- done ( )
175
- } )
176
- } )
95
+ it ( 'get path containing "+"s' , ( done ) => {
96
+ if ( ! isNode ) { return done ( ) }
177
97
178
- it ( 'get path containing "+"s' , ( done ) => {
179
- if ( ! isNode ) { return done ( ) }
180
- const multihash = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
181
- let count = 0
182
- ipfs . get ( multihash , ( err , files ) => {
183
- expect ( err ) . to . not . exist ( )
184
- files . on ( 'data' , ( file ) => {
185
- if ( file . path !== multihash ) {
186
- count ++
187
- expect ( file . path ) . to . contain ( '+' )
188
- if ( count === 2 ) done ( )
189
- }
190
- } )
98
+ const cid = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
99
+ let count = 0
100
+ ipfs . get ( cid , ( err , files ) => {
101
+ expect ( err ) . to . not . exist ( )
102
+ files . forEach ( ( file ) => {
103
+ if ( file . path !== cid ) {
104
+ count ++
105
+ expect ( file . path ) . to . contain ( '+' )
106
+ if ( count === 2 ) done ( )
107
+ }
191
108
} )
192
109
} )
193
110
} )
194
-
195
- describe ( 'Promise API' , ( ) => {
196
- this . timeout ( 80 * 1000 )
197
-
198
- it ( 'get' , ( done ) => {
199
- ipfs . get ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' )
200
- . then ( ( files ) => {
201
- files . on ( 'data' , ( file ) => {
202
- let buf = ''
203
- file . content
204
- . on ( 'error' , ( err ) => expect ( err ) . to . not . exist ( ) )
205
- . on ( 'data' , ( data ) => {
206
- buf += data . toString ( )
207
- } )
208
- . on ( 'end' , ( ) => {
209
- expect ( buf ) . to . contain ( testfile . toString ( ) )
210
- done ( )
211
- } )
212
- } )
213
- } )
214
- . catch ( ( err ) => {
215
- expect ( err ) . to . not . exist ( )
216
- } )
217
- } )
218
- } )
219
111
} )
0 commit comments