1 |
|
2 | fs = require 'fs'
|
3 | http = require 'http'
|
4 | should = require 'should'
|
5 | mecano = if process.env.MECANO_COV then require '../lib-cov/mecano' else require '../lib/mecano'
|
6 | test = require './test'
|
7 |
|
8 | describe 'download', ->
|
9 |
|
10 | scratch = test.scratch @
|
11 |
|
12 | it 'should deal with http scheme', (next) ->
|
13 | source = 'http://127.0.0.1:12345'
|
14 | destination = "#{scratch}/download_test"
|
15 | server = http.createServer (req, res) ->
|
16 | res.writeHead 200, {'Content-Type': 'text/plain'}
|
17 | res.end 'okay'
|
18 | server.listen 12345
|
19 |
|
20 | mecano.download
|
21 | source: source
|
22 | destination: destination
|
23 | , (err, downloaded) ->
|
24 | should.not.exist err
|
25 | downloaded.should.eql 1
|
26 | fs.readFile destination, 'ascii', (err, content) ->
|
27 | content.should.eql 'okay'
|
28 |
|
29 | mecano.download
|
30 | source: source
|
31 | destination: destination
|
32 | , (err, downloaded) ->
|
33 | should.not.exist err
|
34 | downloaded.should.eql 0
|
35 | server.close()
|
36 | next()
|
37 |
|
38 | it 'should deal with ftp scheme', (next) ->
|
39 | @timeout 10000
|
40 | source = 'ftp://ftp.gnu.org/gnu/glibc/README.glibc'
|
41 | destination = "#{scratch}/download_test"
|
42 |
|
43 | mecano.download
|
44 | source: source
|
45 | destination: destination
|
46 | , (err, downloaded) ->
|
47 | should.not.exist err
|
48 | downloaded.should.eql 1
|
49 | fs.readFile destination, 'ascii', (err, content) ->
|
50 | content.should.include 'GNU'
|
51 |
|
52 | mecano.download
|
53 | source: source
|
54 | destination: destination
|
55 | , (err, downloaded) ->
|
56 | should.not.exist err
|
57 | downloaded.should.eql 0
|
58 | next()
|
59 |
|
60 | it 'should deal with file scheme', (next) ->
|
61 | source = "file://#{__filename}"
|
62 | destination = "#{scratch}/download_test"
|
63 |
|
64 | mecano.download
|
65 | source: source
|
66 | destination: destination
|
67 | , (err, downloaded) ->
|
68 | should.not.exist err
|
69 | downloaded.should.eql 1
|
70 | fs.readFile destination, 'ascii', (err, content) ->
|
71 | content.should.include 'yeah'
|
72 |
|
73 | mecano.download
|
74 | source: source
|
75 | destination: destination
|
76 | , (err, downloaded) ->
|
77 | should.not.exist err
|
78 | downloaded.should.eql 0
|
79 | next()
|
80 |
|
81 |
|
82 |
|