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

Commit 6d7473f

Browse files
Fix domain presenter tests
- add missing unit test - fix incorrect test setup - fix bug with string checking [#172512289] Co-authored-by: Sarah Weinstein <sweinstein@pivotal.io> Co-authored-by: Belinda Liu <bliu@pivotal.io>
1 parent 95c2901 commit 6d7473f

3 files changed

Lines changed: 15 additions & 18 deletions

File tree

app/models/runtime/domain.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def protocols
147147
return ['http'] if self.private?
148148

149149
# If Kubernetes is enabled that implies that we are using istio, not the routing API
150-
k8s_enabled = !!Config.config.get(:kubernetes, :host_url)
150+
k8s_enabled = Config.config.get(:kubernetes, :host_url).present?
151151
return ['tcp'] if !k8s_enabled && self.router_group_guid
152152

153153
['http']

app/presenters/v3/domain_presenter.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ def domain
5959
@resource
6060
end
6161

62-
# def protocols
63-
# # If Kubernetes is enabled that implies that we are using istio
64-
# k8s_enabled = !VCAP::CloudController::Config.config.get(:kubernetes, :host_url).blank?
65-
# return ['tcp'] if !k8s_enabled && domain.router_group_guid
66-
67-
# return ['http']
68-
# end
69-
7062
def hashified_router_group(router_group_guid)
7163
router_group_guid ? { guid: router_group_guid } : nil
7264
end

spec/unit/presenters/v3/domain_presenter_spec.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,14 @@ module VCAP::CloudController::Presenters::V3
139139
allow(VCAP::CloudController::Config).to receive_message_chain(:config, :get).with(:kubernetes, :host_url).and_return(nil)
140140
allow(VCAP::CloudController::Config).to receive_message_chain(:config, :get).with(:external_domain).and_return('api2.vcap.me')
141141
allow(VCAP::CloudController::Config).to receive_message_chain(:config, :get).with(:external_protocol).and_return('https')
142+
allow(CloudController::DependencyLocator).to receive_message_chain(:instance, :routing_api_client).and_return(routing_api_client)
143+
allow(routing_api_client).to receive(:enabled?).and_return(true)
142144
end
143145

146+
let(:routing_api_client) { instance_double(VCAP::CloudController::RoutingApi::Client) }
144147
let(:org) { VCAP::CloudController::Organization.make(guid: 'org') }
145148
let(:domain) do
146-
VCAP::CloudController::PrivateDomain.make(
149+
VCAP::CloudController::SharedDomain.make(
147150
name: 'my.domain.com',
148151
router_group_guid: 'some-router-guid'
149152
)
@@ -175,14 +178,9 @@ module VCAP::CloudController::Presenters::V3
175178
expect(subject[:supported_protocols]).to eq(['tcp'])
176179
expect(subject[:metadata][:labels]).to eq({ 'maine.gov/potato' => 'mashed' })
177180
expect(subject[:metadata][:annotations]).to eq({ 'contacts' => 'Bill tel(1111111) email(bill@fixme), Bob tel(222222) pager(3333333#555) email(bob@fixme)' })
178-
expect(subject[:relationships][:organization]).to eq({
179-
data: { guid: domain.owning_organization.guid }
180-
})
181181
expect(subject[:links][:self][:href]).to eq("https://api2.vcap.me/v3/domains/#{domain.guid}")
182-
expect(subject[:links][:organization][:href]).to eq("https://api2.vcap.me/v3/organizations/#{domain.owning_organization.guid}")
183182
expect(subject[:links][:route_reservations][:href]).to eq("https://api2.vcap.me/v3/domains/#{domain.guid}/route_reservations")
184183
expect(subject[:links][:router_group][:href]).to eq('https://api2.vcap.me/routing/v1/router_groups/some-router-guid')
185-
expect(subject[:links][:shared_organizations][:href]).to eq("https://api2.vcap.me/v3/domains/#{domain.guid}/relationships/shared_organizations")
186184
end
187185

188186
context 'when the kubernetes host url is blank' do
@@ -205,11 +203,18 @@ module VCAP::CloudController::Presenters::V3
205203
end
206204
end
207205

208-
context 'and the routing API is disabled' do
209-
let(:routing_api_client) { instance_double(VCAP::CloudController::RoutingApi::Client) }
206+
context 'when kubernetes is enabled (not using routing API)' do
207+
before do
208+
allow(VCAP::CloudController::Config).to receive_message_chain(:config, :get).with(:kubernetes, :host_url).and_return('kube.com')
209+
end
210+
211+
it 'shows the http protocol' do
212+
expect(subject[:supported_protocols]).to eq(['http'])
213+
end
214+
end
210215

216+
context 'and the routing API is disabled' do
211217
before do
212-
allow(VCAP::CloudController::RoutingApi::Client).to receive(:new).and_return(routing_api_client)
213218
allow(routing_api_client).to receive(:enabled?).and_return false
214219
end
215220

0 commit comments

Comments
 (0)