Skip to content

Commit

Permalink
Include the base bucket uri in the context name
Browse files Browse the repository at this point in the history
  • Loading branch information
ivgiuliani committed Apr 12, 2023
1 parent 3b1aae0 commit 3a2b09e
Showing 1 changed file with 47 additions and 45 deletions.
92 changes: 47 additions & 45 deletions spec/bucket_store_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3a2b09e

Please sign in to comment.