@@ -54,7 +54,28 @@ module VCAP::CloudController
5454 expect ( Hash [ updated_droplet . annotations . map { |a | [ a . key , a . value ] } ] ) .
5555 to eq ( { 'University' => 'Toronto' , 'reason' => 'add some more annotations' } )
5656 end
57- context 'trying to update a buildpack droplet image' do
57+ end
58+
59+ context 'image updates' do
60+ context 'when the droplet is not STAGED' do
61+ let! ( :droplet ) { DropletModel . make ( :kpack , state : VCAP ::CloudController ::DropletModel ::STAGING_STATE ) }
62+
63+ let ( :message ) do
64+ VCAP ::CloudController ::DropletUpdateMessage . new ( {
65+ image : 'new-image-reference'
66+ } )
67+ end
68+
69+ it 'returns an error saying that a droplet update cannot occur during staging' do
70+ expect ( message ) . to be_valid
71+ expect { droplet_update . update ( droplet , message )
72+ } . to raise_error ( DropletUpdate ::InvalidDroplet , 'Droplet image can only be updated on staged droplets' )
73+ end
74+ end
75+
76+ context 'when the droplet type is buildpack' do
77+ let! ( :droplet ) { DropletModel . make ( :buildpack ) }
78+
5879 let ( :message ) do
5980 VCAP ::CloudController ::DropletUpdateMessage . new ( {
6081 image : 'some-image-reference' ,
@@ -69,42 +90,59 @@ module VCAP::CloudController
6990 } ,
7091 } )
7192 end
93+
7294 it 'returns an error saying that a buildpack droplet image cannot be updated' do
7395 expect ( message ) . to be_valid
7496 expect { droplet_update . update ( droplet , message )
7597 } . to raise_error ( DropletUpdate ::InvalidDroplet , 'Images can only be updated for docker droplets' )
7698 end
7799 end
78- end
79- context 'docker droplet update' do
80- let! ( :docker_droplet ) do
81- VCAP ::CloudController ::DropletModel . make ( :kpack )
82- end
83100
84- let ( :message ) do
85- VCAP ::CloudController ::DropletUpdateMessage . new ( {
86- image : 'new-image-reference'
87- } )
88- end
89- context 'the image of a staged docker droplet is requested to be updated' do
90- before do
91- docker_droplet . update ( docker_receipt_image : 'some-image-reference' )
101+ context 'when the droplet type is docker' do
102+ let! ( :docker_droplet ) do
103+ VCAP ::CloudController ::DropletModel . make ( :docker )
92104 end
93- it 'updates the droplet record with new image reference' do
94- expect ( message ) . to be_valid
95- updated_droplet = droplet_update . update ( docker_droplet , message )
96- expect ( updated_droplet . docker_receipt_image ) . to eq 'new-image-reference'
105+
106+ let ( :message ) do
107+ VCAP ::CloudController ::DropletUpdateMessage . new ( {
108+ image : 'new-image-reference'
109+ } )
110+ end
111+
112+ context 'the image of a staged docker droplet is requested to be updated' do
113+ before do
114+ docker_droplet . update ( docker_receipt_image : 'some-image-reference' )
115+ end
116+
117+ it 'updates the droplet record with new image reference' do
118+ expect ( message ) . to be_valid
119+ updated_droplet = droplet_update . update ( docker_droplet , message )
120+ expect ( updated_droplet . docker_receipt_image ) . to eq 'new-image-reference'
121+ end
97122 end
98123 end
99- context 'the image of a staging docker droplet is requested to be updated' do
100- before do
101- docker_droplet . update ( state : VCAP ::CloudController ::DropletModel ::STAGING_STATE )
124+
125+ context 'when the droplet type is kpack' do
126+ let! ( :docker_droplet ) do
127+ VCAP ::CloudController ::DropletModel . make ( :kpack )
102128 end
103129
104- it 'returns an error saying that a droplet update cannot occur during staging' do
105- expect ( message ) . to be_valid
106- expect { droplet_update . update ( docker_droplet , message )
107- } . to raise_error ( DropletUpdate ::InvalidDroplet , 'Droplet image can only be updated on staged droplets' )
130+ let ( :message ) do
131+ VCAP ::CloudController ::DropletUpdateMessage . new ( {
132+ image : 'new-image-reference'
133+ } )
134+ end
135+
136+ context 'the image of a staged kpack droplet is requested to be updated' do
137+ before do
138+ docker_droplet . update ( docker_receipt_image : 'some-image-reference' )
139+ end
140+
141+ it 'updates the droplet record with new image reference' do
142+ expect ( message ) . to be_valid
143+ updated_droplet = droplet_update . update ( docker_droplet , message )
144+ expect ( updated_droplet . docker_receipt_image ) . to eq 'new-image-reference'
145+ end
108146 end
109147 end
110148 end
0 commit comments