Permalink
Browse files

List proxied services should return all service fields

 - Added some useful logging for debugging errors when
   registering service offering with CC
 - Unit test

Change-Id: I5a2dded532a2a3924f72c4cc6ec2935d92933f7a
  • Loading branch information...
1 parent 3d6883e commit 91a631bdf4035d849070534a42bbfe8a7c5f1ac1 Harshawardhan Gadgil committed Sep 8, 2012
@@ -71,14 +71,21 @@ def list
# Registers a new service offering with the CC
#
def create
- req = VCAP::Services::Api::ServiceOfferingRequest.decode(request_body)
- CloudController.logger.debug("Create service request: #{req.extract.inspect}")
+ CloudController.logger.debug("Create service request: #{request_body}")
+ req = nil
+ begin
+ req = VCAP::Services::Api::ServiceOfferingRequest.decode(request_body)
+ rescue => e
+ CloudController.logger.error("Failure decoding service offering request: #{e}")
+ raise e
+ end
# Should we worry about a race here?
success = nil
svc = Service.find_by_label_and_provider(req.label, req.provider == "core" ? nil : req.provider)
if svc
+ CloudController.logger.debug("Found svc = #{svc.inspect}")
raise CloudError.new(CloudError::FORBIDDEN) unless svc.verify_auth_token(@service_auth_token)
attrs = req.extract.dup
attrs.delete(:label)
@@ -107,6 +114,7 @@ def create
# register with us to get a token.
# or, it's a brokered service
svc = Service.new(req.extract)
+ CloudController.logger.debug("Attempt creating service: #{svc.inspect}")
if AppConfig[:service_proxy] and \
AppConfig[:service_proxy][:token].index(@service_auth_token) and \
!svc.is_builtin?
@@ -190,8 +198,7 @@ def list_proxied_services
result = Service.where(:token => @service_auth_token)
result = result.select { |svc| !svc.is_builtin? }
- result = result.map { |svc| {:label => svc.label, \
- :description => svc.description, :acls => svc.acls } }
+ result = result.map { |svc| svc.hash_to_service_offering }
render :json => {:proxied_services => result}
end
@@ -512,6 +512,41 @@
response.status.should == 200
Yajl::Parser.parse(response.body)['proxied_services'].size.should == 1
end
+
+ it "should return all non-null and mandatory fields for the service" do
+ AppConfig[:builtin_services] = {
+ :foo => {:token => ["foobar"]}
+ }
+ request.env['HTTP_X_VCAP_SERVICE_TOKEN'] = 'broker'
+ post_msg :create do
+ VCAP::Services::Api::ServiceOfferingRequest.new(
+ :label => 'brokered-1.0',
+ :url => 'http://localhost:56789',
+ :supported_versions => ["1.0" ],
+ :version_aliases => { "current" => "1.0" },
+ :provider => 'fooprovider',
+ )
+ end
+ response.status.should == 200
+
+ get :list_proxied_services
+ response.status.should == 200
+ services = Yajl::Parser.parse(response.body)['proxied_services']
+ services.size.should == 1
+
+ keys = %w(label url provider active supported_versions version_aliases)
+ keys.each { |k|
+ services[0].keys.include?(k).should == true
+ }
+
+ services[0]["label"].should == "brokered-1.0"
+ services[0]["provider"].should == "fooprovider"
+ services[0]["active"].should be_true
+ services[0]["url"].should == "http://localhost:56789"
+ services[0]["supported_versions"].size.should == 1
+ services[0]["supported_versions"][0].should == "1.0"
+ services[0]["version_aliases"]["current"].should == "1.0"
+ end
end
describe '#update_handle' do

0 comments on commit 91a631b

Please sign in to comment.