Skip to content

Commit 0fd8fdf

Browse files
Rollback uses explicit rollback variables if declared
1 parent 1294e02 commit 0fd8fdf

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

app/models/shipit/deploy_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def rollback_steps!
140140
end
141141

142142
def rollback_variables
143-
if config.dig('rollback', 'variables').present?
143+
if config('rollback', 'variables').present?
144144
Array.wrap(config('rollback', 'variables')).map(&VariableDefinition.method(:new))
145145
else
146146
# For backwards compatibility, fallback to using deploy_variables if no explicit rollback variables are set

test/dummy/config/secrets.test.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
"teams": null
1818
}
1919
},
20-
"redis_url": "redis://127.0.0.1:6379/7"
21-
}
20+
"redis_url": "redis://shipit-engine.root.shopify.dev.internal:6379/7"
21+
}

test/dummy/config/secrets.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ test:
4444
id: Iv1.bf2c2c45b449bfd9
4545
secret: ef694cd6e45223075d78d138ef014049052665f1
4646
teams:
47-
redis_url: "redis://127.0.0.1:6379/7"
47+
redis_url: "redis://shipit-engine.root.shopify.dev.internal:6379/7"

test/models/deploy_spec_test.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,31 @@ class DeploySpecTest < ActiveSupport::TestCase
243243
assert_equal ["kubernetes-deploy --max-watch-seconds 900 foo bar"], @spec.rollback_steps
244244
end
245245

246+
test "#rollback_variables returns an empty array by default" do
247+
assert_equal [], @spec.deploy_variables
248+
end
249+
250+
test "#rollback_variables returns an array of VariableDefinition instances" do
251+
@spec.stubs(:load_config).returns('rollback' => { 'variables' => [{
252+
'name' => 'SAFETY_DISABLED',
253+
'title' => 'Set to 1 to do dangerous things',
254+
'default' => 0
255+
}] })
256+
257+
assert_equal 1, @spec.rollback_variables.size
258+
variable_definition = @spec.rollback_variables.first
259+
assert_equal 'SAFETY_DISABLED', variable_definition.name
260+
end
261+
262+
test "#rollback_variables falls back to deploy_variables if rollback_variables itself is empty" do
263+
@spec.stubs(:load_config).returns('deploy' => { 'variables' => [{
264+
'name' => 'SAFETY_DISABLED',
265+
'title' => 'Set to 1 to do dangerous things',
266+
'default' => 0
267+
}] })
268+
assert_equal @spec.rollback_variables.map(&:to_h), @spec.deploy_variables.map(&:to_h)
269+
end
270+
246271
test "#discover_task_definitions include a kubernetes restart command if `kubernetes` is present" do
247272
@spec.stubs(:load_config).returns(
248273
'kubernetes' => {
@@ -381,7 +406,8 @@ class DeploySpecTest < ActiveSupport::TestCase
381406
},
382407
'rollback' => {
383408
'override' => nil,
384-
'retries' => nil
409+
'retries' => nil,
410+
'variables' => []
385411
},
386412
'fetch' => nil,
387413
'tasks' => {}

0 commit comments

Comments
 (0)