test/models/deploy_spec_test.rb in shipit-engine-0.31.0 vs test/models/deploy_spec_test.rb in shipit-engine-0.32.0
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
require 'test_helper'
module Shipit
class DeploySpecTest < ActiveSupport::TestCase
setup do
@@ -20,32 +21,32 @@
test '#supports_rollback? returns false by default' do
refute @spec.supports_rollback?
end
test '#supports_rollback? returns true if steps are defined' do
- @spec.stubs(:load_config).returns('rollback' => {'override' => ['rm -rf /usr /lib/nvidia-current/xorg/xorg']})
+ @spec.stubs(:load_config).returns('rollback' => { 'override' => ['rm -rf /usr /lib/nvidia-current/xorg/xorg'] })
assert @spec.supports_rollback?
end
test '#supports_rollback? returns true if stack is detected as capistrano' do
@spec.expects(:capistrano?).returns(true)
assert @spec.supports_rollback?
end
test '#dependencies_steps returns `dependencies.override` if present' do
- @spec.stubs(:load_config).returns('dependencies' => {'override' => %w(foo bar baz)})
+ @spec.stubs(:load_config).returns('dependencies' => { 'override' => %w(foo bar baz) })
assert_equal %w(foo bar baz), @spec.dependencies_steps
end
test '#dependencies_steps returns `bundle install` if a `Gemfile` is present' do
@spec.expects(:bundler?).returns(true).at_least_once
@spec.expects(:bundle_install).returns(['bundle install'])
assert_equal ['bundle install'], @spec.dependencies_steps
end
test "#dependencies_steps prepend and append pre and post steps" do
- @spec.stubs(:load_config).returns('dependencies' => {'pre' => ['before'], 'post' => ['after']})
+ @spec.stubs(:load_config).returns('dependencies' => { 'pre' => ['before'], 'post' => ['after'] })
@spec.expects(:bundler?).returns(true).at_least_once
@spec.expects(:bundle_install).returns(['bundle install'])
assert_equal ['before', 'bundle install', 'after'], @spec.dependencies_steps
end
@@ -73,11 +74,11 @@
assert_equal command, @spec.bundle_install.last
end
test '#bundle_install use `dependencies.bundler.without` if present to build the --without argument' do
@spec.stubs(:gemfile_lock_exists?).returns(true)
- @spec.stubs(:load_config).returns('dependencies' => {'bundler' => {'without' => %w(some custom groups)}})
+ @spec.stubs(:load_config).returns('dependencies' => { 'bundler' => { 'without' => %w(some custom groups) } })
command = %(
bundle install
--frozen
--jobs 4
--path #{DeploySpec.bundle_path}
@@ -86,29 +87,29 @@
).gsub(/\s+/, ' ').strip
assert_equal command, @spec.bundle_install.last
end
test '#bundle_install has --frozen option if Gemfile.lock is present' do
- @spec.stubs(:load_config).returns('dependencies' => {'bundler' => {'without' => %w(some custom groups)}})
+ @spec.stubs(:load_config).returns('dependencies' => { 'bundler' => { 'without' => %w(some custom groups) } })
@spec.stubs(:gemfile_lock_exists?).returns(true)
assert @spec.bundle_install.last.include?('--frozen')
end
test '#bundle_install does not have --frozen option if Gemfile.lock is not present' do
- @spec.stubs(:load_config).returns('dependencies' => {'bundler' => {'without' => %w(some custom groups)}})
+ @spec.stubs(:load_config).returns('dependencies' => { 'bundler' => { 'without' => %w(some custom groups) } })
@spec.stubs(:gemfile_lock_exists?).returns(false)
refute @spec.bundle_install.last.include?('--frozen')
end
test '#bundle_install does not have --frozen if overridden in shipit.yml' do
- @spec.stubs(:load_config).returns('dependencies' => {'bundler' => {'frozen' => false}})
+ @spec.stubs(:load_config).returns('dependencies' => { 'bundler' => { 'frozen' => false } })
@spec.stubs(:gemfile_lock_exists?).returns(true)
refute @spec.bundle_install.last.include?('--frozen')
end
test '#deploy_steps returns `deploy.override` if present' do
- @spec.stubs(:load_config).returns('deploy' => {'override' => %w(foo bar baz)})
+ @spec.stubs(:load_config).returns('deploy' => { 'override' => %w(foo bar baz) })
assert_equal %w(foo bar baz), @spec.deploy_steps
end
test '#deploy_steps returns `cap $ENVIRONMENT deploy` if a `Capfile` is present' do
@spec.expects(:bundler?).returns(true).at_least_once
@@ -159,11 +160,11 @@
)
assert_equal ["kubernetes-deploy --max-watch-seconds 900 --template-dir k8s_templates/ foo bar"], @spec.deploy_steps
end
test "#deploy_steps prepend and append pre and post steps" do
- @spec.stubs(:load_config).returns('deploy' => {'pre' => ['before'], 'post' => ['after']})
+ @spec.stubs(:load_config).returns('deploy' => { 'pre' => ['before'], 'post' => ['after'] })
@spec.expects(:bundler?).returns(true).at_least_once
@spec.expects(:capistrano?).returns(true)
assert_equal ['before', 'bundle exec cap $ENVIRONMENT deploy', 'after'], @spec.deploy_steps
end
@@ -173,22 +174,22 @@
@spec.deploy_steps!
end
end
test '#rollback_steps returns `rollback.override` if present' do
- @spec.stubs(:load_config).returns('rollback' => {'override' => %w(foo bar baz)})
+ @spec.stubs(:load_config).returns('rollback' => { 'override' => %w(foo bar baz) })
assert_equal %w(foo bar baz), @spec.rollback_steps
end
test '#rollback_steps returns `cap $ENVIRONMENT deploy:rollback` if a `Capfile` is present' do
@spec.expects(:bundler?).returns(true).at_least_once
@spec.expects(:capistrano?).returns(true)
assert_equal ['bundle exec cap $ENVIRONMENT deploy:rollback'], @spec.rollback_steps
end
test "#rollback_steps prepend and append pre and post steps" do
- @spec.stubs(:load_config).returns('rollback' => {'pre' => ['before'], 'post' => ['after']})
+ @spec.stubs(:load_config).returns('rollback' => { 'pre' => ['before'], 'post' => ['after'] })
@spec.expects(:bundler?).returns(true).at_least_once
@spec.expects(:capistrano?).returns(true)
assert_equal ['before', 'bundle exec cap $ENVIRONMENT deploy:rollback', 'after'], @spec.rollback_steps
end
@@ -253,18 +254,18 @@
)
assert_equal tasks, @spec.discover_task_definitions
end
test '#machine_env returns an environment hash' do
- @spec.stubs(:load_config).returns('machine' => {'environment' => {'GLOBAL' => '1'}})
- assert_equal({'GLOBAL' => '1'}, @spec.machine_env)
+ @spec.stubs(:load_config).returns('machine' => { 'environment' => { 'GLOBAL' => '1' } })
+ assert_equal({ 'GLOBAL' => '1' }, @spec.machine_env)
end
test '#load_config can grab the env-specific shipit.yml file' do
config = {}
config.expects(:exist?).returns(true)
- config.expects(:read).returns({'dependencies' => {'override' => %w(foo bar baz)}}.to_yaml)
+ config.expects(:read).returns({ 'dependencies' => { 'override' => %w(foo bar baz) } }.to_yaml)
spec = DeploySpec::FileSystem.new('.', 'staging')
spec.expects(:file).with('shipit.staging.yml', root: true).returns(config)
assert_equal %w(foo bar baz), spec.dependencies_steps
end
@@ -272,11 +273,11 @@
not_config = {}
not_config.expects(:exist?).returns(false)
config = {}
config.expects(:exist?).returns(true)
- config.expects(:read).returns({'dependencies' => {'override' => %w(foo bar baz)}}.to_yaml)
+ config.expects(:read).returns({ 'dependencies' => { 'override' => %w(foo bar baz) } }.to_yaml)
spec = DeploySpec::FileSystem.new('.', 'staging')
spec.expects(:file).with('shipit.staging.yml', root: true).returns(not_config)
spec.expects(:file).with('shipit.yml', root: true).returns(config)
assert_equal %w(foo bar baz), spec.dependencies_steps
@@ -350,28 +351,28 @@
'allow_failures' => [],
'require' => [],
'blocking' => [],
},
'machine' => {
- 'environment' => {'BUNDLE_PATH' => @spec.bundle_path.to_s},
+ 'environment' => { 'BUNDLE_PATH' => @spec.bundle_path.to_s },
'directory' => nil,
'cleanup' => true,
},
- 'review' => {'checklist' => [], 'monitoring' => [], 'checks' => []},
+ 'review' => { 'checklist' => [], 'monitoring' => [], 'checks' => [] },
'status' => {
'context' => nil,
'delay' => 0,
},
- 'dependencies' => {'override' => []},
+ 'dependencies' => { 'override' => [] },
'plugins' => {},
'deploy' => {
'override' => nil,
'variables' => [],
'max_commits' => 8,
'interval' => 0,
},
- 'rollback' => {'override' => nil},
+ 'rollback' => { 'override' => nil },
'fetch' => nil,
'tasks' => {},
}
assert_equal config, @spec.cacheable.config
end
@@ -379,29 +380,29 @@
test "#deploy_variables returns an empty array by default" do
assert_equal [], @spec.deploy_variables
end
test "#deploy_variables returns an array of VariableDefinition instances" do
- @spec.stubs(:load_config).returns('deploy' => {'variables' => [{
+ @spec.stubs(:load_config).returns('deploy' => { 'variables' => [{
'name' => 'SAFETY_DISABLED',
'title' => 'Set to 1 to do dangerous things',
'default' => 0,
- }]})
+ }] })
assert_equal 1, @spec.deploy_variables.size
variable_definition = @spec.deploy_variables.first
assert_equal 'SAFETY_DISABLED', variable_definition.name
end
test "task definitions don't prepend bundle exec by default" do
- @spec.expects(:load_config).returns('tasks' => {'restart' => {'steps' => %w(foo)}})
+ @spec.expects(:load_config).returns('tasks' => { 'restart' => { 'steps' => %w(foo) } })
definition = @spec.find_task_definition('restart')
assert_equal ['foo'], definition.steps
end
test "task definitions don't bundle exec before serialization" do
- @spec.expects(:discover_task_definitions).returns('restart' => {'steps' => %w(foo)})
+ @spec.expects(:discover_task_definitions).returns('restart' => { 'steps' => %w(foo) })
@spec.expects(:bundler?).returns(true).at_least_once
cached_spec = DeploySpec.load(DeploySpec.dump(@spec))
definition = cached_spec.find_task_definition('restart')
assert_equal ['foo'], definition.steps
@@ -416,22 +417,22 @@
# For this test case, we want to have the module create a task with the same
# ID as defined from config
module TestTaskDiscovery
def discover_task_definitions
{
- 'config_task' => {'steps' => %w(bar)},
+ 'config_task' => { 'steps' => %w(bar) },
}.merge!(super)
end
end
# Include the module in our new test class
- DuplicateCustomizedDeploySpec.include TestTaskDiscovery
+ DuplicateCustomizedDeploySpec.include(TestTaskDiscovery)
# Setup the spec as we would normally, but use the customized version
@spec = DuplicateCustomizedDeploySpec.new(@app_dir, 'env')
@spec.stubs(:load_config).returns(
- 'tasks' => {'config_task' => {'steps' => %w(foo)}},
+ 'tasks' => { 'config_task' => { 'steps' => %w(foo) } },
)
tasks = @spec.task_definitions
# Assert we get only the task from the config, not from the module
assert_equal %w(config_task), tasks.map(&:id)
@@ -446,22 +447,22 @@
# Create the module we want to include in our new class
# This module demonstrates how to have new tasks to be appended to the task list
module TestTaskDiscovery
def discover_task_definitions
{
- 'module_task' => {'steps' => %w(bar)},
+ 'module_task' => { 'steps' => %w(bar) },
}.merge(super)
end
end
# Include the module in our new test class
- CustomizedDeploySpec.include TestTaskDiscovery
+ CustomizedDeploySpec.include(TestTaskDiscovery)
# Setup the spec as we would normally, but use the customized version
@spec = CustomizedDeploySpec.new(@app_dir, 'env')
@spec.stubs(:load_config).returns(
- 'tasks' => {'config_task' => {'steps' => %w(foo)}},
+ 'tasks' => { 'config_task' => { 'steps' => %w(foo) } },
'kubernetes' => {
'namespace' => 'foo',
'context' => 'bar',
'timeout' => '20m',
},
@@ -482,11 +483,11 @@
assert_equal ["kubernetes-restart foo bar --max-watch-seconds 1200"], restart_task.steps
end
test "task definitions returns an array of VariableDefinition instances" do
@spec.expects(:load_config).returns('tasks' =>
- {'restart' =>
+ { 'restart' =>
{
'variables' => [
{
'name' => 'SAFETY_DISABLED',
'title' => 'Set to 1 to do dangerous things',
@@ -497,12 +498,11 @@
'title' => 'Set to 0 to foo',
'default' => 1,
},
],
'steps' => %w(foo),
- },
- })
+ } })
assert_equal 2, @spec.task_definitions.first.variables.size
variable_definition = @spec.task_definitions.first.variables.first
assert_equal 'SAFETY_DISABLED', variable_definition.name
end
@@ -510,26 +510,26 @@
test "task definitions returns an empty array by default" do
assert_equal [], @spec.task_definitions
end
test "#review_checklist returns an array" do
- @spec.expects(:load_config).returns('review' => {'checklist' => %w(foo bar)})
+ @spec.expects(:load_config).returns('review' => { 'checklist' => %w(foo bar) })
assert_equal %w(foo bar), @spec.review_checklist
end
test "#review_checklist returns an empty array if the section is missing" do
assert_equal [], @spec.review_checklist
end
test "#review_monitoring returns an array of hashes" do
- @spec.expects(:load_config).returns('review' => {'monitoring' => [
- {'image' => 'http://example.com/foo.png', 'width' => 200, 'height' => 400},
- {'iframe' => 'http://example.com/', 'width' => 200, 'height' => 400},
- ]})
+ @spec.expects(:load_config).returns('review' => { 'monitoring' => [
+ { 'image' => 'http://example.com/foo.png', 'width' => 200, 'height' => 400 },
+ { 'iframe' => 'http://example.com/', 'width' => 200, 'height' => 400 },
+ ] })
assert_equal [
- {'image' => 'http://example.com/foo.png', 'width' => 200, 'height' => 400},
- {'iframe' => 'http://example.com/', 'width' => 200, 'height' => 400},
+ { 'image' => 'http://example.com/foo.png', 'width' => 200, 'height' => 400 },
+ { 'iframe' => 'http://example.com/', 'width' => 200, 'height' => 400 },
], @spec.review_monitoring
end
test "#review_monitoring returns an empty array if the section is missing" do
assert_equal [], @spec.review_monitoring
@@ -538,16 +538,16 @@
test "#hidden_statuses is empty by default" do
assert_equal [], @spec.hidden_statuses
end
test "#hidden_statuses is an array even if the value is a string" do
- @spec.expects(:load_config).returns('ci' => {'hide' => 'ci/circleci'})
+ @spec.expects(:load_config).returns('ci' => { 'hide' => 'ci/circleci' })
assert_equal %w(ci/circleci), @spec.hidden_statuses
end
test "#hidden_statuses is an array even if the value is present" do
- @spec.expects(:load_config).returns('ci' => {'hide' => %w(ci/circleci ci/jenkins)})
+ @spec.expects(:load_config).returns('ci' => { 'hide' => %w(ci/circleci ci/jenkins) })
assert_equal %w(ci/circleci ci/jenkins), @spec.hidden_statuses
end
test "#required_statuses automatically includes #blocking_statuses" do
@spec.expects(:load_config).returns(
@@ -675,11 +675,11 @@
assert_equal 330, @spec.revalidate_pull_requests_after.to_i
end
test "#file is impacted by `machine.directory`" do
subdir = '/foo/bar'
- @spec.stubs(:load_config).returns('machine' => {'directory' => subdir})
+ @spec.stubs(:load_config).returns('machine' => { 'directory' => subdir })
assert_instance_of Pathname, @spec.file('baz')
assert_equal File.join(@app_dir, subdir, 'baz'), @spec.file('baz').to_s
end
test "#clear_working_directory? returns true by default" do
@@ -1081,8 +1081,13 @@
'age' => 'badbadbad',
},
},
)
assert_nil @spec.max_divergence_age
+ end
+
+ test "serialised deploy specs are normalised" do
+ stack = shipit_stacks(:shipit)
+ assert_equal stack.cached_deploy_spec_before_type_cast, DeploySpec.dump(stack.cached_deploy_spec)
end
end
end