@@ -147,6 +147,98 @@ module VCAP::CloudController
147147 end
148148 end
149149
150+ context 'cnb apps' do
151+ let ( :buildpack ) { VCAP ::CloudController ::Buildpack . make }
152+ let ( :message ) { AppManifestMessage . create_from_yml ( { name : 'blah' } ) }
153+ let ( :app_update_message ) { message . app_update_message }
154+ let ( :app ) { AppModel . make ( :cnb ) }
155+
156+ before do
157+ TestConfig . override ( default_app_lifecycle : 'cnb' )
158+ end
159+
160+ context 'when the default_app_lifecycle is set and the the lifecycle is not specified' do
161+ it 'preserves the lifecycle' do
162+ app_apply_manifest . apply ( app . guid , message )
163+ expect ( AppUpdate ) . to have_received ( :new ) . with ( user_audit_info , manifest_triggered : true )
164+ expect ( app_update ) . to have_received ( :update ) .
165+ with ( app , app_update_message , instance_of ( AppCNBLifecycle ) )
166+ expect ( app . reload . lifecycle_type ) . to eq ( 'cnb' )
167+ end
168+ end
169+
170+ context 'when buildpack is specified' do
171+ let ( :message ) { AppManifestMessage . create_from_yml ( { name : 'blah' , buildpack : buildpack . name } ) }
172+
173+ it 'preserves the lifecycle' do
174+ app_apply_manifest . apply ( app . guid , message )
175+ expect ( AppUpdate ) . to have_received ( :new ) . with ( user_audit_info , manifest_triggered : true )
176+ expect ( app_update ) . to have_received ( :update ) .
177+ with ( app , app_update_message , instance_of ( AppCNBLifecycle ) )
178+ expect ( app . reload . lifecycle_type ) . to eq ( 'cnb' )
179+ end
180+ end
181+
182+ context 'when the default differs from what is already set on the app' do
183+ let ( :message ) { AppManifestMessage . create_from_yml ( { name : 'blah' , buildpack : buildpack . name } ) }
184+ let ( :app ) { AppModel . make ( :buildpack ) }
185+
186+ it 'preserves the apps lifecycle' do
187+ app_apply_manifest . apply ( app . guid , message )
188+ expect ( AppUpdate ) . to have_received ( :new ) . with ( user_audit_info , manifest_triggered : true )
189+ expect ( app_update ) . to have_received ( :update ) .
190+ with ( app , app_update_message , instance_of ( AppBuildpackLifecycle ) )
191+ expect ( app . reload . lifecycle_type ) . to eq ( 'buildpack' )
192+ end
193+ end
194+ end
195+
196+ context 'buildpack apps' do
197+ let ( :buildpack ) { VCAP ::CloudController ::Buildpack . make }
198+ let ( :message ) { AppManifestMessage . create_from_yml ( { name : 'blah' } ) }
199+ let ( :app_update_message ) { message . app_update_message }
200+ let ( :app ) { AppModel . make ( :buildpack ) }
201+
202+ before do
203+ TestConfig . override ( default_app_lifecycle : 'buildpack' )
204+ end
205+
206+ context 'when the default_app_lifecycle is set and the the lifecycle is not specified' do
207+ it 'preserves the lifecycle' do
208+ app_apply_manifest . apply ( app . guid , message )
209+ expect ( AppUpdate ) . to have_received ( :new ) . with ( user_audit_info , manifest_triggered : true )
210+ expect ( app_update ) . to have_received ( :update ) .
211+ with ( app , app_update_message , instance_of ( AppBuildpackLifecycle ) )
212+ expect ( app . reload . lifecycle_type ) . to eq ( 'buildpack' )
213+ end
214+ end
215+
216+ context 'when buildpack is specified' do
217+ let ( :message ) { AppManifestMessage . create_from_yml ( { name : 'blah' , buildpack : buildpack . name } ) }
218+
219+ it 'preserves the lifecycle' do
220+ app_apply_manifest . apply ( app . guid , message )
221+ expect ( AppUpdate ) . to have_received ( :new ) . with ( user_audit_info , manifest_triggered : true )
222+ expect ( app_update ) . to have_received ( :update ) .
223+ with ( app , app_update_message , instance_of ( AppBuildpackLifecycle ) )
224+ expect ( app . reload . lifecycle_type ) . to eq ( 'buildpack' )
225+ end
226+ end
227+
228+ context 'when the default differs from what is already set on the app' do
229+ let ( :message ) { AppManifestMessage . create_from_yml ( { name : 'blah' , buildpack : buildpack . name } ) }
230+ let ( :app ) { AppModel . make ( :cnb ) }
231+
232+ it 'preserves the apps lifecycle' do
233+ app_apply_manifest . apply ( app . guid , message )
234+ expect ( AppUpdate ) . to have_received ( :new ) . with ( user_audit_info , manifest_triggered : true )
235+ expect ( app_update ) . to have_received ( :update ) .
236+ with ( app , app_update_message , instance_of ( AppCNBLifecycle ) )
237+ expect ( app . reload . lifecycle_type ) . to eq ( 'cnb' )
238+ end
239+ end
240+ end
241+
150242 describe 'updating stack' do
151243 let ( :message ) { AppManifestMessage . create_from_yml ( { name : 'stack-test' , stack : 'cflinuxfs4' } ) }
152244 let ( :app_update_message ) { message . app_update_message }
0 commit comments