|
|
@ -19,7 +19,7 @@ RSpec.describe StorageService do |
|
|
|
JSON |
|
|
|
JSON |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when we create an S3 Service with no PaaS Configuration present" do |
|
|
|
context "when we create a storage service with no PaaS Configuration present" do |
|
|
|
subject(:storage_service) { described_class.new(PaasConfigurationService.new, "random_instance") } |
|
|
|
subject(:storage_service) { described_class.new(PaasConfigurationService.new, "random_instance") } |
|
|
|
|
|
|
|
|
|
|
|
it "raises an exception" do |
|
|
|
it "raises an exception" do |
|
|
@ -27,7 +27,7 @@ RSpec.describe StorageService do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when we create an S3 Service with an unknown instance name" do |
|
|
|
context "when we create a storage service with an unknown instance name" do |
|
|
|
subject(:storage_service) { described_class.new(PaasConfigurationService.new, "random_instance") } |
|
|
|
subject(:storage_service) { described_class.new(PaasConfigurationService.new, "random_instance") } |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
@ -39,7 +39,7 @@ RSpec.describe StorageService do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when we create an storage service with a valid instance name" do |
|
|
|
context "when we create a storage service with a valid instance name" do |
|
|
|
subject(:storage_service) { described_class.new(PaasConfigurationService.new, instance_name) } |
|
|
|
subject(:storage_service) { described_class.new(PaasConfigurationService.new, instance_name) } |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
@ -64,7 +64,7 @@ RSpec.describe StorageService do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when we create an storage service and write a stubbed object" do |
|
|
|
context "when we create a storage service and write a stubbed object" do |
|
|
|
subject(:storage_service) { described_class.new(PaasConfigurationService.new, instance_name) } |
|
|
|
subject(:storage_service) { described_class.new(PaasConfigurationService.new, instance_name) } |
|
|
|
|
|
|
|
|
|
|
|
let(:filename) { "my_file" } |
|
|
|
let(:filename) { "my_file" } |
|
|
@ -98,4 +98,34 @@ RSpec.describe StorageService do |
|
|
|
storage_service.write_file(filename, content) |
|
|
|
storage_service.write_file(filename, content) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when we create a storage service and list files" do |
|
|
|
|
|
|
|
subject(:storage_service) { described_class.new(PaasConfigurationService.new, instance_name) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let(:s3_client_stub) { Aws::S3::Client.new(stub_responses: true) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
allow(ENV).to receive(:[]) |
|
|
|
|
|
|
|
allow(ENV).to receive(:[]).with("VCAP_SERVICES").and_return(vcap_services) |
|
|
|
|
|
|
|
allow(Aws::S3::Client).to receive(:new).and_return(s3_client_stub) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "returns a list with all present file names in a given folder" do |
|
|
|
|
|
|
|
expected_filenames = %w[my_folder/my_file1.xml my_folder/my_file2.xml] |
|
|
|
|
|
|
|
s3_client_stub.stub_responses(:list_objects_v2, { |
|
|
|
|
|
|
|
contents: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
key: expected_filenames[0], |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
key: expected_filenames[1], |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filenames = storage_service.list_files("my_folder") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(filenames).to eq(expected_filenames) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|