File: download.jl

package info (click to toggle)
julia 1.0.3%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 49,452 kB
  • sloc: lisp: 236,453; ansic: 55,579; cpp: 25,603; makefile: 1,685; pascal: 1,130; sh: 956; asm: 86; xml: 76
file content (33 lines) | stat: -rw-r--r-- 1,414 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# This file is a part of Julia. License is MIT: https://julialang.org/license

mktempdir() do temp_dir
    # Download a file
    file = joinpath(temp_dir, "ip")
    @test download("http://httpbin.org/ip", file) == file
    @test isfile(file)
    @test !isempty(read(file))

    # Download an empty file
    empty_file = joinpath(temp_dir, "empty")
    @test download("http://httpbin.org/status/200", empty_file) == empty_file

    # Windows and older versions of curl do not create the empty file (https://github.com/curl/curl/issues/183)
    @test !isfile(empty_file) || isempty(read(empty_file))

    # Make sure that failed downloads do not leave files around
    missing_file = joinpath(temp_dir, "missing")
    @test_throws ErrorException download("http://httpbin.org/status/404", missing_file)
    @test !isfile(missing_file)

    # Make sure we properly handle metachar '
    metachar_file = joinpath(temp_dir, "metachar")
    download("https://httpbin.org/get?test='^'", metachar_file)
    metachar_string = read(metachar_file, String)
    m = match(r"\"url\"\s*:\s*\"(.*)\"", metachar_string)
    @test m.captures[1] == "https://httpbin.org/get?test='^'"

    # Use a TEST-NET (192.0.2.0/24) address which shouldn't be bound
    invalid_host_file = joinpath(temp_dir, "invalid_host")
    @test_throws ErrorException download("http://192.0.2.1", invalid_host_file)
    @test !isfile(invalid_host_file)
end