@@ -9,9 +9,11 @@ chai.use(dirtyChai)
9
9
const isNode = require ( 'detect-node' )
10
10
const path = require ( 'path' )
11
11
const fs = require ( 'fs' )
12
+ const os = require ( 'os' )
12
13
13
14
const IPFSApi = require ( '../src' )
14
15
const f = require ( './utils/factory' )
16
+ const expectTimeout = require ( './utils/expect-timeout' )
15
17
16
18
describe ( '.util' , ( ) => {
17
19
if ( ! isNode ) { return }
@@ -92,31 +94,66 @@ describe('.util', () => {
92
94
done ( )
93
95
} )
94
96
} )
97
+
98
+ it ( 'with only-hash=true' , function ( ) {
99
+ this . slow ( 10 * 1000 )
100
+ const content = String ( Math . random ( ) + Date . now ( ) )
101
+ const filepath = path . join ( os . tmpdir ( ) , `${ content } .txt` )
102
+ fs . writeFileSync ( filepath , content )
103
+
104
+ return ipfs . util . addFromFs ( filepath , { onlyHash : true } )
105
+ . then ( out => {
106
+ fs . unlinkSync ( filepath )
107
+ return expectTimeout ( ipfs . object . get ( out [ 0 ] . hash ) , 4000 )
108
+ } )
109
+ } )
95
110
} )
96
111
97
- it ( '.urlAdd http' , function ( done ) {
98
- this . timeout ( 20 * 1000 )
112
+ describe ( '.urlAdd' , ( ) => {
113
+ it ( 'http' , function ( done ) {
114
+ this . timeout ( 20 * 1000 )
99
115
100
- ipfs . util . addFromURL ( 'http://example.com/' , ( err , result ) => {
101
- expect ( err ) . to . not . exist ( )
102
- expect ( result . length ) . to . equal ( 1 )
103
- done ( )
116
+ ipfs . util . addFromURL ( 'http://example.com/' , ( err , result ) => {
117
+ expect ( err ) . to . not . exist ( )
118
+ expect ( result . length ) . to . equal ( 1 )
119
+ done ( )
120
+ } )
104
121
} )
105
- } )
106
122
107
- it ( '.urlAdd https' , ( done ) => {
108
- ipfs . util . addFromURL ( 'https://example.com/' , ( err , result ) => {
109
- expect ( err ) . to . not . exist ( )
110
- expect ( result . length ) . to . equal ( 1 )
111
- done ( )
123
+ it ( 'https' , function ( done ) {
124
+ this . timeout ( 20 * 1000 )
125
+
126
+ ipfs . util . addFromURL ( 'https://example.com/' , ( err , result ) => {
127
+ expect ( err ) . to . not . exist ( )
128
+ expect ( result . length ) . to . equal ( 1 )
129
+ done ( )
130
+ } )
112
131
} )
113
- } )
114
132
115
- it ( '.urlAdd http with redirection' , ( done ) => {
116
- ipfs . util . addFromURL ( 'https://coverartarchive.org/release/6e2a1694-d8b9-466a-aa33-b1077b2333c1' , ( err , result ) => {
117
- expect ( err ) . to . not . exist ( )
118
- expect ( result [ 0 ] . hash ) . to . equal ( 'QmSUdDvmXuq5YGrL4M3SEz7UZh5eT9WMuAsd9K34sambSj' )
119
- done ( )
133
+ it ( 'http with redirection' , function ( done ) {
134
+ this . timeout ( 20 * 1000 )
135
+
136
+ ipfs . util . addFromURL ( 'http://covers.openlibrary.org/book/id/969165.jpg' , ( err , result ) => {
137
+ expect ( err ) . to . not . exist ( )
138
+ expect ( result [ 0 ] . hash ) . to . equal ( 'QmaL9zy7YUfvWmtD5ZXp42buP7P4xmZJWFkm78p8FJqgjg' )
139
+ done ( )
140
+ } )
141
+ } )
142
+
143
+ it ( '.urlAdd http with redirection' , ( done ) => {
144
+ ipfs . util . addFromURL ( 'https://coverartarchive.org/release/6e2a1694-d8b9-466a-aa33-b1077b2333c1' , ( err , result ) => {
145
+ expect ( err ) . to . not . exist ( )
146
+ expect ( result [ 0 ] . hash ) . to . equal ( 'QmSUdDvmXuq5YGrL4M3SEz7UZh5eT9WMuAsd9K34sambSj' )
147
+ done ( )
148
+ } )
149
+ } )
150
+
151
+ it ( 'with only-hash=true' , function ( ) {
152
+ this . timeout ( 10 * 1000 )
153
+ this . slow ( 10 * 1000 )
154
+
155
+ return ipfs . util . addFromURL ( 'http://www.randomtext.me/#/gibberish' , { onlyHash : true } )
156
+ . then ( out => expectTimeout ( ipfs . object . get ( out [ 0 ] . hash ) , 4000 ) )
120
157
} )
121
158
} )
122
159
} )
0 commit comments