Skip to content

Commit

Permalink
Add tests for download
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Mar 22, 2017
1 parent dd5a7ac commit decead1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ script:
- export JULIA_CPU_CORES=2 && export JULIA_TEST_MAXRSS_MB=600 &&
cd /tmp/julia/share/julia/test &&
/tmp/julia/bin/julia --check-bounds=yes runtests.jl $TESTSTORUN &&
/tmp/julia/bin/julia --check-bounds=yes runtests.jl libgit2-online pkg
/tmp/julia/bin/julia --check-bounds=yes runtests.jl libgit2-online download pkg
- cd `dirname $TRAVIS_BUILD_DIR` && mv julia2 julia &&
rm -f julia/deps/scratch/libgit2-*/CMakeFiles/CMakeOutput.log
# uncomment the following if failures are suspected to be due to the out-of-memory killer
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ test_script:
- usr\bin\julia -e "versioninfo()"
- usr\bin\julia --precompiled=no -e "true"
- cd test && ..\usr\bin\julia --check-bounds=yes runtests.jl all &&
..\usr\bin\julia --check-bounds=yes runtests.jl libgit2-online pkg
..\usr\bin\julia --check-bounds=yes runtests.jl libgit2-online download pkg
26 changes: 26 additions & 0 deletions test/download.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file is a part of Julia. License is MIT: http:https://julialang.org/license

mktempdir() do temp_dir
# Download a file
file = joinpath(temp_dir, "ip")
@test download("http:https://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:https://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:https://httpbin.org/status/404", missing_file)
@test !isfile(missing_file)

# 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:https://192.0.2.1", invalid_host_file)
@test !isfile(invalid_host_file)
end

0 comments on commit decead1

Please sign in to comment.