Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run tests with both backends #262

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
9 changes: 8 additions & 1 deletion src/AWSS3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,18 @@ function s3_get_file(
end

"""
s3_get_meta([::AbstractAWSConfig], bucket, path; [version=], kwargs...)
s3_get_meta([::AbstractAWSConfig], bucket, path; [version=], kwargs...)

[HEAD Object](http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectHEAD.html)

Retrieves metadata from an object without returning the object itself.

!!! warning
This function returns the headers from `S3.head_object` as `Dict` of key-value pairs.
[HTTP/1.1 headers are case insensitive](https://datatracker.ietf.org/doc/html/rfc2616#section-4.2)
while [HTTP/2 headers must be lowercase](https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2).
Therefore, the casing of the keys of the returned dict may depend on the HTTP client implementation
(e.g. via `AWS.DownloadsBackend` vs `AWS.HTTPBackend`).
"""
function s3_get_meta(
aws::AbstractAWSConfig, bucket, path; version::AbstractS3Version=nothing, kwargs...
Expand Down
4 changes: 2 additions & 2 deletions test/awss3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ function awss3_tests(config)

@testset "Check Metadata" begin
meta = s3_get_meta(config, bucket_name, "key1")
@test meta["ETag"] == "\"68bc8898af64159b72f349b391a7ae35\""
@test AWSS3.get_robust_case(meta, "ETag") == "\"68bc8898af64159b72f349b391a7ae35\""
end

@testset "default Content-Type" begin
# https://github.com/samoconnor/AWSS3.jl/issues/24
ctype(key) = s3_get_meta(bucket_name, key)["Content-Type"]
ctype(key) = AWSS3.get_robust_case(s3_get_meta(bucket_name, key), "Content-Type")

for k in ["file.foo", "file", "file_html", "file.d/html", "foobar.html/file.htm"]
is_aws(config) && k == "file" && continue
Expand Down
15 changes: 12 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,17 @@ include("awss3.jl") # creates `s3path_tests(config)`

# Set `AWSConfig` as the default for the following tests
aws = global_aws_config(AWSConfig())
@testset "S3" begin
awss3_tests(aws)
s3path_tests(aws)

prev_backend = AWS.DEFAULT_BACKEND[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to keep track of the previous backend and reset it? We don't bother w/ AWS.jl

for backend in (AWS.HTTPBackend, AWS.DownloadsBackend)
AWS.DEFAULT_BACKEND[] = backend()
try
@testset "S3 with $backend" begin
awss3_tests(aws)
s3path_tests(aws)
end
finally
AWS.DEFAULT_BACKEND[] = prev_backend
end
end
end
12 changes: 11 additions & 1 deletion test/s3path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,17 @@ function s3path_tests(config)
alt_region = prev_config.region == "us-east-2" ? "us-east-1" : "us-east-2"
try
global_aws_config(; region=alt_region) # this is the wrong region!
@test_throws AWS.AWSException read(path, String)
if AWS.DEFAULT_BACKEND[] isa AWS.DownloadsBackend
# https://github.com/JuliaCloud/AWS.jl/issues/564
local e
try
read(path, String)
catch e
end
@test_broken e isa AWS.AWSException
else
@test_throws AWS.AWSException read(path, String)
end

# restore the right region
global_aws_config(prev_config)
Expand Down