Skip to content

Commit

Permalink
Merge pull request #269 from j-asser/delete_object_empty_values
Browse files Browse the repository at this point in the history
Add empty value checks for delete_object
  • Loading branch information
bernardd authored Sep 10, 2024
2 parents aaa2a4d + d579a53 commit 4d9810f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/ex_aws/s3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,24 @@ defmodule ExAws.S3 do
@spec delete_object(bucket :: binary, object :: binary) :: ExAws.Operation.S3.t()
@spec delete_object(bucket :: binary, object :: binary, opts :: delete_object_opts) ::
ExAws.Operation.S3.t()
@spec delete_object(bucket :: binary, object :: nil) :: no_return
@request_headers [
:x_amz_mfa,
:x_amz_request_payer,
:x_amz_bypass_governance_retention,
:x_amz_expected_bucket_owner
]
def delete_object(bucket, object, opts \\ []) do
def delete_object(bucket, object, opts \\ [])

def delete_object(_bucket, nil = _object, _opts) do
raise "object must not be nil"
end

def delete_object(_bucket, "" = _object, _opts) do
raise "object must not be empty string"
end

def delete_object(bucket, object, opts) do
opts = opts |> Map.new()

params =
Expand Down
12 changes: 12 additions & 0 deletions test/lib/s3_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ defmodule ExAws.S3Test do
assert expected == S3.delete_object("bucket", "object")
end

test "#delete_object object must not be nil" do
assert_raise RuntimeError, "object must not be nil", fn ->
S3.delete_object("bucket", nil)
end
end

test "#delete_object object must not be empty string" do
assert_raise RuntimeError, "object must not be empty string", fn ->
S3.delete_object("bucket", "")
end
end

test "#delete_object version_id option" do
expected = %Operation.S3{
body: "",
Expand Down

0 comments on commit 4d9810f

Please sign in to comment.