@@ -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
0 commit comments