Skip to content

Commit 09be7f2

Browse files
committed
chore(TNZ-44895): start with recreate tests
1 parent b328c8f commit 09be7f2

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

app/models/runtime/deployment_model.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class DeploymentModel < Sequel::Model(:deployments)
2727

2828
DEPLOYMENT_STRATEGIES = [
2929
ROLLING_STRATEGY = 'rolling'.freeze,
30-
CANARY_STRATEGY = 'canary'.freeze
30+
CANARY_STRATEGY = 'canary'.freeze,
31+
RECREATE_STRATEGY = 'recreate'.freeze
3132
].freeze
3233

3334
PROGRESSING_STATES = [

spec/unit/actions/deployment_create_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,30 @@ module VCAP::CloudController
15091509
end
15101510
end
15111511

1512+
context 'when the strategy is recreate' do
1513+
let(:strategy) { 'recreate' }
1514+
1515+
it 'creates the deployment with the recreate strategy' do
1516+
deployment = nil
1517+
1518+
expect do
1519+
deployment = DeploymentCreate.create(app:, message:, user_audit_info:)
1520+
end.to change(DeploymentModel, :count).by(1)
1521+
1522+
expect(deployment.strategy).to eq(DeploymentModel::RECREATE_STRATEGY)
1523+
end
1524+
1525+
it 'sets the deployment state to DEPLOYING' do
1526+
deployment = nil
1527+
1528+
expect do
1529+
deployment = DeploymentCreate.create(app:, message:, user_audit_info:)
1530+
end.to change(DeploymentModel, :count).by(1)
1531+
1532+
expect(deployment.state).to eq(DeploymentModel::DEPLOYING_STATE)
1533+
end
1534+
end
1535+
15121536
context 'when the strategy is nil' do
15131537
let(:strategy) { nil }
15141538

spec/unit/messages/deployment_create_message_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ module VCAP::CloudController
2929
expect(message).to be_valid
3030
end
3131

32+
it 'can be recreate' do
33+
body['strategy'] = 'recreate'
34+
message = DeploymentCreateMessage.new(body)
35+
expect(message).to be_valid
36+
end
37+
3238
it 'is valid with nil strategy' do
3339
body['strategy'] = nil
3440
message = DeploymentCreateMessage.new(body)
@@ -125,6 +131,15 @@ module VCAP::CloudController
125131
expect(message).to be_valid
126132
end
127133
end
134+
135+
context 'when set with recreate strategy'
136+
it 'is not valid' do
137+
body['strategy'] = 'recreate'
138+
message = DeploymentCreateMessage.new(body)
139+
expect(message).not_to be_valid
140+
expect(message.errors.full_messages).to include('Max in flight is not a supported option for recreate deployment strategy')
141+
end
142+
end
128143
end
129144

130145
describe 'web_instances' do
@@ -372,6 +387,14 @@ module VCAP::CloudController
372387
expect(message.errors[:'options.canary']).to include('are only valid for Canary deployments')
373388
end
374389

390+
it 'errors when strategy is set to recreate' do
391+
body['options'] = { canary: {} }
392+
body['strategy'] = 'recreate'
393+
message = DeploymentCreateMessage.new(body)
394+
expect(message).not_to be_valid
395+
expect(message.errors[:'options.canary']).to include('are only valid for Canary deployments')
396+
end
397+
375398
it 'errors when there is an unknown option' do
376399
body['options'] = { foo: 'bar', baz: 'boo' }
377400
message = DeploymentCreateMessage.new(body)
@@ -486,6 +509,10 @@ module VCAP::CloudController
486509
end
487510
end
488511

512+
describe 'recreate options' do
513+
514+
end
515+
489516
describe 'metadata' do
490517
context 'when the annotations params are valid' do
491518
let(:params) do

spec/unit/presenters/v3/deployment_presenter_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ module VCAP::CloudController::Presenters::V3
200200
end
201201
end
202202
end
203+
context 'when the strategy is recreate' do
204+
before do
205+
deployment.strategy = VCAP::CloudController::DeploymentModel::RECREATE_STRATEGY
206+
end
207+
208+
it 'shows no canary status' do
209+
result = DeploymentPresenter.new(deployment).to_hash
210+
expect(result[:status][:canary]).to be_nil
211+
end
212+
end
203213
end
204214

205215
describe 'options' do

0 commit comments

Comments
 (0)