Skip to content

Commit b4f34af

Browse files
Christian Comptonrolivieri
authored andcommitted
complete test coverage (#92)
* complete test coverage * complete test coverage * complete test coverage
1 parent 981c316 commit b4f34af

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

spec/app_management/initial_startup_spec.rb

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module InitialStartup
5656
end
5757
end
5858

59-
describe '#run' do
59+
describe '#run' do
6060
context 'there are no handlers' do
6161
it 'returns nil' do
6262
expect(run(app_dir, {}, false)).to be_nil
@@ -171,6 +171,58 @@ module InitialStartup
171171
end
172172
end
173173

174+
describe '#startup_with_handlers' do
175+
context 'proxy is required' do
176+
context 'it is not the first index' do
177+
before do
178+
ENV['VCAP_APPLICATION'] = {"instance_index": 1}.to_json
179+
end
180+
181+
it 'calls start_runtime' do
182+
allow_any_instance_of(Object).to receive(:handler_list).and_return(%w[handler1 handler2])
183+
allow_any_instance_of(Utils::Handlers).to receive(:proxy_required?).and_return(true)
184+
allow_any_instance_of(Object).to receive(:start_runtime).with(anything)
185+
expect_any_instance_of(Object).to receive(:start_runtime).with(app_dir)
186+
startup_with_handlers(app_dir)
187+
end
188+
189+
after do
190+
ENV['VCAP_APPLICATION'] = nil
191+
end
192+
end
193+
194+
context 'it is the first index' do
195+
before do
196+
ENV['VCAP_APPLICATION'] = {"instance_index": 0}.to_json
197+
end
198+
199+
it 'calls run_handlers, write_json, and start_proxy' do
200+
allow_any_instance_of(Object).to receive(:handler_list).and_return(%w[handler1 handler2])
201+
allow_any_instance_of(Utils::Handlers).to receive(:proxy_required?).and_return(true)
202+
expect_any_instance_of(Object).to receive(:run_handlers)
203+
expect_any_instance_of(Object).to receive(:write_json)
204+
expect_any_instance_of(Object).to receive(:start_proxy)
205+
startup_with_handlers(app_dir)
206+
end
207+
208+
after do
209+
ENV['VCAP_APPLICATION'] = nil
210+
end
211+
212+
end
213+
end
214+
215+
context 'proxy not required' do
216+
it 'calls run_handlers and start_runtime' do
217+
allow_any_instance_of(Object).to receive(:handler_list).and_return(%w[handler1 handler2])
218+
allow_any_instance_of(Utils::Handlers).to receive(:proxy_required?).and_return(false)
219+
allow_any_instance_of(Object).to receive(:start_runtime).with(anything)
220+
expect_any_instance_of(Object).to receive(:start_runtime).with(app_dir)
221+
startup_with_handlers(app_dir)
222+
end
223+
end
224+
end
225+
174226
describe '#startup' do
175227
context 'handler_list is nil' do
176228
it 'calls start_runtime and not startup_with_handlers' do

spec/app_management/utils/droplet_utils_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'spec_helper'
33
require 'rspec'
44
require 'tmpdir'
5+
require 'timeout'
56
require 'socket'
67
require_relative '../../../app_management/utils/droplet_utils.rb'
78

@@ -29,6 +30,13 @@
2930
s.close
3031
end
3132
end
33+
34+
context 'there is a timeout error' do
35+
it 'returns false' do
36+
allow(Timeout).to receive(:timeout).and_raise(Timeout::Error)
37+
expect(DropletUtils.port_bound?(server_port)).not_to be_truthy
38+
end
39+
end
3240
end
3341

3442
describe '#find_port' do

0 commit comments

Comments
 (0)