Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 532b4bd

Browse files
authored
v3(services): Backfilled request tests for sharing service instance (cloudfoundry#1792)
- Creating request tests for SI sharing - Fix unshare SI request tests - reorder sharing service instances tests
1 parent a93f778 commit 532b4bd

6 files changed

Lines changed: 580 additions & 767 deletions

File tree

app/actions/service_instance_share.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,31 @@ def validate_plan_is_active!(service_instance)
4747

4848
def validate_plan_visibility!(service_instance, space)
4949
unless service_instance.service_plan.visible_in_space?(space)
50-
error_msg = "Access to service #{service_instance.service.label} and plan #{service_instance.service_plan.name} is not enabled in #{space.organization.name}/#{space.name}"
50+
error_msg = "Access to service #{service_instance.service.label} and plan #{service_instance.service_plan.name} is not enabled in #{space.organization.name}/#{space.name}."
5151
error!(error_msg)
5252
end
5353
end
5454

5555
def validate_name_uniqueness!(service_instance, space)
5656
if space.service_instances.map(&:name).include?(service_instance.name)
57-
error_msg = "A service instance called #{service_instance.name} already exists in #{space.name}"
57+
error_msg = "A service instance called #{service_instance.name} already exists in #{space.name}."
5858
error!(error_msg)
5959
end
6060
end
6161

6262
def validate_not_sharing_to_self!(service_instance, spaces)
6363
if spaces.include?(service_instance.space)
64-
error!('Service instances cannot be shared into the space where they were created')
64+
error!('Service instances cannot be shared into the space where they were created.')
6565
end
6666
end
6767

6868
def validate_supported_service_type!(service_instance)
6969
if service_instance.route_service?
70-
error!('Route services cannot be shared')
70+
error!('Route services cannot be shared.')
7171
end
7272

7373
unless service_instance.managed_instance?
74-
error!('User-provided services cannot be shared')
74+
error!('User-provided services cannot be shared.')
7575
end
7676
end
7777

app/controllers/v3/service_instances_controller.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,18 @@ def destroy
126126
def share_service_instance
127127
FeatureFlag.raise_unless_enabled!(:service_instance_sharing)
128128

129-
service_instance = ServiceInstance.first(guid: hashed_params[:service_instance_guid])
130-
129+
service_instance = ServiceInstance.first(guid: hashed_params[:guid])
131130
resource_not_found!(:service_instance) unless service_instance && can_read_service_instance?(service_instance)
132131
unauthorized! unless can_write_space?(service_instance.space)
133132

134133
message = VCAP::CloudController::ToManyRelationshipMessage.new(hashed_params[:body])
135134
unprocessable!(message.errors.full_messages) unless message.valid?
136135

137-
spaces = Space.where(guid: message.guids)
138-
check_spaces_exist_and_are_writeable!(service_instance, message.guids, spaces)
136+
target_spaces = Space.where(guid: message.guids)
137+
check_spaces_exist_and_are_writeable!(service_instance, message.guids, target_spaces)
139138

140139
share = ServiceInstanceShare.new
141-
share.create(service_instance, spaces, user_audit_info)
140+
share.create(service_instance, target_spaces, user_audit_info)
142141

143142
render status: :ok, json: Presenters::V3::ToManyRelationshipPresenter.new(
144143
"service_instances/#{service_instance.guid}", service_instance.shared_spaces, 'shared_spaces', build_related: false)
@@ -147,7 +146,7 @@ def share_service_instance
147146
end
148147

149148
def unshare_service_instance
150-
service_instance = ServiceInstance.first(guid: hashed_params[:service_instance_guid])
149+
service_instance = ServiceInstance.first(guid: hashed_params[:guid])
151150

152151
resource_not_found!(:service_instance) unless service_instance && can_read_service_instance?(service_instance)
153152
unauthorized! unless can_write_space?(service_instance.space)
@@ -168,7 +167,7 @@ def unshare_service_instance
168167
end
169168

170169
def relationships_shared_spaces
171-
service_instance = ServiceInstance.first(guid: hashed_params[:service_instance_guid])
170+
service_instance = ServiceInstance.first(guid: hashed_params[:guid])
172171
resource_not_found!(:service_instance) unless service_instance && can_read_space?(service_instance.space)
173172

174173
message = SharedSpacesShowMessage.from_params(query_params)

config/routes.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,15 @@
222222
# service_instances
223223
get '/service_instances', to: 'service_instances_v3#index'
224224
get '/service_instances/:guid', to: 'service_instances_v3#show'
225-
get '/service_instances/:service_instance_guid/relationships/shared_spaces', to: 'service_instances_v3#relationships_shared_spaces'
225+
get '/service_instances/:guid/relationships/shared_spaces', to: 'service_instances_v3#relationships_shared_spaces'
226226
get '/service_instances/:guid/relationships/shared_spaces/usage_summary', to: 'service_instances_v3#shared_spaces_usage_summary'
227227
get '/service_instances/:guid/credentials', to: 'service_instances_v3#credentials'
228228
get '/service_instances/:guid/parameters', to: 'service_instances_v3#parameters'
229229
post '/service_instances', to: 'service_instances_v3#create'
230-
post '/service_instances/:service_instance_guid/relationships/shared_spaces', to: 'service_instances_v3#share_service_instance'
230+
post '/service_instances/:guid/relationships/shared_spaces', to: 'service_instances_v3#share_service_instance'
231231
patch '/service_instances/:guid', to: 'service_instances_v3#update'
232232
delete '/service_instances/:guid', to: 'service_instances_v3#destroy'
233-
delete '/service_instances/:service_instance_guid/relationships/shared_spaces/:space_guid', to: 'service_instances_v3#unshare_service_instance'
233+
delete '/service_instances/:guid/relationships/shared_spaces/:space_guid', to: 'service_instances_v3#unshare_service_instance'
234234

235235
# space_features
236236
get '/spaces/:guid/features/:name', to: 'space_features#show'

0 commit comments

Comments
 (0)