@@ -9,9 +9,11 @@ chai.use(dirtyChai)
99const isNode = require ( 'detect-node' )
1010const path = require ( 'path' )
1111const fs = require ( 'fs' )
12+ const os = require ( 'os' )
1213
1314const IPFSApi = require ( '../src' )
1415const f = require ( './utils/factory' )
16+ const expectTimeout = require ( './utils/expect-timeout' )
1517
1618describe ( '.util' , ( ) => {
1719 if ( ! isNode ) { return }
@@ -92,31 +94,66 @@ describe('.util', () => {
9294 done ( )
9395 } )
9496 } )
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+ } )
95110 } )
96111
97- it ( '.urlAdd http' , function ( done ) {
98- this . timeout ( 20 * 1000 )
112+ describe ( '.urlAdd' , ( ) => {
113+ it ( 'http' , function ( done ) {
114+ this . timeout ( 20 * 1000 )
99115
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+ } )
104121 } )
105- } )
106122
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+ } )
112131 } )
113- } )
114132
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 ) )
120157 } )
121158 } )
122159} )
0 commit comments