@@ -10,49 +10,102 @@ module VCAP::CloudController
1010 subject ( :droplet_update ) { DropletUpdate . new }
1111
1212 describe '#update' do
13- let! ( :droplet ) { DropletModel . make }
14-
15- let! ( :label ) do
16- VCAP ::CloudController ::DropletLabelModel . make (
17- key_prefix : 'indiana.edu' ,
18- key_name : 'state' ,
19- value : 'Indiana' ,
20- resource_guid : droplet . guid
21- )
22- end
13+ context 'buildpack droplet update' do
14+ let! ( :droplet ) { DropletModel . make }
15+ let! ( :label ) do
16+ VCAP ::CloudController ::DropletLabelModel . make (
17+ key_prefix : 'indiana.edu' ,
18+ key_name : 'state' ,
19+ value : 'Indiana' ,
20+ resource_guid : droplet . guid
21+ )
22+ end
2323
24- let! ( :annotation ) do
25- VCAP ::CloudController ::DropletAnnotationModel . make (
26- key : 'University' ,
27- value : 'Toronto' ,
28- resource_guid : droplet . guid
29- )
30- end
24+ let! ( :annotation ) do
25+ VCAP ::CloudController ::DropletAnnotationModel . make (
26+ key : 'University' ,
27+ value : 'Toronto' ,
28+ resource_guid : droplet . guid
29+ )
30+ end
3131
32- let ( :message ) do
33- VCAP ::CloudController ::DropletUpdateMessage . new ( {
34- metadata : {
35- labels : {
36- freaky : 'wednesday' ,
37- 'indiana.edu/state' => nil ,
38- } ,
39- annotations : {
40- reason : 'add some more annotations' ,
32+ let ( :message ) do
33+ VCAP ::CloudController ::DropletUpdateMessage . new ( {
34+ metadata : {
35+ labels : {
36+ freaky : 'wednesday' ,
37+ 'indiana.edu/state' => nil ,
38+ } ,
39+ annotations : {
40+ reason : 'add some more annotations' ,
41+ } ,
4142 } ,
42- } ,
43- } )
44- end
43+ } )
44+ end
45+
46+ it 'update the droplet record' do
47+ expect ( message ) . to be_valid
48+ updated_droplet = droplet_update . update ( droplet , message )
4549
46- it 'update the droplet record' do
47- expect ( message ) . to be_valid
48- updated_droplet = droplet_update . update ( droplet , message )
50+ expect ( updated_droplet . labels . first . key_name ) . to eq 'freaky'
51+ expect ( updated_droplet . labels . first . value ) . to eq 'wednesday'
52+ expect ( updated_droplet . labels . size ) . to eq 1
53+ expect ( updated_droplet . annotations . size ) . to eq ( 2 )
54+ expect ( Hash [ updated_droplet . annotations . map { |a | [ a . key , a . value ] } ] ) .
55+ to eq ( { 'University' => 'Toronto' , 'reason' => 'add some more annotations' } )
56+ end
57+ context 'trying to update a buildpack droplet image' do
58+ let ( :message ) do
59+ VCAP ::CloudController ::DropletUpdateMessage . new ( {
60+ image : 'some-image-reference' ,
61+ metadata : {
62+ labels : {
63+ freaky : 'wednesday' ,
64+ 'indiana.edu/state' => nil ,
65+ } ,
66+ annotations : {
67+ reason : 'add some more annotations' ,
68+ } ,
69+ } ,
70+ } )
71+ end
72+ it 'returns an error saying that a buildpack droplet image cannot be updated' do
73+ expect ( message ) . to be_valid
74+ expect { droplet_update . update ( droplet , message )
75+ } . to raise_error ( DropletUpdate ::InvalidDroplet , 'Images can only be updated for docker droplets' )
76+ end
77+ end
78+ end
79+ context 'docker droplet update' do
80+ let! ( :docker_droplet ) do
81+ VCAP ::CloudController ::DropletModel . make ( :kpack )
82+ end
4983
50- expect ( updated_droplet . labels . first . key_name ) . to eq 'freaky'
51- expect ( updated_droplet . labels . first . value ) . to eq 'wednesday'
52- expect ( updated_droplet . labels . size ) . to eq 1
53- expect ( updated_droplet . annotations . size ) . to eq ( 2 )
54- expect ( Hash [ updated_droplet . annotations . map { |a | [ a . key , a . value ] } ] ) .
55- to eq ( { 'University' => 'Toronto' , 'reason' => 'add some more annotations' } )
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' )
92+ 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'
97+ end
98+ 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 )
102+ end
103+ it 'returns an error saying that a droplet update cannot occur during staging' do
104+ expect ( message ) . to be_valid
105+ expect { droplet_update . update ( docker_droplet , message )
106+ } . to raise_error ( DropletUpdate ::InvalidDroplet , 'Droplet image cannot be updated during staging' )
107+ end
108+ end
56109 end
57110 end
58111 end
0 commit comments