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

Commit beb4e96

Browse files
v3: client can see a **link** to a domain's **router group**
* Will only show if router group is set and the routing API is not disabled [#172547117] Co-authored-by: Belinda Liu <bliu@pivotal.io>
1 parent 965c397 commit beb4e96

3 files changed

Lines changed: 42 additions & 20 deletions

File tree

app/presenters/v3/domain_presenter.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ def build_links
8181
}
8282
end
8383

84+
routing_client = CloudController::DependencyLocator.instance.routing_api_client
85+
if domain.router_group_guid && routing_client.enabled?
86+
links[:router_group] = {
87+
href: url_builder.build_url(path: "/routing/v1/router_groups/#{domain.router_group_guid}")
88+
}
89+
end
90+
8491
links
8592
end
8693
end

spec/request/domains_spec.rb

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -752,27 +752,28 @@
752752

753753
let(:domain_json) do
754754
{
755-
guid: UUID_REGEX,
756-
created_at: iso8601,
757-
updated_at: iso8601,
758-
name: params[:name],
759-
internal: false,
760-
router_group: { guid: 'some-router-guid' },
761-
metadata: {
762-
labels: { key: 'value' },
763-
annotations: { key2: 'value2' }
764-
},
765-
relationships: {
766-
organization: {
767-
data: nil
755+
guid: UUID_REGEX,
756+
created_at: iso8601,
757+
updated_at: iso8601,
758+
name: params[:name],
759+
internal: false,
760+
router_group: { guid: 'some-router-guid' },
761+
metadata: {
762+
labels: { key: 'value' },
763+
annotations: { key2: 'value2' }
768764
},
769-
shared_organizations: {
770-
data: []
771-
}
772-
},
773-
links: {
774-
self: { href: %r(#{Regexp.escape(link_prefix)}\/v3\/domains\/#{UUID_REGEX}) },
775-
route_reservations: { href: %r(#{Regexp.escape(link_prefix)}\/v3/domains/#{UUID_REGEX}/route_reservations) },
765+
relationships: {
766+
organization: {
767+
data: nil
768+
},
769+
shared_organizations: {
770+
data: []
771+
}
772+
},
773+
links: {
774+
self: { href: %r(#{Regexp.escape(link_prefix)}/v3/domains/#{UUID_REGEX}) },
775+
route_reservations: { href: %r(#{Regexp.escape(link_prefix)}/v3/domains/#{UUID_REGEX}/route_reservations) },
776+
router_group: { href: %r(#{Regexp.escape(link_prefix)}/routing/v1/router_groups/some-router-guid) },
776777
}
777778
}
778779
end

spec/unit/presenters/v3/domain_presenter_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,22 @@ module VCAP::CloudController::Presenters::V3
172172
expect(subject[:links][:self][:href]).to eq("#{link_prefix}/v3/domains/#{domain.guid}")
173173
expect(subject[:links][:organization][:href]).to eq("#{link_prefix}/v3/organizations/#{domain.owning_organization.guid}")
174174
expect(subject[:links][:route_reservations][:href]).to eq("#{link_prefix}/v3/domains/#{domain.guid}/route_reservations")
175+
expect(subject[:links][:router_group][:href]).to eq("#{link_prefix}/routing/v1/router_groups/some-router-guid")
175176
expect(subject[:links][:shared_organizations][:href]).to eq("#{link_prefix}/v3/domains/#{domain.guid}/relationships/shared_organizations")
176177
end
178+
179+
context 'and the routing API is disabled' do
180+
let(:routing_api_client) { instance_double(VCAP::CloudController::RoutingApi::Client) }
181+
182+
before do
183+
allow(VCAP::CloudController::RoutingApi::Client).to receive(:new).and_return(routing_api_client)
184+
allow(routing_api_client).to receive(:enabled?).and_return false
185+
end
186+
187+
it 'does not include a link to the router group' do
188+
expect(subject[:links][:router_group]).to eq(nil)
189+
end
190+
end
177191
end
178192
end
179193
end

0 commit comments

Comments
 (0)