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

Convenience improvements to tests #223

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,14 @@ write(p, "some data")
read(p, byte_range=1:4) # returns b"some"
```

## Testing

Some of the tests involve using a temporary AWS S3 bucket. For these tests to succeed you'll
need to set your current AWS profile to use a role which allows for `s3:*` access to the `arn:aws:s3:::ocaws.jl.test.*` resource.
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm definitely being overly general here but this should grant enough permissions to run


If you do not have AWS access or lack the required permission you can use the
`AWSS3_TESTSETS` environmental variable to control which testsets run:

```bash
AWSS3_TESTSETS=MinIO julia --project -e 'using Pkg; Pkg.test()'
```
15 changes: 12 additions & 3 deletions test/awss3.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
_has_failed(testset::Test.DefaultTestSet) = any(r -> !(r isa Test.Pass), testset.results)

function awss3_tests(config)
bucket_name =
"ocaws.jl.test." * lowercase(Dates.format(now(Dates.UTC), "yyyymmddTHHMMSSZ"))
bucket_name = begin
"ocaws.jl.test." * Dates.format(now(Dates.UTC), dateformat"yyyymmdd\tHHMMSS\z")
end

@testset "Create Bucket" begin
t = @testset "Create Bucket" begin
s3_create_bucket(config, bucket_name)

@test bucket_name in s3_list_buckets(config)
is_aws(config) && s3_enable_versioning(config, bucket_name)
sleep(1)
end

if _has_failed(t)
@warn "Bucket creation has failed. Skipping remaining tests which rely on bucket: $bucket_name"
return nothing
end

@testset "Bucket Tagging" begin
@test isempty(s3_get_tags(config, bucket_name))
tags = Dict("A" => "1", "B" => "2", "C" => "3")
Expand Down
67 changes: 39 additions & 28 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,57 @@ using FilePathsBase.TestPaths
using UUIDs: uuid4
using JSON3

const AWSS3_TESTSETS = split(get(ENV, "AWSS3_TESTSETS", "MinIO,S3"), ',')
omus marked this conversation as resolved.
Show resolved Hide resolved

is_aws(config) = config isa AWSConfig

# Load the test functions
include("s3path.jl") # creates `awss3_tests(config)`
include("awss3.jl") # creates `s3path_tests(config)`

@testset "AWSS3.jl" begin
if VERSION >= v"1.5"
using Minio
AWS.aws_account_number(::Minio.MinioConfig) = "123"

# We run most tests under Minio. This can be done locally by those
# without access to the s3 bucket under which CI is performed.
# We then run all tests with s3 directly.

port = 9005
minio_server = Minio.Server([mktempdir()]; address="localhost:$port")

try
run(minio_server; wait=false)
sleep(0.5) # give the server just a bit of time, though it is amazingly fast to start
config = global_aws_config(
MinioConfig(
"http://localhost:$port"; username="minioadmin", password="minioadmin"
),
@testset "MinIO" begin
if "MinIO" in AWSS3_TESTSETS && VERSION >= v"1.5"
using Minio
AWS.aws_account_number(::Minio.MinioConfig) = "123"

# We run most tests under Minio. This can be done locally by those
# without access to the s3 bucket under which CI is performed.
mattBrzezinski marked this conversation as resolved.
Show resolved Hide resolved
# We then run all tests with s3 directly.

port = 9005
minio_server = Minio.Server([mktempdir()]; address="localhost:$port")

minio_config = MinioConfig(
"http://localhost:$port"; username="minioadmin", password="minioadmin"
)
@testset "Minio" begin
awss3_tests(config)
s3path_tests(config)

try
run(minio_server; wait=false)
sleep(0.5) # give the server just a bit of time, though it is amazingly fast to start

awss3_tests(minio_config)
s3path_tests(minio_config)
finally
# Make sure we kill the server even if a test failed.
kill(minio_server)
end
finally
# Make sure we kill the server even if a test failed.
kill(minio_server)
elseif VERSION < v"1.5"
@warn "Skipping MinIO tests as they can only be run on Julia ≥ 1.5"
else
@warn "Skipping MinIO tests"
end
end

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

awss3_tests(aws_config)
s3path_tests(aws_config)
else
@warn "Skipping S3 tests"
end
end
end
5 changes: 3 additions & 2 deletions test/s3path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,9 @@ end

# This is the main entrypoint for the S3Path tests
function s3path_tests(config)
bucket_name =
"ocaws.jl.test." * lowercase(Dates.format(now(Dates.UTC), "yyyymmddTHHMMSSZ"))
bucket_name = begin
"ocaws.jl.test." * Dates.format(now(Dates.UTC), dateformat"yyyymmdd\tHHMMSS\z")
end

s3_create_bucket(config, bucket_name)
root = Path("s3://$bucket_name/pathset-root/")
Expand Down