Skip to content

Commit

Permalink
Enforce work count to default to 0 for new submissions (#1737)
Browse files Browse the repository at this point in the history
* Enforce work count to default to 0 for new submissions

Co-authored-by: Hector Correa <[email protected]>

* rubocop corrections

* Wrote the test for when there is no data for the key

Co-authored-by: Carolyn Cole <[email protected]>

* more rubocop cleanup

---------

Co-authored-by: Hector Correa <[email protected]>
Co-authored-by: Carolyn Cole <[email protected]>
Co-authored-by: Hector Correa <[email protected]>
  • Loading branch information
4 people authored Apr 5, 2024
1 parent d76dd78 commit 8ed3b97
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/services/s3_query_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,15 @@ def md5(io:)
def count_objects(bucket_name: self.bucket_name, prefix: self.prefix)
responses = s3_responses(bucket_name:, prefix:)
total_key_count = responses.reduce(0) { |total, resp| total + resp.key_count }
total_key_count - 1 # s3 always sends back the bucket key as the first response, so we should not count it
if total_key_count == 0
# if the bucket does not exist
# it will return 0
0
else
# if the bucket does exist
# s3 always sends back the bucket key as the first response, so we should not count it
total_key_count - 1
end
end

private
Expand Down
11 changes: 11 additions & 0 deletions spec/services/s3_query_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,17 @@
expect(s3_query_service.count_objects).to eq(7) # do not count the bucket the first time
end
end

context "an empty response" do
before do
fake_s3_resp.stub(:key_count).and_return(0)
fake_s3_resp.stub(:is_truncated).and_return(false)
end

it "returns all the objects" do
expect(s3_query_service.count_objects).to eq(0)
end
end
end
end

Expand Down

0 comments on commit 8ed3b97

Please sign in to comment.