Skip to content

Commit decead1

Browse files
committed
Add tests for download
1 parent dd5a7ac commit decead1

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ script:
128128
- export JULIA_CPU_CORES=2 && export JULIA_TEST_MAXRSS_MB=600 &&
129129
cd /tmp/julia/share/julia/test &&
130130
/tmp/julia/bin/julia --check-bounds=yes runtests.jl $TESTSTORUN &&
131-
/tmp/julia/bin/julia --check-bounds=yes runtests.jl libgit2-online pkg
131+
/tmp/julia/bin/julia --check-bounds=yes runtests.jl libgit2-online download pkg
132132
- cd `dirname $TRAVIS_BUILD_DIR` && mv julia2 julia &&
133133
rm -f julia/deps/scratch/libgit2-*/CMakeFiles/CMakeOutput.log
134134
# uncomment the following if failures are suspected to be due to the out-of-memory killer

appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ test_script:
5656
- usr\bin\julia -e "versioninfo()"
5757
- usr\bin\julia --precompiled=no -e "true"
5858
- cd test && ..\usr\bin\julia --check-bounds=yes runtests.jl all &&
59-
..\usr\bin\julia --check-bounds=yes runtests.jl libgit2-online pkg
59+
..\usr\bin\julia --check-bounds=yes runtests.jl libgit2-online download pkg

test/download.jl

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This file is a part of Julia. License is MIT: http://julialang.org/license
2+
3+
mktempdir() do temp_dir
4+
# Download a file
5+
file = joinpath(temp_dir, "ip")
6+
@test download("http://httpbin.org/ip", file) == file
7+
@test isfile(file)
8+
@test !isempty(read(file))
9+
10+
# Download an empty file
11+
empty_file = joinpath(temp_dir, "empty")
12+
@test download("http://httpbin.org/status/200", empty_file) == empty_file
13+
14+
# Windows and older versions of curl do not create the empty file (https://github.com/curl/curl/issues/183)
15+
@test !isfile(empty_file) || isempty(read(empty_file))
16+
17+
# Make sure that failed downloads do not leave files around
18+
missing_file = joinpath(temp_dir, "missing")
19+
@test_throws ErrorException download("http://httpbin.org/status/404", missing_file)
20+
@test !isfile(missing_file)
21+
22+
# Use a TEST-NET (192.0.2.0/24) address which shouldn't be bound
23+
invalid_host_file = joinpath(temp_dir, "invalid_host")
24+
@test_throws ErrorException download("http://192.0.2.1", invalid_host_file)
25+
@test !isfile(invalid_host_file)
26+
end

0 commit comments

Comments
 (0)