-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ad68aa
commit 688433a
Showing
11 changed files
with
310 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ tmp/ | |
|
||
.bundle/ | ||
.rspec_status | ||
.yardoc/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
require "file_storage/gcs" | ||
|
||
RSpec.describe FileStorage::Gcs do | ||
subject(:instance) { described_class.new(**gcs_config) } | ||
|
||
let(:bucket_name) { "bucket" } | ||
let(:gcs_config) do | ||
{ | ||
endpoint: "http://0.0.0.0:4443/", | ||
project_id: "test", | ||
} | ||
end | ||
|
||
let(:storage) do | ||
@storage = Google::Cloud::Storage.new(**gcs_config) | ||
end | ||
let(:test_bucket) { storage.bucket(bucket_name) } | ||
|
||
before do | ||
storage.create_bucket(bucket_name) | ||
end | ||
|
||
after do | ||
test_bucket.files.each(&:delete) | ||
test_bucket.delete | ||
end | ||
|
||
describe "#upload!" do | ||
subject(:upload!) do | ||
instance.upload!(bucket: bucket_name, key: "some-file.json", content: "something") | ||
end | ||
|
||
it "uploads the file" do | ||
expect { upload! }.to change { test_bucket.files.count }.from(0).to(1) | ||
end | ||
|
||
it "uploads the content" do | ||
upload! | ||
|
||
buffer = StringIO.new | ||
test_bucket.file("some-file.json").download(buffer) | ||
|
||
expect(buffer.string).to eq("something") | ||
end | ||
end | ||
|
||
describe "#download" do | ||
subject(:download) { instance.download(bucket: bucket_name, key: "some-file.json") } | ||
|
||
before do | ||
instance.upload!(bucket: bucket_name, key: "some-file.json", content: "something") | ||
end | ||
|
||
it "returns the correct information" do | ||
expect(download).to eq(bucket: bucket_name, key: "some-file.json", content: "something") | ||
end | ||
end | ||
|
||
describe "#list" do | ||
subject(:list) { instance.list(bucket: bucket_name, key: "", page_size: 1000) } | ||
|
||
before do | ||
instance.upload!(bucket: bucket_name, key: "some-file1.json", content: "something") | ||
instance.upload!(bucket: bucket_name, key: "some-file2.json", content: "something") | ||
end | ||
|
||
it "returns an enumerator" do | ||
expect(list.to_a).to eq([ | ||
{ bucket: bucket_name, keys: ["some-file1.json", "some-file2.json"] }, | ||
]) | ||
end | ||
end | ||
|
||
describe "#delete!" do | ||
subject(:delete!) { instance.delete!(bucket: bucket_name, key: "some-file.json") } | ||
|
||
before do | ||
instance.upload!(bucket: bucket_name, key: "some-file.json", content: "something") | ||
end | ||
|
||
it "deletes the file" do | ||
expect { delete! }.to change { test_bucket.files.count }.from(1).to(0) | ||
end | ||
end | ||
|
||
describe "#move!" do | ||
subject(:move!) do | ||
instance.move!( | ||
bucket: bucket_name, | ||
key: "some-file.json", | ||
new_bucket: bucket_2_name, | ||
new_key: "some-file-moved.json", | ||
) | ||
end | ||
|
||
let(:bucket_2_name) { "bucket-2" } | ||
let(:bucket_2) { storage.bucket(bucket_2_name) } | ||
|
||
before do | ||
storage.create_bucket(bucket_2_name) | ||
instance.upload!(bucket: bucket_name, key: "some-file.json", content: "something") | ||
end | ||
|
||
after do | ||
bucket_2.files.each(&:delete) | ||
bucket_2.delete | ||
end | ||
|
||
it "moves the file to the new directory" do | ||
move! | ||
|
||
expect(test_bucket.files.count).to eq(0) | ||
expect(bucket_2.file("some-file-moved.json")).to_not be_nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters