Skip to content

Commit

Permalink
Only return instances of core services
Browse files Browse the repository at this point in the history
  This patch makes the cc respond to legacy api
    GET /services
with only instances of services whose provider is "core".

Test plan: unit tests passed

Change-Id: I3fb11950187eab7b006edc61c1154b33b1f7d4c8
  • Loading branch information
d committed Jul 23, 2012
1 parent 2670127 commit ba343e6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/cloud_controller/api/service_instance.rb
Expand Up @@ -15,7 +15,7 @@ module VCAP::CloudController
to_one :service_plan
to_many :service_bindings
attribute :credentials, Hash
attribute :gateway_data, Hash, :default => "" # FIXME: notation for access override here
attribute :gateway_data, Hash, :default => {} # FIXME: notation for access override here
end

query_parameters :name, :space_guid, :service_plan_guid, :service_binding_guid
Expand Down
7 changes: 6 additions & 1 deletion lib/cloud_controller/legacy_api/legacy_services.rb
Expand Up @@ -18,7 +18,12 @@ def initialize(config, logger, request, service_auth_token = nil)
end

def enumerate
resp = default_space.service_instances.map do |svc_instance|
resp = default_space.service_instances_dataset.
# I want LINQ-style auto join on FK for this:
# filter { service.provider == "core" }.
join(:services, :id => :service_id).filter(:provider => DEFAULT_PROVIDER).
select_all(:service_instances).
map do |svc_instance|
legacy_service_encoding(svc_instance)
end

Expand Down
24 changes: 11 additions & 13 deletions spec/api/legacy_services_spec.rb
Expand Up @@ -74,51 +74,43 @@
:provider => "core",
:url => "http://localhost:56789",
)
svc1.save
svc1.should be_valid

svc2 = Models::Service.make(
:label => "foo-bar",
:provider => "test",
:url => "http://localhost:56789",
)
svc2.save
svc2.should be_valid

cfg1 = Models::ServiceInstance.make(
:gateway_name => "foo1",
:name => "bar1",
:service => svc1
)
cfg1.save
cfg1.should be_valid

cfg2 = Models::ServiceInstance.make(
:gateway_name => "foo2",
:name => "bar2",
:service => svc2
)
cfg2.save
cfg2.should be_valid

bdg1 = Models::ServiceBinding.make(
:gateway_name => "bind1",
:service_instance => cfg1,
:configuration => {},
:credentials => {},
:binding_options => []
)
bdg1.save
bdg1.should be_valid

bdg2 = Models::ServiceBinding.make(
:gateway_name => "bind2",
:service_instance => cfg2,
:configuration => {},
:credentials => {},
:binding_options => []
)
bdg2.save
bdg2.should be_valid

get "/services/v1/offerings/foo-bar/handles"
Expand All @@ -142,9 +134,15 @@

describe "GET /services" do
before do
@services = []
7.times do
@services << Models::ServiceInstance.make(:space => user.default_space)
core_service = Models::Service.make(:provider => "core")
@core = 3.times.map do
Models::ServiceInstance.make(
:space => user.default_space,
:service => core_service,
)
end
2.times do
Models::ServiceInstance.make(:space => user.default_space)
end

3.times do
Expand All @@ -164,12 +162,12 @@
end

it "should only return services for the default app space" do
decoded_response.length.should == 7
decoded_response.length.should == 3
end

it "should return service names" do
names = decoded_response.map { |a| a["name"] }.sort!
expected_names = @services.map { |a| a.name }.sort!
expected_names = @core.map { |a| a.name }.sort!
names.should == expected_names
end
end
Expand Down

0 comments on commit ba343e6

Please sign in to comment.