Skip to content

Commit 8c8c630

Browse files
committed
adapt tests
1 parent d4ca4ba commit 8c8c630

File tree

5 files changed

+58
-29
lines changed

5 files changed

+58
-29
lines changed

lib/cloud_controller/blobstore/storage_cli/storage_cli_client.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@ def initialize(connection_config:, directory_key:, resource_type:, root_dir:, mi
5959

6060
begin
6161
VCAP::CloudController::YAMLConfig.safe_load_file(file_path)
62-
rescue => e
62+
rescue StandardError => e
6363
raise BlobstoreError.new("Failed to load storage-cli config at #{file_path}: #{e.message}")
6464
end
6565

6666
@config_file = file_path
6767
logger.info('storage_cli_config_selected', resource_type: @resource_type, path: @config_file)
68-
6968
end
7069

7170
def local?

spec/unit/lib/cloud_controller/blobstore/client_provider_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ module Blobstore
140140
it 'provides a storage-cli client' do
141141
allow(StorageCliClient).to receive(:build).and_return(storage_cli_client_mock)
142142
ClientProvider.provide(options:, directory_key:, root_dir:, resource_type:)
143-
expect(StorageCliClient).to have_received(:build).with(connection_config: {}, directory_key: directory_key, resource_type: resource_type, root_dir: root_dir, min_size: 100, max_size: 1000)
143+
expect(StorageCliClient).to have_received(:build).with(connection_config: {}, directory_key: directory_key, resource_type: resource_type, root_dir: root_dir,
144+
min_size: 100, max_size: 1000)
144145
end
145146

146147
it 'raises an error if connection_config is not provided' do

spec/unit/lib/cloud_controller/blobstore/storage_cli/azure_storage_cli_client_spec.rb

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,44 @@
11
require 'spec_helper'
2+
require 'tempfile'
3+
require 'json'
24
require_relative '../client_shared'
35
require 'cloud_controller/blobstore/storage_cli/azure_storage_cli_client'
46
require 'cloud_controller/blobstore/storage_cli/storage_cli_blob'
57

68
module CloudController
79
module Blobstore
810
RSpec.describe AzureStorageCliClient do
9-
subject(:client) { AzureStorageCliClient.new(connection_config: connection_config, directory_key: directory_key, root_dir: 'bommel') }
11+
let!(:tmp_cfg) do
12+
f = Tempfile.new(['storage_cli_config', '.json'])
13+
f.write({ provider: 'AzureRM',
14+
account_name: 'some-account-name',
15+
account_key: 'some-access-key',
16+
container_name: directory_key,
17+
environment: 'AzureCloud' }.to_json)
18+
f.flush
19+
f
20+
end
21+
22+
before do
23+
cc_cfg = instance_double(VCAP::CloudController::Config)
24+
allow(VCAP::CloudController::Config).to receive(:config).and_return(cc_cfg)
25+
26+
allow(cc_cfg).to receive(:get) do |key, *_|
27+
case key
28+
when :storage_cli_config_file_droplets,
29+
:storage_cli_config_file_buildpacks,
30+
:storage_cli_config_file_packages,
31+
:storage_cli_config_file_resource_pool
32+
tmp_cfg.path
33+
end
34+
end
35+
end
36+
37+
after { tmp_cfg.close! }
38+
39+
subject(:client) { AzureStorageCliClient.new(connection_config: connection_config, directory_key: directory_key, resource_type: resource_type, root_dir: 'bommel') }
1040
let(:directory_key) { 'my-bucket' }
41+
let(:resource_type) { 'resource_pool' }
1142
let(:connection_config) do
1243
{
1344
azure_storage_access_key: 'some-access-key',
@@ -59,7 +90,7 @@ module Blobstore
5990
expect(client.instance_variable_get(:@config_file)).to be_a(String)
6091
expect(File.exist?(client.instance_variable_get(:@config_file))).to be true
6192
expect(File.read(client.instance_variable_get(:@config_file))).to eq(
62-
'{"account_name":"some-account-name","account_key":"some-access-key","container_name":"my-bucket","environment":"AzureCloud"}'
93+
'{"provider":"AzureRM","account_name":"some-account-name","account_key":"some-access-key","container_name":"my-bucket","environment":"AzureCloud"}'
6394
)
6495
end
6596
end

spec/unit/lib/cloud_controller/blobstore/storage_cli/storage_cli_client_spec.rb

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module CloudController
55
module Blobstore
66
RSpec.describe StorageCliClient do
77
describe 'registry build and lookup' do
8-
98
it 'builds the correct client' do
109
droplets_cfg = Tempfile.new(['droplets', '.json'])
1110
droplets_cfg.write({ connection_config: { provider: 'AzureRM' } }.to_json)
@@ -57,8 +56,6 @@ module Blobstore
5756
when :storage_cli_config_file_buildpacks then buildpacks_cfg.path
5857
when :storage_cli_config_file_packages then packages_cfg.path
5958
when :storage_cli_config_file_resource_pool then resource_pool_cfg.path
60-
else
61-
nil
6259
end
6360
end
6461

@@ -70,12 +67,12 @@ module Blobstore
7067
[droplets_cfg, buildpacks_cfg, packages_cfg, resource_pool_cfg].each(&:close!)
7168
end
7269

73-
def build_client(rt)
70+
def build_client(resource_type)
7471
StorageCliClient.build(
7572
connection_config: { provider: 'AzureRM' },
7673
directory_key: 'dir-key',
7774
root_dir: 'root',
78-
resource_type: rt
75+
resource_type: resource_type
7976
)
8077
end
8178

@@ -110,23 +107,23 @@ def build_client(rt)
110107
end
111108

112109
it 'raises for unknown resource_type' do
113-
expect {
110+
expect do
114111
build_client('nope')
115-
}.to raise_error(CloudController::Blobstore::BlobstoreError, /Unknown resource_type: nope/)
112+
end.to raise_error(CloudController::Blobstore::BlobstoreError, /Unknown resource_type: nope/)
116113
end
117114

118115
it 'raises when file missing/unreadable' do
119116
allow(config_double).to receive(:get).with(:storage_cli_config_file_packages).and_return('/no/such/file.json')
120-
expect {
117+
expect do
121118
build_client('packages')
122-
}.to raise_error(CloudController::Blobstore::BlobstoreError, /not found or not readable/)
119+
end.to raise_error(CloudController::Blobstore::BlobstoreError, /not found or not readable/)
123120
end
124121

125122
it 'raises when YAML load fails' do
126-
File.write(packages_cfg.path, "{ this is: [not, valid }")
127-
expect {
123+
File.write(packages_cfg.path, '{ this is: [not, valid }')
124+
expect do
128125
build_client('packages')
129-
}.to raise_error(CloudController::Blobstore::BlobstoreError, /Failed to load storage-cli config/)
126+
end.to raise_error(CloudController::Blobstore::BlobstoreError, /Failed to load storage-cli config/)
130127
end
131128
end
132129

@@ -157,30 +154,29 @@ def build_client(rt)
157154
end
158155

159156
it 'returns true on exitstatus 0' do
160-
expect(Open3).to receive(:capture3)
161-
.with(kind_of(String), '-c', droplets_cfg.path, 'exists', kind_of(String))
162-
.and_return(['', '', instance_double(Process::Status, success?: true, exitstatus: 0)])
157+
expect(Open3).to receive(:capture3).
158+
with(kind_of(String), '-c', droplets_cfg.path, 'exists', kind_of(String)).
159+
and_return(['', '', instance_double(Process::Status, success?: true, exitstatus: 0)])
163160

164161
expect(client.exists?('key')).to be true
165162
end
166163

167164
it 'returns false on exitstatus 3' do
168-
expect(Open3).to receive(:capture3)
169-
.with(kind_of(String), '-c', droplets_cfg.path, 'exists', kind_of(String))
170-
.and_return(['', '', instance_double(Process::Status, success?: false, exitstatus: 3)])
165+
expect(Open3).to receive(:capture3).
166+
with(kind_of(String), '-c', droplets_cfg.path, 'exists', kind_of(String)).
167+
and_return(['', '', instance_double(Process::Status, success?: false, exitstatus: 3)])
171168

172169
expect(client.exists?('key')).to be false
173170
end
174171

175172
it 'raises for other non-zero exit codes' do
176-
expect(Open3).to receive(:capture3)
177-
.with(kind_of(String), '-c', droplets_cfg.path, 'exists', kind_of(String))
178-
.and_return(['', 'boom', instance_double(Process::Status, success?: false, exitstatus: 2)])
173+
expect(Open3).to receive(:capture3).
174+
with(kind_of(String), '-c', droplets_cfg.path, 'exists', kind_of(String)).
175+
and_return(['', 'boom', instance_double(Process::Status, success?: false, exitstatus: 2)])
179176

180177
expect { client.exists?('key') }.to raise_error(/storage-cli exists failed/)
181178
end
182179
end
183-
184180
end
185181
end
186182
end

spec/unit/lib/cloud_controller/dependency_locator_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@
7777
it 'creates blob store' do
7878
expect(CloudController::Blobstore::ClientProvider).to receive(:provide).with(
7979
options: config.get(:resource_pool),
80-
directory_key: 'key'
80+
directory_key: 'key',
81+
resource_type: :resource_pool
8182
)
8283
locator.legacy_global_app_bits_cache
8384
end
@@ -97,7 +98,8 @@
9798
expect(CloudController::Blobstore::ClientProvider).to receive(:provide).with(
9899
options: config.get(:resource_pool),
99100
directory_key: 'key',
100-
root_dir: 'app_bits_cache'
101+
root_dir: 'app_bits_cache',
102+
resource_type: :resource_pool
101103
)
102104
locator.global_app_bits_cache
103105
end

0 commit comments

Comments
 (0)