From 3a2b09e0887a9a59aded4217b35e065b2c66eee1 Mon Sep 17 00:00:00 2001 From: Ivan Giuliani Date: Wed, 12 Apr 2023 10:17:42 +0100 Subject: [PATCH] Include the base bucket uri in the context name --- spec/bucket_store_integration_spec.rb | 92 ++++++++++++++------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/spec/bucket_store_integration_spec.rb b/spec/bucket_store_integration_spec.rb index b1d0d8f..0adfbaf 100644 --- a/spec/bucket_store_integration_spec.rb +++ b/spec/bucket_store_integration_spec.rb @@ -24,54 +24,56 @@ end shared_examples "adapter integration" do |base_bucket_uri| - before do - described_class.for(base_bucket_uri).list.each do |path| - described_class.for(path).delete! - end - end - - it "has a consistent interface" do - # Write 201 files - file_list = [] - 201.times do |i| - filename = "file#{(i + 1).to_s.rjust(3, '0')}.txt" - file_list << filename - - # the body of the file is the filename itself - described_class.for("#{base_bucket_uri}/prefix/#{filename}").upload!(filename) - end - - # Add some files with spaces - described_class.for("#{base_bucket_uri}/prefix/i have a space.txt"). - upload!("i have a space.txt") - described_class.for("#{base_bucket_uri}/prefix/another space.txt"). - upload!("another space.txt") - - file_list << "i have a space.txt" - file_list << "another space.txt" - - # List with prefix should only return the matching files - expect(described_class.for("#{base_bucket_uri}/prefix/file1").list.to_a.size).to eq(100) - expect(described_class.for("#{base_bucket_uri}/prefix/file2").list.to_a.size).to eq(2) - expect(described_class.for("#{base_bucket_uri}/prefix/").list.to_a.size).to eq(203) - - # List (without prefixes) should return everything - expect(described_class.for(base_bucket_uri.to_s).list.to_a). - to match_array(file_list.map { |filename| "#{base_bucket_uri}/prefix/#{filename}" }) - - # We know the content of the file, we can check `.download` returns it as expected - all_files = file_list.map do |filename| - [filename, "#{base_bucket_uri}/prefix/#{filename}"] - end - all_files.each do |content, key| - expect(described_class.for(key).download[:content]).to eq(content) + context "using #{base_bucket_uri}" do + before do + described_class.for(base_bucket_uri).list.each do |path| + described_class.for(path).delete! + end end - # Delete all the files, the bucket should be empty afterwards - described_class.for(base_bucket_uri.to_s).list.each do |key| - described_class.for(key).delete! + it "has a consistent interface" do + # Write 201 files + file_list = [] + 201.times do |i| + filename = "file#{(i + 1).to_s.rjust(3, '0')}.txt" + file_list << filename + + # the body of the file is the filename itself + described_class.for("#{base_bucket_uri}/prefix/#{filename}").upload!(filename) + end + + # Add some files with spaces + described_class.for("#{base_bucket_uri}/prefix/i have a space.txt"). + upload!("i have a space.txt") + described_class.for("#{base_bucket_uri}/prefix/another space.txt"). + upload!("another space.txt") + + file_list << "i have a space.txt" + file_list << "another space.txt" + + # List with prefix should only return the matching files + expect(described_class.for("#{base_bucket_uri}/prefix/file1").list.to_a.size).to eq(100) + expect(described_class.for("#{base_bucket_uri}/prefix/file2").list.to_a.size).to eq(2) + expect(described_class.for("#{base_bucket_uri}/prefix/").list.to_a.size).to eq(203) + + # List (without prefixes) should return everything + expect(described_class.for(base_bucket_uri.to_s).list.to_a). + to match_array(file_list.map { |filename| "#{base_bucket_uri}/prefix/#{filename}" }) + + # We know the content of the file, we can check `.download` returns it as expected + all_files = file_list.map do |filename| + [filename, "#{base_bucket_uri}/prefix/#{filename}"] + end + all_files.each do |content, key| + expect(described_class.for(key).download[:content]).to eq(content) + end + + # Delete all the files, the bucket should be empty afterwards + described_class.for(base_bucket_uri.to_s).list.each do |key| + described_class.for(key).delete! + end + expect(described_class.for(base_bucket_uri.to_s).list.to_a.size).to eq(0) end - expect(described_class.for(base_bucket_uri.to_s).list.to_a.size).to eq(0) end end