4646
4747 context 'when staging an app' do
4848 before do
49- allow ( VCAP ::CloudController ::Diego ::Buildpack ::LifecycleProtocol ) . to receive ( :new ) . and_return ( lifecycle_protocol )
50-
5149 stub_request ( :post , "#{ eirini_url } /stage/#{ staging_guid } " ) .
5250 to_return ( status : 202 )
5351 end
5452
5553 context 'when lifecycle type is buildpack' do
5654 let ( :lifecycle_type ) { VCAP ::CloudController ::Lifecycles ::BUILDPACK }
55+
56+ before do
57+ allow ( VCAP ::CloudController ::Diego ::Buildpack ::LifecycleProtocol ) . to receive ( :new ) . and_return ( lifecycle_protocol )
58+ end
59+
5760 it 'should send the expected request' do
5861 stager_client . stage ( staging_guid , staging_details )
5962 expect ( WebMock ) . to have_requested ( :post , "#{ eirini_url } /stage/#{ staging_guid } " ) . with ( body : {
6871 { name : 'MEMORY_LIMIT' , value : '256m' } ,
6972 { name : 'VCAP_SERVICES' , value : '{}' } ] ,
7073 completion_callback : 'https://internal_user:internal_password@api.internal.cf:8182/internal/v3/staging//build_completed?start=' ,
71- lifecycle_data : { droplet_upload_uri : "http://cc-uploader.service.cf.internal:9091/v1/droplet/#{ staging_guid } ?cc-droplet-upload-uri=http://upload.me" ,
72- app_bits_download_uri : 'http://download.me' ,
73- buildpacks : [ { name : 'ruby' , key : 'idk' , url : 'www.com' , skip_detect : false } ]
74+ lifecycle : {
75+ buildpack_lifecycle : {
76+ droplet_upload_uri : "http://cc-uploader.service.cf.internal:9091/v1/droplet/#{ staging_guid } ?cc-droplet-upload-uri=http://upload.me" ,
77+ app_bits_download_uri : 'http://download.me' ,
78+ buildpacks : [ { name : 'ruby' , key : 'idk' , url : 'www.com' , skip_detect : false } ]
79+ }
7480 } ,
7581 cpu_weight : VCAP ::CloudController ::Diego ::STAGING_TASK_CPU_WEIGHT ,
7682 disk_mb : 100 ,
99105 { name : 'MEMORY_LIMIT' , value : '256m' } ,
100106 { name : 'VCAP_SERVICES' , value : '{}' } ] ,
101107 completion_callback : 'https://internal_user:internal_password@api.internal.cf:8182/internal/v3/staging//build_completed?start=' ,
102- lifecycle_data : { droplet_upload_uri : "http://cc-uploader.service.cf.internal:9091/v1/droplet/#{ staging_guid } ?cc-droplet-upload-uri=http://upload.me" ,
103- app_bits_download_uri : 'http://download.me' ,
104- buildpacks : [ { name : 'ruby' , key : 'idk' , url : 'www.com' , skip_detect : false } ]
108+ lifecycle : {
109+ buildpack_lifecycle : {
110+ droplet_upload_uri : "http://cc-uploader.service.cf.internal:9091/v1/droplet/#{ staging_guid } ?cc-droplet-upload-uri=http://upload.me" ,
111+ app_bits_download_uri : 'http://download.me' ,
112+ buildpacks : [ { name : 'ruby' , key : 'idk' , url : 'www.com' , skip_detect : false } ]
113+ }
105114 } ,
106115 cpu_weight : VCAP ::CloudController ::Diego ::STAGING_TASK_CPU_WEIGHT ,
107116 disk_mb : 100 ,
125134
126135 context 'when lifecycle type is docker' do
127136 let ( :lifecycle_type ) { VCAP ::CloudController ::Lifecycles ::DOCKER }
128- let ( :staging_completion_handler ) { instance_double ( VCAP ::CloudController ::Diego ::Docker ::StagingCompletionHandler ) }
129- let ( :build_model ) { instance_double ( VCAP ::CloudController ::BuildModel ) }
130- let ( :payload ) {
131- {
132- result : {
133- lifecycle_type : 'docker' ,
134- lifecycle_metadata : {
135- docker_image : 'docker.io/some/image'
136- } ,
137- process_types : { web : '' } ,
138- execution_metadata : '{\"cmd\":[],\"ports\":[{\"Port\":8080,\"Protocol\":\"tcp\"}]}'
139- }
140- }
141- }
142-
143- it 'should not make any http calls to eirini' do
144- allow ( VCAP ::CloudController ::BuildModel ) . to receive ( :find ) . and_return ( build_model )
145- allow ( VCAP ::CloudController ::Diego ::Docker ::StagingCompletionHandler ) . to receive ( :new ) . and_return ( staging_completion_handler )
146- allow ( staging_completion_handler ) . to receive ( :staging_complete )
147137
148- stager_client . stage ( staging_guid , staging_details )
149- expect ( WebMock ) . not_to have_requested ( :any , "#{ eirini_url } /stage/#{ staging_guid } " )
138+ let ( :staging_action_builder ) do
139+ instance_double ( VCAP ::CloudController ::Diego ::Docker ::StagingActionBuilder ,
140+ task_environment_variables : lifecycle_environment_variables ,
141+ )
150142 end
151143
152- it 'should mark staging as completed' do
153- expect ( VCAP ::CloudController ::BuildModel ) . to receive ( :find ) . with ( guid : staging_guid ) . and_return ( build_model )
154- expect ( VCAP ::CloudController ::Diego ::Docker ::StagingCompletionHandler ) . to receive ( :new ) . with ( build_model ) . and_return ( staging_completion_handler )
155- expect ( staging_completion_handler ) . to receive ( :staging_complete ) . with ( payload , true )
144+ let ( :lifecycle_protocol ) do
145+ instance_double ( VCAP ::CloudController ::Diego ::Docker ::LifecycleProtocol ,
146+ staging_action_builder : staging_action_builder
147+ )
148+ end
156149
157- staging_details . start_after_staging = true
158- stager_client . stage ( staging_guid , staging_details )
150+ before do
151+ allow ( VCAP :: CloudController :: Diego :: Docker :: LifecycleProtocol ) . to receive ( :new ) . and_return ( lifecycle_protocol )
159152 end
160153
161- context 'when build is not found' do
162- it 'should raise an error' do
163- expect ( VCAP ::CloudController ::BuildModel ) . to receive ( :find ) . with ( guid : staging_guid ) . and_return ( nil )
164- expect {
165- stager_client . stage ( staging_guid , staging_details )
166- } . to raise_error ( CloudController ::Errors ::ApiError , 'Build not found' )
167- end
154+ it 'should set a docker lifecycle' do
155+ stager_client . stage ( staging_guid , staging_details )
156+ expect ( WebMock ) . to have_requested ( :post , "#{ eirini_url } /stage/#{ staging_guid } " ) . with ( body : {
157+ app_guid : 'thor' ,
158+ app_name : 'the_thor' ,
159+ staging_guid : staging_guid ,
160+ org_name : 'some-org' ,
161+ org_guid : 'some-org-guid' ,
162+ space_name : 'outer' ,
163+ space_guid : 'outer-guid' ,
164+ environment : [ { name : 'VCAP_APPLICATION' , value : '{"wow":"pants"}' } ,
165+ { name : 'MEMORY_LIMIT' , value : '256m' } ,
166+ { name : 'VCAP_SERVICES' , value : '{}' } ] ,
167+ completion_callback : 'https://internal_user:internal_password@api.internal.cf:8182/internal/v3/staging//build_completed?start=' ,
168+ lifecycle : {
169+ docker_lifecycle : {
170+ image : 'docker.io/some/image' ,
171+ registry_username : 'theone' ,
172+ registry_password : 'notone'
173+ }
174+ } ,
175+ cpu_weight : VCAP ::CloudController ::Diego ::STAGING_TASK_CPU_WEIGHT ,
176+ disk_mb : 100 ,
177+ memory_mb : 200
178+ } . to_json
179+ )
168180 end
169181 end
182+ end
170183
171- context 'when lifecycle type is invalid' do
172- let ( :lifecycle_type ) { 'dockerpack' }
184+ context 'when lifecycle type is invalid' do
185+ let ( :lifecycle_type ) { 'dockerpack' }
173186
174- it 'should raise an error' do
175- expect {
176- stager_client . stage ( staging_guid , staging_details )
177- } . to raise_error ( RuntimeError , 'lifecycle type `dockerpack` is invalid' )
178- end
187+ it 'should raise an error' do
188+ expect {
189+ stager_client . stage ( staging_guid , staging_details )
190+ } . to raise_error ( RuntimeError , 'lifecycle type `dockerpack` is invalid' )
179191 end
180192 end
181193
@@ -193,6 +205,8 @@ def stub_staging_details(lifecycle_type)
193205 package_model = VCAP ::CloudController ::PackageModel . make (
194206 type : 'docker' ,
195207 docker_image : 'docker.io/some/image' ,
208+ docker_username : 'theone' ,
209+ docker_password : 'notone' ,
196210 app : app_model )
197211
198212 staging_details = VCAP ::CloudController ::Diego ::StagingDetails . new
0 commit comments