From 8d500d165d9797c19ecdec96fa76f8e4a3a3bba8 Mon Sep 17 00:00:00 2001 From: Ivan Giuliani Date: Wed, 12 Apr 2023 09:13:56 +0100 Subject: [PATCH] Add tests for large file downloads via the streaming interface --- spec/bucket_store_integration_spec.rb | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/spec/bucket_store_integration_spec.rb b/spec/bucket_store_integration_spec.rb index 78d5193..41b9bf8 100644 --- a/spec/bucket_store_integration_spec.rb +++ b/spec/bucket_store_integration_spec.rb @@ -36,6 +36,10 @@ end end + it "returns an empty bucket when no files are uploaded" do + expect(described_class.for(base_bucket_uri.to_s).list.to_a.size).to eq(0) + end + it "has a consistent interface" do # Write 201 files file_list = [] @@ -79,9 +83,27 @@ end expect(described_class.for(base_bucket_uri.to_s).list.to_a.size).to eq(0) end + + context "using the streaming interface" do + it "supports large file downloads" do + # Upload a large file + large_file_content = "Z" * 1024 * 1024 * 10 # 10Mb + described_class. + for("#{base_bucket_uri}/large.txt"). + upload!(large_file_content) + + # Streaming downloads should return a chunked response + rebuilt_large_file = + described_class.for("#{base_bucket_uri}/large.txt"). + stream. + download. + map { |_meta, chunk| chunk }. + join + expect(rebuilt_large_file).to eq(large_file_content) + end + end end - # We don't test GCS as there's no sensible way of running a local simulator include_examples "adapter integration", "inmemory://bucket" include_examples "adapter integration", "disk://bucket" include_examples "adapter integration", "s3://bucket"