capistrano 3.4.1 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +7 -5
- data/.rubocop.yml +49 -0
- data/.travis.yml +5 -4
- data/CHANGELOG.md +72 -9
- data/CONTRIBUTING.md +61 -93
- data/DEVELOPMENT.md +122 -0
- data/Gemfile +2 -2
- data/LICENSE.txt +1 -1
- data/README.md +121 -43
- data/RELEASING.md +16 -0
- data/Rakefile +4 -1
- data/bin/cap +1 -1
- data/capistrano.gemspec +16 -21
- data/features/doctor.feature +11 -0
- data/features/step_definitions/assertions.rb +17 -17
- data/features/step_definitions/cap_commands.rb +0 -1
- data/features/step_definitions/setup.rb +12 -8
- data/features/support/env.rb +5 -5
- data/features/support/remote_command_helpers.rb +8 -6
- data/features/support/vagrant_helpers.rb +5 -4
- data/issue_template.md +21 -0
- data/lib/Capfile +5 -1
- data/lib/capistrano/all.rb +9 -10
- data/lib/capistrano/application.rb +36 -26
- data/lib/capistrano/configuration.rb +56 -41
- data/lib/capistrano/configuration/empty_filter.rb +9 -0
- data/lib/capistrano/configuration/filter.rb +18 -47
- data/lib/capistrano/configuration/host_filter.rb +30 -0
- data/lib/capistrano/configuration/null_filter.rb +9 -0
- data/lib/capistrano/configuration/plugin_installer.rb +33 -0
- data/lib/capistrano/configuration/question.rb +10 -7
- data/lib/capistrano/configuration/role_filter.rb +30 -0
- data/lib/capistrano/configuration/server.rb +22 -23
- data/lib/capistrano/configuration/servers.rb +6 -7
- data/lib/capistrano/configuration/variables.rb +136 -0
- data/lib/capistrano/defaults.rb +13 -3
- data/lib/capistrano/deploy.rb +1 -1
- data/lib/capistrano/doctor.rb +5 -0
- data/lib/capistrano/doctor/environment_doctor.rb +19 -0
- data/lib/capistrano/doctor/gems_doctor.rb +45 -0
- data/lib/capistrano/doctor/output_helpers.rb +79 -0
- data/lib/capistrano/doctor/variables_doctor.rb +66 -0
- data/lib/capistrano/dotfile.rb +1 -2
- data/lib/capistrano/dsl.rb +12 -14
- data/lib/capistrano/dsl/env.rb +11 -42
- data/lib/capistrano/dsl/paths.rb +12 -13
- data/lib/capistrano/dsl/stages.rb +2 -4
- data/lib/capistrano/dsl/task_enhancements.rb +5 -7
- data/lib/capistrano/framework.rb +1 -1
- data/lib/capistrano/git.rb +17 -9
- data/lib/capistrano/hg.rb +4 -4
- data/lib/capistrano/i18n.rb +24 -24
- data/lib/capistrano/immutable_task.rb +29 -0
- data/lib/capistrano/install.rb +1 -1
- data/lib/capistrano/plugin.rb +95 -0
- data/lib/capistrano/scm.rb +7 -20
- data/lib/capistrano/setup.rb +19 -5
- data/lib/capistrano/svn.rb +9 -5
- data/lib/capistrano/tasks/console.rake +4 -8
- data/lib/capistrano/tasks/deploy.rake +75 -62
- data/lib/capistrano/tasks/doctor.rake +19 -0
- data/lib/capistrano/tasks/framework.rake +13 -14
- data/lib/capistrano/tasks/git.rake +10 -11
- data/lib/capistrano/tasks/hg.rake +7 -7
- data/lib/capistrano/tasks/install.rake +14 -15
- data/lib/capistrano/tasks/svn.rake +7 -7
- data/lib/capistrano/templates/Capfile +3 -3
- data/lib/capistrano/templates/deploy.rb.erb +6 -5
- data/lib/capistrano/upload_task.rb +1 -1
- data/lib/capistrano/version.rb +1 -1
- data/lib/capistrano/version_validator.rb +4 -6
- data/spec/integration/dsl_spec.rb +286 -239
- data/spec/integration_spec_helper.rb +3 -5
- data/spec/lib/capistrano/application_spec.rb +22 -14
- data/spec/lib/capistrano/configuration/empty_filter_spec.rb +17 -0
- data/spec/lib/capistrano/configuration/filter_spec.rb +82 -84
- data/spec/lib/capistrano/configuration/host_filter_spec.rb +61 -0
- data/spec/lib/capistrano/configuration/null_filter_spec.rb +17 -0
- data/spec/lib/capistrano/configuration/question_spec.rb +12 -16
- data/spec/lib/capistrano/configuration/role_filter_spec.rb +64 -0
- data/spec/lib/capistrano/configuration/server_spec.rb +102 -110
- data/spec/lib/capistrano/configuration/servers_spec.rb +124 -141
- data/spec/lib/capistrano/configuration_spec.rb +150 -61
- data/spec/lib/capistrano/doctor/environment_doctor_spec.rb +44 -0
- data/spec/lib/capistrano/doctor/gems_doctor_spec.rb +61 -0
- data/spec/lib/capistrano/doctor/output_helpers_spec.rb +47 -0
- data/spec/lib/capistrano/doctor/variables_doctor_spec.rb +79 -0
- data/spec/lib/capistrano/dsl/paths_spec.rb +58 -50
- data/spec/lib/capistrano/dsl/task_enhancements_spec.rb +62 -32
- data/spec/lib/capistrano/dsl_spec.rb +6 -8
- data/spec/lib/capistrano/git_spec.rb +35 -7
- data/spec/lib/capistrano/hg_spec.rb +14 -5
- data/spec/lib/capistrano/immutable_task_spec.rb +31 -0
- data/spec/lib/capistrano/plugin_spec.rb +84 -0
- data/spec/lib/capistrano/scm_spec.rb +6 -7
- data/spec/lib/capistrano/svn_spec.rb +40 -14
- data/spec/lib/capistrano/upload_task_spec.rb +7 -7
- data/spec/lib/capistrano/version_validator_spec.rb +37 -45
- data/spec/lib/capistrano_spec.rb +2 -3
- data/spec/spec_helper.rb +8 -8
- data/spec/support/Vagrantfile +9 -10
- data/spec/support/tasks/database.rake +3 -3
- data/spec/support/tasks/fail.rake +4 -3
- data/spec/support/tasks/failed.rake +2 -2
- data/spec/support/tasks/plugin.rake +6 -0
- data/spec/support/tasks/root.rake +4 -4
- data/spec/support/test_app.rb +31 -30
- metadata +93 -14
@@ -3,14 +3,14 @@ namespace :hg do
|
|
3
3
|
@strategy ||= Capistrano::Hg.new(self, fetch(:hg_strategy, Capistrano::Hg::DefaultStrategy))
|
4
4
|
end
|
5
5
|
|
6
|
-
desc
|
6
|
+
desc "Check that the repo is reachable"
|
7
7
|
task :check do
|
8
8
|
on release_roles :all do
|
9
9
|
strategy.check
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
desc
|
13
|
+
desc "Clone the repo to the cache"
|
14
14
|
task :clone do
|
15
15
|
on release_roles :all do
|
16
16
|
if strategy.test
|
@@ -23,8 +23,8 @@ namespace :hg do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
desc
|
27
|
-
task :
|
26
|
+
desc "Pull changes from the remote repo"
|
27
|
+
task update: :'hg:clone' do
|
28
28
|
on release_roles :all do
|
29
29
|
within repo_path do
|
30
30
|
strategy.update
|
@@ -32,8 +32,8 @@ namespace :hg do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
desc
|
36
|
-
task :
|
35
|
+
desc "Copy repo to releases"
|
36
|
+
task create_release: :'hg:update' do
|
37
37
|
on release_roles :all do
|
38
38
|
within repo_path do
|
39
39
|
strategy.release
|
@@ -41,7 +41,7 @@ namespace :hg do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
desc
|
44
|
+
desc "Determine the revision that will be deployed"
|
45
45
|
task :set_current_revision do
|
46
46
|
on release_roles :all do
|
47
47
|
within repo_path do
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
desc
|
1
|
+
require "erb"
|
2
|
+
require "pathname"
|
3
|
+
desc "Install Capistrano, cap install STAGES=staging,production"
|
4
4
|
task :install do
|
5
|
-
envs = ENV[
|
5
|
+
envs = ENV["STAGES"] || "staging,production"
|
6
6
|
|
7
|
-
tasks_dir = Pathname.new(
|
8
|
-
config_dir = Pathname.new(
|
9
|
-
deploy_dir = config_dir.join(
|
7
|
+
tasks_dir = Pathname.new("lib/capistrano/tasks")
|
8
|
+
config_dir = Pathname.new("config")
|
9
|
+
deploy_dir = config_dir.join("deploy")
|
10
10
|
|
11
11
|
deploy_rb = File.expand_path("../../templates/deploy.rb.erb", __FILE__)
|
12
12
|
stage_rb = File.expand_path("../../templates/stage.rb.erb", __FILE__)
|
@@ -14,14 +14,14 @@ task :install do
|
|
14
14
|
|
15
15
|
mkdir_p deploy_dir
|
16
16
|
|
17
|
-
entries = [{template: deploy_rb, file: config_dir.join(
|
18
|
-
entries += envs.split(
|
17
|
+
entries = [{ template: deploy_rb, file: config_dir.join("deploy.rb") }]
|
18
|
+
entries += envs.split(",").map { |stage| { template: stage_rb, file: deploy_dir.join("#{stage}.rb") } }
|
19
19
|
|
20
20
|
entries.each do |entry|
|
21
|
-
if File.
|
21
|
+
if File.exist?(entry[:file])
|
22
22
|
warn "[skip] #{entry[:file]} already exists"
|
23
23
|
else
|
24
|
-
File.open(entry[:file],
|
24
|
+
File.open(entry[:file], "w+") do |f|
|
25
25
|
f.write(ERB.new(File.read(entry[:template])).result(binding))
|
26
26
|
puts I18n.t(:written_file, scope: :capistrano, file: entry[:file])
|
27
27
|
end
|
@@ -30,13 +30,12 @@ task :install do
|
|
30
30
|
|
31
31
|
mkdir_p tasks_dir
|
32
32
|
|
33
|
-
if File.
|
33
|
+
if File.exist?("Capfile")
|
34
34
|
warn "[skip] Capfile already exists"
|
35
35
|
else
|
36
|
-
FileUtils.cp(capfile,
|
37
|
-
puts I18n.t(:written_file, scope: :capistrano, file:
|
36
|
+
FileUtils.cp(capfile, "Capfile")
|
37
|
+
puts I18n.t(:written_file, scope: :capistrano, file: "Capfile")
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
40
|
puts I18n.t :capified, scope: :capistrano
|
42
41
|
end
|
@@ -3,14 +3,14 @@ namespace :svn do
|
|
3
3
|
@strategy ||= Capistrano::Svn.new(self, fetch(:svn_strategy, Capistrano::Svn::DefaultStrategy))
|
4
4
|
end
|
5
5
|
|
6
|
-
desc
|
6
|
+
desc "Check that the repo is reachable"
|
7
7
|
task :check do
|
8
8
|
on release_roles :all do
|
9
9
|
strategy.check
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
desc
|
13
|
+
desc "Clone the repo to the cache"
|
14
14
|
task :clone do
|
15
15
|
on release_roles :all do
|
16
16
|
if strategy.test
|
@@ -23,8 +23,8 @@ namespace :svn do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
desc
|
27
|
-
task :
|
26
|
+
desc "Pull changes from the remote repo"
|
27
|
+
task update: :'svn:clone' do
|
28
28
|
on release_roles :all do
|
29
29
|
within repo_path do
|
30
30
|
strategy.update
|
@@ -32,8 +32,8 @@ namespace :svn do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
desc
|
36
|
-
task :
|
35
|
+
desc "Copy repo to releases"
|
36
|
+
task create_release: :'svn:update' do
|
37
37
|
on release_roles :all do
|
38
38
|
within repo_path do
|
39
39
|
strategy.release
|
@@ -41,7 +41,7 @@ namespace :svn do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
desc
|
44
|
+
desc "Determine the revision that will be deployed"
|
45
45
|
task :set_current_revision do
|
46
46
|
on release_roles :all do
|
47
47
|
within repo_path do
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# Load DSL and set up stages
|
2
|
-
require
|
2
|
+
require "capistrano/setup"
|
3
3
|
|
4
4
|
# Include default deployment tasks
|
5
|
-
require
|
5
|
+
require "capistrano/deploy"
|
6
6
|
|
7
7
|
# Include tasks from other gems included in your Gemfile
|
8
8
|
#
|
@@ -24,4 +24,4 @@ require 'capistrano/deploy'
|
|
24
24
|
# require 'capistrano/passenger'
|
25
25
|
|
26
26
|
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
|
27
|
-
Dir.glob(
|
27
|
+
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
|
@@ -13,11 +13,12 @@ set :repo_url, 'git@example.com:me/my_repo.git'
|
|
13
13
|
# Default value for :scm is :git
|
14
14
|
# set :scm, :git
|
15
15
|
|
16
|
-
# Default value for :format is :
|
17
|
-
# set :format, :
|
16
|
+
# Default value for :format is :airbrussh.
|
17
|
+
# set :format, :airbrussh
|
18
18
|
|
19
|
-
#
|
20
|
-
#
|
19
|
+
# You can configure the Airbrussh format using :format_options.
|
20
|
+
# These are the defaults.
|
21
|
+
# set :format_options, command_output: true, log_file: 'log/capistrano.log', color: :auto, truncate: :auto
|
21
22
|
|
22
23
|
# Default value for :pty is false
|
23
24
|
# set :pty, true
|
@@ -26,7 +27,7 @@ set :repo_url, 'git@example.com:me/my_repo.git'
|
|
26
27
|
# set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml')
|
27
28
|
|
28
29
|
# Default value for linked_dirs is []
|
29
|
-
# set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', '
|
30
|
+
# set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'public/system')
|
30
31
|
|
31
32
|
# Default value for default_env is {}
|
32
33
|
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
|
data/lib/capistrano/version.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Capistrano
|
2
2
|
class VersionValidator
|
3
|
-
|
4
3
|
def initialize(version)
|
5
4
|
@version = version
|
6
5
|
end
|
@@ -9,13 +8,13 @@ module Capistrano
|
|
9
8
|
if match?
|
10
9
|
self
|
11
10
|
else
|
12
|
-
|
11
|
+
raise "Capfile locked at #{version}, but #{current_version} is loaded"
|
13
12
|
end
|
14
13
|
end
|
15
14
|
|
16
15
|
private
|
17
|
-
attr_reader :version
|
18
16
|
|
17
|
+
attr_reader :version
|
19
18
|
|
20
19
|
def match?
|
21
20
|
available =~ requested
|
@@ -26,12 +25,11 @@ module Capistrano
|
|
26
25
|
end
|
27
26
|
|
28
27
|
def available
|
29
|
-
Gem::Dependency.new(
|
28
|
+
Gem::Dependency.new("cap", version)
|
30
29
|
end
|
31
30
|
|
32
31
|
def requested
|
33
|
-
Gem::Dependency.new(
|
32
|
+
Gem::Dependency.new("cap", current_version)
|
34
33
|
end
|
35
|
-
|
36
34
|
end
|
37
35
|
end
|
@@ -1,148 +1,177 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Capistrano::DSL do
|
4
|
-
|
5
4
|
let(:dsl) { Class.new.extend Capistrano::DSL }
|
6
5
|
|
7
6
|
before do
|
8
7
|
Capistrano::Configuration.reset!
|
9
8
|
end
|
10
9
|
|
11
|
-
describe
|
12
|
-
describe
|
10
|
+
describe "setting and fetching hosts" do
|
11
|
+
describe "when defining a host using the `server` syntax" do
|
13
12
|
before do
|
14
|
-
dsl.server
|
15
|
-
dsl.server
|
16
|
-
dsl.server
|
17
|
-
dsl.server
|
18
|
-
dsl.server
|
13
|
+
dsl.server "example1.com", roles: %w{web}, active: true
|
14
|
+
dsl.server "example2.com", roles: %w{web}
|
15
|
+
dsl.server "example3.com", roles: %w{app web}, active: true
|
16
|
+
dsl.server "example4.com", roles: %w{app}, primary: true
|
17
|
+
dsl.server "example5.com", roles: %w{db}, no_release: true, active: true
|
19
18
|
end
|
20
19
|
|
21
|
-
describe
|
20
|
+
describe "fetching all servers" do
|
22
21
|
subject { dsl.roles(:all) }
|
23
22
|
|
24
|
-
it
|
23
|
+
it "returns all servers" do
|
25
24
|
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com example5.com}
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
describe
|
30
|
-
|
31
|
-
context 'with no additional options' do
|
28
|
+
describe "fetching all release servers" do
|
29
|
+
context "with no additional options" do
|
32
30
|
subject { dsl.release_roles(:all) }
|
33
31
|
|
34
|
-
it
|
32
|
+
it "returns all release servers" do
|
35
33
|
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com}
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
|
-
context
|
37
|
+
context "with property filter options" do
|
40
38
|
subject { dsl.release_roles(:all, filter: :active) }
|
41
39
|
|
42
|
-
it
|
40
|
+
it "returns all release servers that match the property filter" do
|
43
41
|
expect(subject.map(&:hostname)).to eq %w{example1.com example3.com}
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
48
|
-
describe
|
46
|
+
describe "fetching servers by multiple roles" do
|
49
47
|
it "does not confuse the last role with options" do
|
50
48
|
expect(dsl.roles(:app, :web).count).to eq 4
|
51
49
|
expect(dsl.roles(:app, :web, filter: :active).count).to eq 2
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
55
|
-
describe
|
53
|
+
describe "fetching servers by role" do
|
56
54
|
subject { dsl.roles(:app) }
|
57
55
|
|
58
|
-
it
|
56
|
+
it "returns the servers" do
|
59
57
|
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
63
|
-
describe
|
61
|
+
describe "fetching servers by an array of roles" do
|
64
62
|
subject { dsl.roles([:app]) }
|
65
63
|
|
66
|
-
it
|
64
|
+
it "returns the servers" do
|
67
65
|
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
68
66
|
end
|
69
67
|
end
|
70
68
|
|
71
|
-
describe
|
69
|
+
describe "fetching filtered servers by role" do
|
72
70
|
subject { dsl.roles(:app, filter: :active) }
|
73
71
|
|
74
|
-
it
|
72
|
+
it "returns the servers" do
|
75
73
|
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
76
74
|
end
|
77
75
|
end
|
78
76
|
|
79
|
-
describe
|
77
|
+
describe "fetching selected servers by role" do
|
80
78
|
subject { dsl.roles(:app, select: :active) }
|
81
79
|
|
82
|
-
it
|
80
|
+
it "returns the servers" do
|
83
81
|
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
84
82
|
end
|
85
83
|
end
|
86
84
|
|
87
|
-
describe
|
88
|
-
context
|
85
|
+
describe "fetching the primary server by role" do
|
86
|
+
context "when inferring primary status based on order" do
|
89
87
|
subject { dsl.primary(:web) }
|
90
|
-
it
|
91
|
-
expect(subject.hostname).to eq
|
88
|
+
it "returns the servers" do
|
89
|
+
expect(subject.hostname).to eq "example1.com"
|
92
90
|
end
|
93
91
|
end
|
94
92
|
|
95
|
-
context
|
93
|
+
context "when the attribute `primary` is explicitly set" do
|
96
94
|
subject { dsl.primary(:app) }
|
97
|
-
it
|
98
|
-
expect(subject.hostname).to eq
|
95
|
+
it "returns the servers" do
|
96
|
+
expect(subject.hostname).to eq "example4.com"
|
99
97
|
end
|
100
98
|
end
|
101
99
|
end
|
102
100
|
|
103
|
-
describe
|
101
|
+
describe "setting an internal host filter" do
|
104
102
|
subject { dsl.roles(:app) }
|
105
|
-
it
|
106
|
-
dsl.set :filter,
|
107
|
-
expect(subject.map(&:hostname)).to eq([
|
103
|
+
it "is ignored" do
|
104
|
+
dsl.set :filter, host: "example3.com"
|
105
|
+
expect(subject.map(&:hostname)).to eq(["example3.com", "example4.com"])
|
108
106
|
end
|
109
107
|
end
|
110
108
|
|
111
|
-
describe
|
109
|
+
describe "setting an internal role filter" do
|
112
110
|
subject { dsl.roles(:app) }
|
113
|
-
it
|
114
|
-
dsl.set :filter,
|
115
|
-
expect(subject.map(&:hostname)).to eq([
|
111
|
+
it "ignores it" do
|
112
|
+
dsl.set :filter, role: :web
|
113
|
+
expect(subject.map(&:hostname)).to eq(["example3.com", "example4.com"])
|
116
114
|
end
|
117
115
|
end
|
118
116
|
|
119
|
-
describe
|
117
|
+
describe "setting an internal host and role filter" do
|
120
118
|
subject { dsl.roles(:app) }
|
121
|
-
it
|
122
|
-
dsl.set :filter,
|
123
|
-
expect(subject.map(&:hostname)).to eq([
|
119
|
+
it "ignores it" do
|
120
|
+
dsl.set :filter, role: :web, host: "example1.com"
|
121
|
+
expect(subject.map(&:hostname)).to eq(["example3.com", "example4.com"])
|
124
122
|
end
|
125
123
|
end
|
126
124
|
|
127
|
-
describe
|
125
|
+
describe "setting an internal regexp host filter" do
|
128
126
|
subject { dsl.roles(:all) }
|
129
|
-
it
|
130
|
-
dsl.set :filter,
|
127
|
+
it "is ignored" do
|
128
|
+
dsl.set :filter, host: /1/
|
131
129
|
expect(subject.map(&:hostname)).to eq(%w{example1.com example2.com example3.com example4.com example5.com})
|
132
130
|
end
|
133
131
|
end
|
134
132
|
|
133
|
+
describe "setting an internal hosts filter" do
|
134
|
+
subject { dsl.roles(:app) }
|
135
|
+
it "is ignored" do
|
136
|
+
dsl.set :filter, hosts: "example3.com"
|
137
|
+
expect(subject.map(&:hostname)).to eq(["example3.com", "example4.com"])
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "setting an internal roles filter" do
|
142
|
+
subject { dsl.roles(:app) }
|
143
|
+
it "ignores it" do
|
144
|
+
dsl.set :filter, roles: :web
|
145
|
+
expect(subject.map(&:hostname)).to eq(["example3.com", "example4.com"])
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "setting an internal hosts and roles filter" do
|
150
|
+
subject { dsl.roles(:app) }
|
151
|
+
it "ignores it" do
|
152
|
+
dsl.set :filter, roles: :web, hosts: "example1.com"
|
153
|
+
expect(subject.map(&:hostname)).to eq(["example3.com", "example4.com"])
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "setting an internal regexp hosts filter" do
|
158
|
+
subject { dsl.roles(:all) }
|
159
|
+
it "is ignored" do
|
160
|
+
dsl.set :filter, hosts: /1/
|
161
|
+
expect(subject.map(&:hostname)).to eq(%w{example1.com example2.com example3.com example4.com example5.com})
|
162
|
+
end
|
163
|
+
end
|
135
164
|
end
|
136
165
|
|
137
|
-
describe
|
138
|
-
it
|
139
|
-
expect
|
166
|
+
describe "when defining role with reserved name" do
|
167
|
+
it "fails with ArgumentError" do
|
168
|
+
expect do
|
140
169
|
dsl.role :all, %w{example1.com}
|
141
|
-
|
170
|
+
end.to raise_error(ArgumentError, "all reserved name for role. Please choose another name")
|
142
171
|
end
|
143
172
|
end
|
144
173
|
|
145
|
-
describe
|
174
|
+
describe "when defining hosts using the `role` syntax" do
|
146
175
|
before do
|
147
176
|
dsl.role :web, %w{example1.com example2.com example3.com}
|
148
177
|
dsl.role :web, %w{example1.com}, active: true
|
@@ -152,243 +181,237 @@ describe Capistrano::DSL do
|
|
152
181
|
dsl.role :db, %w{example5.com}, no_release: true
|
153
182
|
end
|
154
183
|
|
155
|
-
describe
|
184
|
+
describe "fetching all servers" do
|
156
185
|
subject { dsl.roles(:all) }
|
157
186
|
|
158
|
-
it
|
187
|
+
it "returns all servers" do
|
159
188
|
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com example5.com}
|
160
189
|
end
|
161
190
|
end
|
162
191
|
|
163
|
-
describe
|
164
|
-
|
165
|
-
context 'with no additional options' do
|
192
|
+
describe "fetching all release servers" do
|
193
|
+
context "with no additional options" do
|
166
194
|
subject { dsl.release_roles(:all) }
|
167
195
|
|
168
|
-
it
|
196
|
+
it "returns all release servers" do
|
169
197
|
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com}
|
170
198
|
end
|
171
199
|
end
|
172
200
|
|
173
|
-
context
|
201
|
+
context "with filter options" do
|
174
202
|
subject { dsl.release_roles(:all, filter: :active) }
|
175
203
|
|
176
|
-
it
|
204
|
+
it "returns all release servers that match the filter" do
|
177
205
|
expect(subject.map(&:hostname)).to eq %w{example1.com example3.com}
|
178
206
|
end
|
179
207
|
end
|
180
208
|
end
|
181
209
|
|
182
|
-
|
183
|
-
describe 'fetching servers by role' do
|
210
|
+
describe "fetching servers by role" do
|
184
211
|
subject { dsl.roles(:app) }
|
185
212
|
|
186
|
-
it
|
213
|
+
it "returns the servers" do
|
187
214
|
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
188
215
|
end
|
189
216
|
end
|
190
217
|
|
191
|
-
describe
|
218
|
+
describe "fetching servers by an array of roles" do
|
192
219
|
subject { dsl.roles([:app]) }
|
193
220
|
|
194
|
-
it
|
221
|
+
it "returns the servers" do
|
195
222
|
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
196
223
|
end
|
197
224
|
end
|
198
225
|
|
199
|
-
describe
|
226
|
+
describe "fetching filtered servers by role" do
|
200
227
|
subject { dsl.roles(:app, filter: :active) }
|
201
228
|
|
202
|
-
it
|
229
|
+
it "returns the servers" do
|
203
230
|
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
204
231
|
end
|
205
232
|
end
|
206
233
|
|
207
|
-
describe
|
234
|
+
describe "fetching selected servers by role" do
|
208
235
|
subject { dsl.roles(:app, select: :active) }
|
209
236
|
|
210
|
-
it
|
237
|
+
it "returns the servers" do
|
211
238
|
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
212
239
|
end
|
213
240
|
end
|
214
241
|
|
215
|
-
describe
|
216
|
-
context
|
242
|
+
describe "fetching the primary server by role" do
|
243
|
+
context "when inferring primary status based on order" do
|
217
244
|
subject { dsl.primary(:web) }
|
218
|
-
it
|
219
|
-
expect(subject.hostname).to eq
|
245
|
+
it "returns the servers" do
|
246
|
+
expect(subject.hostname).to eq "example1.com"
|
220
247
|
end
|
221
248
|
end
|
222
249
|
|
223
|
-
context
|
250
|
+
context "when the attribute `primary` is explicity set" do
|
224
251
|
subject { dsl.primary(:app) }
|
225
|
-
it
|
226
|
-
expect(subject.hostname).to eq
|
252
|
+
it "returns the servers" do
|
253
|
+
expect(subject.hostname).to eq "example4.com"
|
227
254
|
end
|
228
255
|
end
|
229
256
|
end
|
230
|
-
|
231
257
|
end
|
232
258
|
|
233
|
-
describe
|
234
|
-
|
259
|
+
describe "when defining a host using a combination of the `server` and `role` syntax" do
|
235
260
|
before do
|
236
|
-
dsl.server
|
237
|
-
dsl.server
|
238
|
-
dsl.server
|
261
|
+
dsl.server "db@example1.com:1234", roles: %w{db}, active: true
|
262
|
+
dsl.server "root@example1.com:1234", roles: %w{web}, active: true
|
263
|
+
dsl.server "example1.com:5678", roles: %w{web}, active: true
|
239
264
|
dsl.role :app, %w{deployer@example1.com:1234}
|
240
265
|
dsl.role :app, %w{example1.com:5678}
|
241
266
|
end
|
242
267
|
|
243
|
-
describe
|
244
|
-
it
|
245
|
-
expect(dsl.roles(:all).size).to eq(
|
268
|
+
describe "fetching all servers" do
|
269
|
+
it "creates one server per hostname, ignoring user combinations" do
|
270
|
+
expect(dsl.roles(:all).size).to eq(2)
|
246
271
|
end
|
247
272
|
end
|
248
273
|
|
249
|
-
describe
|
250
|
-
it
|
274
|
+
describe "fetching servers for a role" do
|
275
|
+
it "roles defined using the `server` syntax are included" do
|
251
276
|
as = dsl.roles(:web).map { |server| "#{server.user}@#{server.hostname}:#{server.port}" }
|
252
|
-
expect(as.size).to eq(
|
253
|
-
expect(as[0]).to eq("deployer@example1.com:
|
277
|
+
expect(as.size).to eq(2)
|
278
|
+
expect(as[0]).to eq("deployer@example1.com:1234")
|
279
|
+
expect(as[1]).to eq("@example1.com:5678")
|
254
280
|
end
|
255
281
|
|
256
|
-
it
|
282
|
+
it "roles defined using the `role` syntax are included" do
|
257
283
|
as = dsl.roles(:app).map { |server| "#{server.user}@#{server.hostname}:#{server.port}" }
|
258
|
-
expect(as.size).to eq(
|
259
|
-
expect(as[0]).to eq("deployer@example1.com:
|
284
|
+
expect(as.size).to eq(2)
|
285
|
+
expect(as[0]).to eq("deployer@example1.com:1234")
|
286
|
+
expect(as[1]).to eq("@example1.com:5678")
|
260
287
|
end
|
261
288
|
end
|
262
|
-
|
263
289
|
end
|
264
290
|
|
265
|
-
describe
|
291
|
+
describe "when setting user and port" do
|
266
292
|
subject { dsl.roles(:all).map { |server| "#{server.user}@#{server.hostname}:#{server.port}" }.first }
|
267
293
|
|
268
294
|
describe "using the :user property" do
|
269
295
|
it "takes precedence over in the host string" do
|
270
|
-
dsl.server
|
296
|
+
dsl.server "db@example1.com:1234", roles: %w{db}, active: true, user: "brian"
|
271
297
|
expect(subject).to eq("brian@example1.com:1234")
|
272
298
|
end
|
273
299
|
end
|
274
300
|
|
275
301
|
describe "using the :port property" do
|
276
302
|
it "takes precedence over in the host string" do
|
277
|
-
dsl.server
|
303
|
+
dsl.server "db@example1.com:9090", roles: %w{db}, active: true, port: 1234
|
278
304
|
expect(subject).to eq("db@example1.com:1234")
|
279
305
|
end
|
280
306
|
end
|
281
307
|
end
|
282
|
-
|
283
308
|
end
|
284
309
|
|
285
|
-
describe
|
286
|
-
|
310
|
+
describe "setting and fetching variables" do
|
287
311
|
before do
|
288
312
|
dsl.set :scm, :git
|
289
313
|
end
|
290
314
|
|
291
|
-
context
|
292
|
-
context
|
293
|
-
it
|
315
|
+
context "without a default" do
|
316
|
+
context "when the variables is defined" do
|
317
|
+
it "returns the variable" do
|
294
318
|
expect(dsl.fetch(:scm)).to eq :git
|
295
319
|
end
|
296
320
|
end
|
297
321
|
|
298
|
-
context
|
299
|
-
it
|
322
|
+
context "when the variables is undefined" do
|
323
|
+
it "returns nil" do
|
300
324
|
expect(dsl.fetch(:source_control)).to be_nil
|
301
325
|
end
|
302
326
|
end
|
303
327
|
end
|
304
328
|
|
305
|
-
context
|
306
|
-
context
|
307
|
-
it
|
329
|
+
context "with a default" do
|
330
|
+
context "when the variables is defined" do
|
331
|
+
it "returns the variable" do
|
308
332
|
expect(dsl.fetch(:scm, :svn)).to eq :git
|
309
333
|
end
|
310
334
|
end
|
311
335
|
|
312
|
-
context
|
313
|
-
it
|
336
|
+
context "when the variables is undefined" do
|
337
|
+
it "returns the default" do
|
314
338
|
expect(dsl.fetch(:source_control, :svn)).to eq :svn
|
315
339
|
end
|
316
340
|
end
|
317
341
|
end
|
318
342
|
|
319
|
-
context
|
320
|
-
context
|
321
|
-
it
|
343
|
+
context "with a block" do
|
344
|
+
context "when the variables is defined" do
|
345
|
+
it "returns the variable" do
|
322
346
|
expect(dsl.fetch(:scm) { :svn }).to eq :git
|
323
347
|
end
|
324
348
|
end
|
325
349
|
|
326
|
-
context
|
327
|
-
it
|
350
|
+
context "when the variables is undefined" do
|
351
|
+
it "calls the block" do
|
328
352
|
expect(dsl.fetch(:source_control) { :svn }).to eq :svn
|
329
353
|
end
|
330
354
|
end
|
331
355
|
end
|
332
|
-
|
333
356
|
end
|
334
357
|
|
335
|
-
describe
|
358
|
+
describe "asking for a variable" do
|
336
359
|
before do
|
337
360
|
dsl.ask(:scm, :svn)
|
338
361
|
$stdout.stubs(:print)
|
339
362
|
end
|
340
363
|
|
341
|
-
context
|
364
|
+
context "variable is provided" do
|
342
365
|
before do
|
343
|
-
$stdin.expects(:gets).returns(
|
366
|
+
$stdin.expects(:gets).returns("git")
|
344
367
|
end
|
345
368
|
|
346
|
-
it
|
347
|
-
expect(dsl.fetch(:scm)).to eq
|
369
|
+
it "sets the input as the variable" do
|
370
|
+
expect(dsl.fetch(:scm)).to eq "git"
|
348
371
|
end
|
349
372
|
end
|
350
373
|
|
351
|
-
context
|
374
|
+
context "variable is not provided" do
|
352
375
|
before do
|
353
|
-
$stdin.expects(:gets).returns(
|
376
|
+
$stdin.expects(:gets).returns("")
|
354
377
|
end
|
355
378
|
|
356
|
-
it
|
379
|
+
it "sets the variable as the default" do
|
357
380
|
expect(dsl.fetch(:scm)).to eq :svn
|
358
381
|
end
|
359
382
|
end
|
360
383
|
end
|
361
384
|
|
362
|
-
describe
|
385
|
+
describe "checking for presence" do
|
363
386
|
subject { dsl.any? :linked_files }
|
364
387
|
|
365
388
|
before do
|
366
389
|
dsl.set(:linked_files, linked_files)
|
367
390
|
end
|
368
391
|
|
369
|
-
context
|
392
|
+
context "variable is an non-empty array" do
|
370
393
|
let(:linked_files) { %w{1} }
|
371
394
|
|
372
395
|
it { expect(subject).to be_truthy }
|
373
396
|
end
|
374
397
|
|
375
|
-
context
|
398
|
+
context "variable is an empty array" do
|
376
399
|
let(:linked_files) { [] }
|
377
400
|
it { expect(subject).to be_falsey }
|
378
401
|
end
|
379
402
|
|
380
|
-
context
|
403
|
+
context "variable exists, is not an array" do
|
381
404
|
let(:linked_files) { stub }
|
382
405
|
it { expect(subject).to be_truthy }
|
383
406
|
end
|
384
407
|
|
385
|
-
context
|
408
|
+
context "variable is nil" do
|
386
409
|
let(:linked_files) { nil }
|
387
410
|
it { expect(subject).to be_falsey }
|
388
411
|
end
|
389
412
|
end
|
390
413
|
|
391
|
-
describe
|
414
|
+
describe "configuration SSHKit" do
|
392
415
|
let(:config) { SSHKit.config }
|
393
416
|
let(:backend) { SSHKit.config.backend.config }
|
394
417
|
let(:default_env) { { rails_env: :production } }
|
@@ -399,185 +422,209 @@ describe Capistrano::DSL do
|
|
399
422
|
dsl.set(:default_env, default_env)
|
400
423
|
dsl.set(:pty, true)
|
401
424
|
dsl.set(:connection_timeout, 10)
|
402
|
-
dsl.set(:ssh_options,
|
403
|
-
|
404
|
-
|
405
|
-
auth_methods: %w(publickey password)
|
406
|
-
})
|
425
|
+
dsl.set(:ssh_options, keys: %w(/home/user/.ssh/id_rsa),
|
426
|
+
forward_agent: false,
|
427
|
+
auth_methods: %w(publickey password))
|
407
428
|
dsl.configure_backend
|
408
429
|
end
|
409
430
|
|
410
|
-
it
|
431
|
+
it "sets the output" do
|
411
432
|
expect(config.output).to be_a SSHKit::Formatter::Dot
|
412
433
|
end
|
413
434
|
|
414
|
-
it
|
435
|
+
it "sets the output verbosity" do
|
415
436
|
expect(config.output_verbosity).to eq 0
|
416
437
|
end
|
417
438
|
|
418
|
-
it
|
439
|
+
it "sets the default env" do
|
419
440
|
expect(config.default_env).to eq default_env
|
420
441
|
end
|
421
442
|
|
422
|
-
it
|
443
|
+
it "sets the backend pty" do
|
423
444
|
expect(backend.pty).to be_truthy
|
424
445
|
end
|
425
446
|
|
426
|
-
it
|
447
|
+
it "sets the backend connection timeout" do
|
427
448
|
expect(backend.connection_timeout).to eq 10
|
428
449
|
end
|
429
450
|
|
430
|
-
it
|
451
|
+
it "sets the backend ssh_options" do
|
431
452
|
expect(backend.ssh_options[:keys]).to eq %w(/home/user/.ssh/id_rsa)
|
432
453
|
expect(backend.ssh_options[:forward_agent]).to eq false
|
433
454
|
expect(backend.ssh_options[:auth_methods]).to eq %w(publickey password)
|
434
455
|
end
|
435
|
-
|
436
456
|
end
|
437
457
|
|
438
|
-
describe
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
458
|
+
describe "on()" do
|
459
|
+
describe "when passed server objects" do
|
460
|
+
before do
|
461
|
+
dsl.server "example1.com", roles: %w{web}, active: true
|
462
|
+
dsl.server "example2.com", roles: %w{web}
|
463
|
+
dsl.server "example3.com", roles: %w{app web}, active: true
|
464
|
+
dsl.server "example4.com", roles: %w{app}, primary: true
|
465
|
+
dsl.server "example5.com", roles: %w{db}, no_release: true
|
466
|
+
@coordinator = mock("coordinator")
|
467
|
+
@coordinator.expects(:each).returns(nil)
|
468
|
+
ENV.delete "ROLES"
|
469
|
+
ENV.delete "HOSTS"
|
470
|
+
end
|
445
471
|
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
472
|
+
it "filters by role from the :filter variable" do
|
473
|
+
hosts = dsl.roles(:web)
|
474
|
+
all = dsl.roles(:all)
|
475
|
+
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
476
|
+
dsl.set :filter, role: "web"
|
477
|
+
dsl.on(all)
|
478
|
+
end
|
450
479
|
|
451
|
-
|
452
|
-
|
453
|
-
|
480
|
+
it "filters by host and role from the :filter variable" do
|
481
|
+
all = dsl.roles(:all)
|
482
|
+
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
483
|
+
dsl.set :filter, role: "db", host: "example3.com"
|
484
|
+
dsl.on(all)
|
454
485
|
end
|
455
486
|
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
487
|
+
it "filters by roles from the :filter variable" do
|
488
|
+
hosts = dsl.roles(:web)
|
489
|
+
all = dsl.roles(:all)
|
490
|
+
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
491
|
+
dsl.set :filter, roles: "web"
|
492
|
+
dsl.on(all)
|
493
|
+
end
|
460
494
|
|
461
|
-
|
462
|
-
|
463
|
-
|
495
|
+
it "filters by hosts and roles from the :filter variable" do
|
496
|
+
all = dsl.roles(:all)
|
497
|
+
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
498
|
+
dsl.set :filter, roles: "db", hosts: "example3.com"
|
499
|
+
dsl.on(all)
|
464
500
|
end
|
465
|
-
end
|
466
|
-
end
|
467
501
|
|
468
|
-
|
502
|
+
it "filters from ENV[ROLES]" do
|
503
|
+
hosts = dsl.roles(:db)
|
504
|
+
all = dsl.roles(:all)
|
505
|
+
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
506
|
+
ENV["ROLES"] = "db"
|
507
|
+
dsl.on(all)
|
508
|
+
end
|
469
509
|
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
@coordinator.expects(:each).returns(nil)
|
478
|
-
ENV.delete 'ROLES'
|
479
|
-
ENV.delete 'HOSTS'
|
510
|
+
it "filters from ENV[HOSTS]" do
|
511
|
+
hosts = dsl.roles(:db)
|
512
|
+
all = dsl.roles(:all)
|
513
|
+
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
514
|
+
ENV["HOSTS"] = "example5.com"
|
515
|
+
dsl.on(all)
|
516
|
+
end
|
480
517
|
|
518
|
+
it "filters by ENV[HOSTS] && ENV[ROLES]" do
|
519
|
+
all = dsl.roles(:all)
|
520
|
+
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
521
|
+
ENV["HOSTS"] = "example5.com"
|
522
|
+
ENV["ROLES"] = "web"
|
523
|
+
dsl.on(all)
|
524
|
+
end
|
481
525
|
end
|
482
526
|
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
527
|
+
describe "when passed server literal names" do
|
528
|
+
before do
|
529
|
+
ENV.delete "ROLES"
|
530
|
+
ENV.delete "HOSTS"
|
531
|
+
@coordinator = mock("coordinator")
|
532
|
+
@coordinator.expects(:each).returns(nil)
|
533
|
+
end
|
490
534
|
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
end
|
535
|
+
it "selects nothing when a role filter is present" do
|
536
|
+
dsl.set :filter, role: "web"
|
537
|
+
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
538
|
+
dsl.on("my.server")
|
539
|
+
end
|
497
540
|
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
dsl.on(all)
|
504
|
-
end
|
541
|
+
it "selects using the string when a host filter is present" do
|
542
|
+
dsl.set :filter, host: "server.local"
|
543
|
+
SSHKit::Coordinator.expects(:new).with(["server.local"]).returns(@coordinator)
|
544
|
+
dsl.on("server.local")
|
545
|
+
end
|
505
546
|
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
dsl.on(all)
|
512
|
-
end
|
547
|
+
it "doesn't select when a host filter is present that doesn't match" do
|
548
|
+
dsl.set :filter, host: "ruby.local"
|
549
|
+
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
550
|
+
dsl.on("server.local")
|
551
|
+
end
|
513
552
|
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
dsl.on(all)
|
520
|
-
end
|
553
|
+
it "selects nothing when a roles filter is present" do
|
554
|
+
dsl.set :filter, roles: "web"
|
555
|
+
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
556
|
+
dsl.on("my.server")
|
557
|
+
end
|
521
558
|
|
522
|
-
|
559
|
+
it "selects using the string when a hosts filter is present" do
|
560
|
+
dsl.set :filter, hosts: "server.local"
|
561
|
+
SSHKit::Coordinator.expects(:new).with(["server.local"]).returns(@coordinator)
|
562
|
+
dsl.on("server.local")
|
563
|
+
end
|
523
564
|
|
524
|
-
|
565
|
+
it "doesn't select when a hosts filter is present that doesn't match" do
|
566
|
+
dsl.set :filter, hosts: "ruby.local"
|
567
|
+
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
568
|
+
dsl.on("server.local")
|
569
|
+
end
|
570
|
+
end
|
571
|
+
end
|
525
572
|
|
573
|
+
describe "role_properties()" do
|
526
574
|
before do
|
527
575
|
dsl.role :redis, %w[example1.com example2.com], redis: { port: 6379, type: :slave }
|
528
|
-
dsl.server
|
529
|
-
dsl.server
|
530
|
-
dsl.server
|
576
|
+
dsl.server "example1.com", roles: %w{web}, active: true, web: { port: 80 }
|
577
|
+
dsl.server "example2.com", roles: %w{web redis}, web: { port: 81 }, redis: { type: :master }
|
578
|
+
dsl.server "example3.com", roles: %w{app}, primary: true
|
531
579
|
end
|
532
580
|
|
533
|
-
it
|
581
|
+
it "retrieves properties for a single role as a set" do
|
534
582
|
rps = dsl.role_properties(:app)
|
535
|
-
expect(rps).to eq(Set[{ hostname:
|
583
|
+
expect(rps).to eq(Set[{ hostname: "example3.com", role: :app }])
|
536
584
|
end
|
537
585
|
|
538
|
-
it
|
586
|
+
it "retrieves properties for multiple roles as a set" do
|
539
587
|
rps = dsl.role_properties(:app, :web)
|
540
|
-
expect(rps).to eq(Set[{ hostname:
|
588
|
+
expect(rps).to eq(Set[{ hostname: "example3.com", role: :app }, { hostname: "example1.com", role: :web, port: 80 }, { hostname: "example2.com", role: :web, port: 81 }])
|
541
589
|
end
|
542
590
|
|
543
|
-
it
|
544
|
-
recipient = mock(
|
545
|
-
recipient.expects(:doit).with(
|
546
|
-
recipient.expects(:doit).with(
|
591
|
+
it "yields the properties for a single role" do
|
592
|
+
recipient = mock("recipient")
|
593
|
+
recipient.expects(:doit).with("example1.com", :redis, port: 6379, type: :slave)
|
594
|
+
recipient.expects(:doit).with("example2.com", :redis, port: 6379, type: :master)
|
547
595
|
dsl.role_properties(:redis) do |host, role, props|
|
548
596
|
recipient.doit(host, role, props)
|
549
597
|
end
|
550
598
|
end
|
551
599
|
|
552
|
-
it
|
553
|
-
recipient = mock(
|
554
|
-
recipient.expects(:doit).with(
|
555
|
-
recipient.expects(:doit).with(
|
556
|
-
recipient.expects(:doit).with(
|
600
|
+
it "yields the properties for multiple roles" do
|
601
|
+
recipient = mock("recipient")
|
602
|
+
recipient.expects(:doit).with("example1.com", :redis, port: 6379, type: :slave)
|
603
|
+
recipient.expects(:doit).with("example2.com", :redis, port: 6379, type: :master)
|
604
|
+
recipient.expects(:doit).with("example3.com", :app, nil)
|
557
605
|
dsl.role_properties(:redis, :app) do |host, role, props|
|
558
606
|
recipient.doit(host, role, props)
|
559
607
|
end
|
560
608
|
end
|
561
609
|
|
562
|
-
it
|
563
|
-
recipient = mock(
|
564
|
-
recipient.expects(:doit).with(
|
565
|
-
recipient.expects(:doit).with(
|
566
|
-
recipient.expects(:doit).with(
|
567
|
-
recipient.expects(:doit).with(
|
610
|
+
it "yields the merged properties for multiple roles" do
|
611
|
+
recipient = mock("recipient")
|
612
|
+
recipient.expects(:doit).with("example1.com", :redis, port: 6379, type: :slave)
|
613
|
+
recipient.expects(:doit).with("example2.com", :redis, port: 6379, type: :master)
|
614
|
+
recipient.expects(:doit).with("example1.com", :web, port: 80)
|
615
|
+
recipient.expects(:doit).with("example2.com", :web, port: 81)
|
568
616
|
dsl.role_properties(:redis, :web) do |host, role, props|
|
569
617
|
recipient.doit(host, role, props)
|
570
618
|
end
|
571
619
|
end
|
572
620
|
|
573
|
-
it
|
574
|
-
recipient = mock(
|
575
|
-
recipient.expects(:doit).with(
|
576
|
-
recipient.expects(:doit).with(
|
621
|
+
it "honours a property filter before yielding" do
|
622
|
+
recipient = mock("recipient")
|
623
|
+
recipient.expects(:doit).with("example1.com", :redis, port: 6379, type: :slave)
|
624
|
+
recipient.expects(:doit).with("example1.com", :web, port: 80)
|
577
625
|
dsl.role_properties(:redis, :web, select: :active) do |host, role, props|
|
578
626
|
recipient.doit(host, role, props)
|
579
627
|
end
|
580
628
|
end
|
581
629
|
end
|
582
|
-
|
583
630
|
end
|