Skip to content

Commit 731f1cd

Browse files
committed
Repair FakeStorage test stub for fog_client_spec
1 parent 698ab0e commit 731f1cd

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

spec/support/bootstrap/test_config.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,20 @@ def defaults
4646
nginx: { use_nginx: true },
4747
resource_pool: {
4848
resource_directory_key: 'spec-cc-resources',
49-
fog_connection: {}
49+
blobstore_type: 'local-temp-storage'
5050
},
5151
packages: {
5252
app_package_directory_key: 'cc-packages',
53-
fog_connection: {},
53+
blobstore_type: 'local-temp-storage',
5454
max_valid_packages_stored: 42
5555
},
5656
buildpacks: {
5757
buildpack_directory_key: 'cc-buildpacks',
58-
fog_connection: {}
58+
blobstore_type: 'local-temp-storage'
5959
},
6060
droplets: {
6161
droplet_directory_key: 'cc-droplets',
62-
fog_connection: {},
62+
blobstore_type: 'local-temp-storage',
6363
max_staged_droplets_stored: 42
6464
},
6565
db: DbConfig.new.config

spec/unit/lib/cloud_controller/blobstore/fog/fog_client_spec.rb

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Blobstore
99
class FakeStorage
1010
FakeFile = Struct.new(:key, :body, :content_type, :public, :content_length, :bucket, keyword_init: true) do
1111
def public_url = public ? "http://fake/#{key}" : nil
12+
def url(_expires) = "http://fake/#{key}"
1213

1314
def copy(dest_bucket, dest_key, _opts={})
1415
storage.store_file(dest_bucket, dest_key, body, content_type)
@@ -61,10 +62,10 @@ def create_bucket(key)
6162
class DirectoryProxy
6263
def initialize(storage) = @storage = storage
6364

64-
def get(key, **)
65+
def get(key, _options=nil, prefix: nil, **_kwargs)
6566
return nil unless @storage.bucket_exists?(key)
6667

67-
BucketProxy.new(@storage, key)
68+
BucketProxy.new(@storage, key, prefix:)
6869
end
6970

7071
def create(key:, **) = BucketProxy.new(@storage, @storage.create_bucket(key) && key)
@@ -74,23 +75,27 @@ def new(key:, **) = BucketProxy.new(@storage, key)
7475
class BucketProxy
7576
attr_reader :key
7677

77-
def initialize(storage, key)
78+
def initialize(storage, key, prefix: nil)
7879
@storage = storage
7980
@key = key
81+
@prefix = prefix
8082
@storage.create_bucket(key)
8183
end
8284

83-
def files = FilesProxy.new(@storage, @key)
85+
def files = FilesProxy.new(@storage, @key, prefix: @prefix)
8486
end
8587

8688
class FilesProxy
8789
include Enumerable
8890

89-
def initialize(storage, bucket)
91+
def initialize(storage, bucket, prefix: nil)
9092
@storage = storage
9193
@bucket = bucket
94+
@prefix = prefix
9295
end
9396

97+
def length = all.length
98+
9499
def head(key) = @storage.get_file(@bucket, key)
95100

96101
def get(key, &block)
@@ -105,12 +110,17 @@ def get(key, &block)
105110
file
106111
end
107112

108-
def create(key:, body:, content_type: 'application/zip', **)
113+
def create(options_or_key = nil, key: nil, body: nil, content_type: 'application/zip', **)
114+
if options_or_key.is_a?(Hash)
115+
key = options_or_key[:key]
116+
body = options_or_key[:body]
117+
content_type = options_or_key[:content_type] || 'application/zip'
118+
end
109119
@storage.store_file(@bucket, key, body, content_type)
110120
end
111121

112122
def each(&) = all.each(&)
113-
def all = @storage.list_files(@bucket)
123+
def all = @all ||= @storage.list_files(@bucket, prefix: @prefix)
114124

115125
def select(prefix: nil)
116126
@storage.list_files(@bucket, prefix:)
@@ -635,7 +645,7 @@ def upload_tmpfile(client, key='abcdef')
635645

636646
describe '#ensure_bucket_exists' do
637647
it 'gets the bucket' do
638-
expect(fake_storage.directories).to receive(:get).with(directory_key, max_keys: 1).and_call_original
648+
expect(fake_storage.directories).to receive(:get).with(directory_key, { max_keys: 1 }).and_call_original
639649
subject.ensure_bucket_exists
640650
end
641651

@@ -649,7 +659,7 @@ def upload_tmpfile(client, key='abcdef')
649659

650660
context 'the bucket does not exist' do
651661
it 'creates the bucket' do
652-
allow(fake_storage.directories).to receive(:get).with(directory_key, max_keys: 1).and_return(nil)
662+
allow(fake_storage.directories).to receive(:get).with(directory_key, { max_keys: 1 }).and_return(nil)
653663
expect(fake_storage.directories).to receive(:create).with(key: directory_key, public: false).and_call_original
654664
subject.ensure_bucket_exists
655665
end

0 commit comments

Comments
 (0)