slash works
This commit is contained in:
+81
-37
@@ -118,14 +118,7 @@ using UUIDs: uuid4
|
||||
@test storage isa GarageStorage
|
||||
end
|
||||
|
||||
# --- put_file callable struct (slash detection) ---
|
||||
|
||||
@testset "put_file callable struct returns nothing for keys with slashes" begin
|
||||
storage = GarageStorage("https://s3-api.example.com", "key", "secret", "bucket")
|
||||
uploader = put_file(storage)
|
||||
result = @test_logs (:warn, r"Upload aborted") uploader("a/b.json", "data")
|
||||
@test result === nothing
|
||||
end
|
||||
# --- put_file callable struct ---
|
||||
|
||||
@testset "put_file callable struct type is correct" begin
|
||||
storage = GarageStorage("https://s3-api.example.com", "key", "secret", "bucket")
|
||||
@@ -139,32 +132,6 @@ using UUIDs: uuid4
|
||||
@test uploader.storage === storage
|
||||
end
|
||||
|
||||
# --- put_file function (slash detection) ---
|
||||
|
||||
@testset "put_file function returns nothing for keys with slashes" begin
|
||||
storage = GarageStorage("https://s3-api.example.com", "key", "secret", "bucket")
|
||||
result = @test_logs (:warn, r"Upload aborted") put_file(storage, "a/b.json", "data")
|
||||
@test result === nothing
|
||||
end
|
||||
|
||||
@testset "put_file function returns nothing for keys with multiple slashes" begin
|
||||
storage = GarageStorage("https://s3-api.example.com", "key", "secret", "bucket")
|
||||
result = @test_logs (:warn, r"Upload aborted") put_file(storage, "a/b/c/d.json", "data")
|
||||
@test result === nothing
|
||||
end
|
||||
|
||||
@testset "put_file function returns nothing for key with single slash in middle" begin
|
||||
storage = GarageStorage("https://s3-api.example.com", "key", "secret", "bucket")
|
||||
result = @test_logs (:warn, r"Upload aborted") put_file(storage, "folder/file.json", "data")
|
||||
@test result === nothing
|
||||
end
|
||||
|
||||
@testset "put_file function returns nothing for key with trailing slash pattern" begin
|
||||
storage = GarageStorage("https://s3-api.example.com", "key", "secret", "bucket")
|
||||
result = @test_logs (:warn, r"Upload aborted") put_file(storage, "a/b", "data")
|
||||
@test result === nothing
|
||||
end
|
||||
|
||||
# --- Integration tests with real Garage server ---
|
||||
|
||||
@testset "integration: full CRUD lifecycle" begin
|
||||
@@ -219,15 +186,92 @@ using UUIDs: uuid4
|
||||
@test deleted_data2 === nothing
|
||||
end
|
||||
|
||||
@testset "integration: put_file rejects slashes even with real server" begin
|
||||
@testset "integration: nested key CRUD - single level" begin
|
||||
storage = GarageStorage(
|
||||
"https://s3-api.yiem.cc",
|
||||
"GKb080154a2e5b19100b1b2c6e",
|
||||
"a2c6b1379c2f731d3e6e5a408dd4d6cffca7511717675f55114ff94828febca1",
|
||||
"testbucket"
|
||||
)
|
||||
result = @test_logs (:warn, r"Upload aborted") put_file(storage, "folder/test.json", "data")
|
||||
@test result === nothing
|
||||
|
||||
test_key = "single/slash/test-$(randstring(8)).json"
|
||||
test_data = "{\"level\": 1, \"nested\": true}"
|
||||
|
||||
# Upload nested key
|
||||
result = put_file(storage, test_key, test_data)
|
||||
@test result isa NamedTuple
|
||||
@test haskey(result, :api)
|
||||
@test haskey(result, :web)
|
||||
@test occursin("single/slash/", result.api)
|
||||
@test occursin("single/slash/", result.web)
|
||||
|
||||
# Download and verify
|
||||
downloaded = get_file(storage, test_key)
|
||||
@test downloaded !== nothing
|
||||
@test String(downloaded) == test_data
|
||||
|
||||
# Verify in listing
|
||||
keys = list_files(storage)
|
||||
@test test_key in keys
|
||||
|
||||
# Delete and verify gone
|
||||
delete_file(storage, test_key)
|
||||
@test get_file(storage, test_key) === nothing
|
||||
end
|
||||
|
||||
@testset "integration: nested key CRUD - multi level" begin
|
||||
storage = GarageStorage(
|
||||
"https://s3-api.yiem.cc",
|
||||
"GKb080154a2e5b19100b1b2c6e",
|
||||
"a2c6b1379c2f731d3e6e5a408dd4d6cffca7511717675f55114ff94828febca1",
|
||||
"testbucket"
|
||||
)
|
||||
|
||||
test_key = "deep/nested/folder/subfolder/test-$(randstring(8)).json"
|
||||
test_data = "{\"deeply\": \"nested\", \"path\": \"deep/nested/folder/subfolder/\"}"
|
||||
|
||||
# Upload deeply nested key
|
||||
result = put_file(storage, test_key, test_data)
|
||||
@test result isa NamedTuple
|
||||
@test occursin("deep/nested/folder/subfolder/", result.api)
|
||||
@test occursin("s3-api", result.api)
|
||||
@test occursin("s3-web", result.web)
|
||||
|
||||
# Download and verify
|
||||
downloaded = get_file(storage, test_key)
|
||||
@test downloaded !== nothing
|
||||
@test String(downloaded) == test_data
|
||||
|
||||
# Verify in listing
|
||||
keys = list_files(storage)
|
||||
@test test_key in keys
|
||||
|
||||
# Delete and verify gone
|
||||
delete_file(storage, test_key)
|
||||
@test get_file(storage, test_key) === nothing
|
||||
end
|
||||
|
||||
@testset "integration: nested key with callable struct" begin
|
||||
storage = GarageStorage(
|
||||
"https://s3-api.yiem.cc",
|
||||
"GKb080154a2e5b19100b1b2c6e",
|
||||
"a2c6b1379c2f731d3e6e5a408dd4d6cffca7511717675f55114ff94828febca1",
|
||||
"testbucket"
|
||||
)
|
||||
|
||||
test_key = "callable/nested/test-$(randstring(8)).json"
|
||||
test_data = "{\"callable\": true, \"nested\": true}"
|
||||
|
||||
uploader = put_file(storage)
|
||||
result = uploader(test_key, test_data)
|
||||
@test result isa NamedTuple
|
||||
@test occursin("callable/nested/", result.api)
|
||||
|
||||
downloaded = get_file(storage, test_key)
|
||||
@test String(downloaded) == test_data
|
||||
|
||||
delete_file(storage, test_key)
|
||||
@test get_file(storage, test_key) === nothing
|
||||
end
|
||||
|
||||
@testset "integration: get_file returns nothing for missing key" begin
|
||||
|
||||
Reference in New Issue
Block a user