Skip to content

Commit 17ad24a

Browse files
committed
Clarify binding naming convention in error message
1 parent 6dbf2e5 commit 17ad24a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/cloud_controller/diego/service_binding_files_builder.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def build
2424
@service_bindings.select(&:create_succeeded?).each do |service_binding|
2525
sb_hash = ServiceBindingPresenter.new(service_binding, include_instance: true).to_hash
2626
name = sb_hash[:name]
27-
raise IncompatibleBindings.new("Invalid binding name: #{name}") unless valid_name?(name)
27+
raise IncompatibleBindings.new("Invalid binding name: '#{name}'. Name must match #{binding_naming_convention.inspect}") unless valid_name?(name)
2828
raise IncompatibleBindings.new("Duplicate binding name: #{name}") if names.add?(name).nil?
2929

3030
# add the credentials first
@@ -47,6 +47,10 @@ def build
4747

4848
private
4949

50+
def binding_naming_convention
51+
/^[a-z0-9\-.]{1,253}$/
52+
end
53+
5054
# - adds a Diego::Bbs::Models::File object to the service_binding_files hash
5155
# - binding name is used as the directory name, key is used as the file name
5256
# - returns the bytesize of the path and content
@@ -71,7 +75,7 @@ def add_file(service_binding_files, name, key, value)
7175
end
7276

7377
def valid_name?(name)
74-
name.match?(/^[a-z0-9\-.]{1,253}$/)
78+
name.match?(binding_naming_convention)
7579
end
7680

7781
def transform_vcap_services_attribute(name)

spec/unit/lib/cloud_controller/diego/service_binding_files_builder_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ module VCAP::CloudController::Diego
239239
let(:binding_name) { 'binding_name' }
240240

241241
it 'raises an exception' do
242-
expect { service_binding_files }.to raise_error(ServiceBindingFilesBuilder::IncompatibleBindings, 'Invalid binding name: binding_name')
242+
expect { service_binding_files }.to raise_error(ServiceBindingFilesBuilder::IncompatibleBindings, "Invalid binding name: 'binding_name'. Name must match /^[a-z0-9\\-.]{1,253}$/")
243243
end
244244
end
245245

0 commit comments

Comments
 (0)