capistrano 3.4.0 → 3.17.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +129 -0
- data/.github/issue_template.md +19 -0
- data/.github/pull_request_template.md +22 -0
- data/.github/release-drafter.yml +17 -0
- data/.github/workflows/push.yml +12 -0
- data/.gitignore +8 -5
- data/.rubocop.yml +62 -0
- data/CHANGELOG.md +1 -307
- data/CONTRIBUTING.md +63 -93
- data/DEVELOPMENT.md +127 -0
- data/Dangerfile +1 -0
- data/Gemfile +40 -3
- data/LICENSE.txt +1 -1
- data/README.md +127 -44
- data/RELEASING.md +17 -0
- data/Rakefile +13 -2
- data/UPGRADING-3.7.md +86 -0
- data/bin/cap +1 -1
- data/capistrano.gemspec +21 -24
- data/features/deploy.feature +35 -1
- data/features/doctor.feature +11 -0
- data/features/installation.feature +8 -3
- data/features/stage_failure.feature +9 -0
- data/features/step_definitions/assertions.rb +51 -18
- data/features/step_definitions/cap_commands.rb +9 -0
- data/features/step_definitions/setup.rb +53 -9
- data/features/subdirectory.feature +9 -0
- data/features/support/env.rb +5 -5
- data/features/support/remote_command_helpers.rb +12 -6
- data/features/support/vagrant_helpers.rb +17 -11
- data/lib/Capfile +1 -1
- data/lib/capistrano/all.rb +10 -10
- data/lib/capistrano/application.rb +47 -34
- data/lib/capistrano/configuration/empty_filter.rb +9 -0
- data/lib/capistrano/configuration/filter.rb +17 -47
- data/lib/capistrano/configuration/host_filter.rb +29 -0
- data/lib/capistrano/configuration/null_filter.rb +9 -0
- data/lib/capistrano/configuration/plugin_installer.rb +51 -0
- data/lib/capistrano/configuration/question.rb +31 -9
- data/lib/capistrano/configuration/role_filter.rb +29 -0
- data/lib/capistrano/configuration/scm_resolver.rb +149 -0
- data/lib/capistrano/configuration/server.rb +29 -23
- data/lib/capistrano/configuration/servers.rb +21 -14
- data/lib/capistrano/configuration/validated_variables.rb +110 -0
- data/lib/capistrano/configuration/variables.rb +112 -0
- data/lib/capistrano/configuration.rb +91 -44
- data/lib/capistrano/defaults.rb +26 -4
- data/lib/capistrano/deploy.rb +1 -1
- 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/servers_doctor.rb +105 -0
- data/lib/capistrano/doctor/variables_doctor.rb +74 -0
- data/lib/capistrano/doctor.rb +6 -0
- data/lib/capistrano/dotfile.rb +1 -2
- data/lib/capistrano/dsl/env.rb +9 -47
- data/lib/capistrano/dsl/paths.rb +11 -25
- data/lib/capistrano/dsl/stages.rb +14 -2
- data/lib/capistrano/dsl/task_enhancements.rb +7 -12
- data/lib/capistrano/dsl.rb +47 -16
- data/lib/capistrano/framework.rb +1 -1
- data/lib/capistrano/i18n.rb +32 -24
- data/lib/capistrano/immutable_task.rb +30 -0
- data/lib/capistrano/install.rb +1 -1
- data/lib/capistrano/plugin.rb +95 -0
- data/lib/capistrano/proc_helpers.rb +13 -0
- data/lib/capistrano/scm/git.rb +100 -0
- data/lib/capistrano/scm/hg.rb +55 -0
- data/lib/capistrano/scm/plugin.rb +13 -0
- data/lib/capistrano/scm/svn.rb +56 -0
- data/lib/capistrano/scm/tasks/git.rake +73 -0
- data/lib/capistrano/scm/tasks/hg.rake +53 -0
- data/lib/capistrano/scm/tasks/svn.rake +53 -0
- data/lib/capistrano/scm.rb +7 -20
- data/lib/capistrano/setup.rb +20 -6
- data/lib/capistrano/tasks/console.rake +4 -8
- data/lib/capistrano/tasks/deploy.rake +105 -73
- data/lib/capistrano/tasks/doctor.rake +24 -0
- data/lib/capistrano/tasks/framework.rake +13 -14
- data/lib/capistrano/tasks/install.rake +14 -15
- data/lib/capistrano/templates/Capfile +21 -10
- data/lib/capistrano/templates/deploy.rb.erb +17 -26
- data/lib/capistrano/templates/stage.rb.erb +9 -9
- data/lib/capistrano/upload_task.rb +1 -1
- data/lib/capistrano/version.rb +1 -1
- data/lib/capistrano/version_validator.rb +5 -10
- data/spec/integration/dsl_spec.rb +289 -240
- data/spec/integration_spec_helper.rb +3 -5
- data/spec/lib/capistrano/application_spec.rb +23 -39
- data/spec/lib/capistrano/configuration/empty_filter_spec.rb +17 -0
- data/spec/lib/capistrano/configuration/filter_spec.rb +83 -85
- data/spec/lib/capistrano/configuration/host_filter_spec.rb +71 -0
- data/spec/lib/capistrano/configuration/null_filter_spec.rb +17 -0
- data/spec/lib/capistrano/configuration/plugin_installer_spec.rb +98 -0
- data/spec/lib/capistrano/configuration/question_spec.rb +58 -26
- data/spec/lib/capistrano/configuration/role_filter_spec.rb +80 -0
- data/spec/lib/capistrano/configuration/scm_resolver_spec.rb +55 -0
- data/spec/lib/capistrano/configuration/server_spec.rb +106 -113
- data/spec/lib/capistrano/configuration/servers_spec.rb +129 -145
- data/spec/lib/capistrano/configuration_spec.rb +224 -63
- data/spec/lib/capistrano/doctor/environment_doctor_spec.rb +44 -0
- data/spec/lib/capistrano/doctor/gems_doctor_spec.rb +67 -0
- data/spec/lib/capistrano/doctor/output_helpers_spec.rb +47 -0
- data/spec/lib/capistrano/doctor/servers_doctor_spec.rb +86 -0
- data/spec/lib/capistrano/doctor/variables_doctor_spec.rb +89 -0
- data/spec/lib/capistrano/dsl/paths_spec.rb +97 -59
- data/spec/lib/capistrano/dsl/task_enhancements_spec.rb +57 -37
- data/spec/lib/capistrano/dsl_spec.rb +84 -11
- data/spec/lib/capistrano/immutable_task_spec.rb +31 -0
- data/spec/lib/capistrano/plugin_spec.rb +84 -0
- data/spec/lib/capistrano/scm/git_spec.rb +184 -0
- data/spec/lib/capistrano/scm/hg_spec.rb +109 -0
- data/spec/lib/capistrano/scm/svn_spec.rb +137 -0
- data/spec/lib/capistrano/scm_spec.rb +7 -8
- data/spec/lib/capistrano/upload_task_spec.rb +7 -7
- data/spec/lib/capistrano/version_validator_spec.rb +61 -46
- data/spec/lib/capistrano_spec.rb +2 -3
- data/spec/spec_helper.rb +21 -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 +64 -39
- metadata +100 -55
- data/.travis.yml +0 -13
- data/features/remote_file_task.feature +0 -14
- data/lib/capistrano/git.rb +0 -46
- data/lib/capistrano/hg.rb +0 -43
- data/lib/capistrano/svn.rb +0 -38
- data/lib/capistrano/tasks/git.rake +0 -81
- data/lib/capistrano/tasks/hg.rake +0 -52
- data/lib/capistrano/tasks/svn.rake +0 -52
- data/spec/lib/capistrano/git_spec.rb +0 -81
- data/spec/lib/capistrano/hg_spec.rb +0 -81
- data/spec/lib/capistrano/svn_spec.rb +0 -79
@@ -1,65 +1,62 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
module Capistrano
|
4
4
|
class Configuration
|
5
5
|
describe Servers do
|
6
6
|
let(:servers) { Servers.new }
|
7
7
|
|
8
|
-
describe
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
to change{servers.count}.from(0).to(2)
|
8
|
+
describe "adding a role" do
|
9
|
+
it "adds two new server instances" do
|
10
|
+
expect { servers.add_role(:app, %w{1 2}) }
|
11
|
+
.to change { servers.count }.from(0).to(2)
|
13
12
|
end
|
14
13
|
|
15
|
-
it
|
14
|
+
it "handles de-duplification within roles" do
|
16
15
|
servers.add_role(:app, %w{1})
|
17
16
|
servers.add_role(:app, %w{1})
|
18
17
|
expect(servers.count).to eq 1
|
19
18
|
end
|
20
19
|
|
21
|
-
it
|
22
|
-
servers.add_role(:app, %w{1}, user:
|
23
|
-
servers.add_role(:app, %w{1}, user:
|
20
|
+
it "handles de-duplification within roles with users" do
|
21
|
+
servers.add_role(:app, %w{1}, user: "nick")
|
22
|
+
servers.add_role(:app, %w{1}, user: "fred")
|
24
23
|
expect(servers.count).to eq 1
|
25
24
|
end
|
26
25
|
|
27
|
-
it
|
28
|
-
servers.add_role(:app, [Capistrano::Configuration::Server.new(
|
26
|
+
it "accepts instances of server objects" do
|
27
|
+
servers.add_role(:app, [Capistrano::Configuration::Server.new("example.net"), "example.com"])
|
29
28
|
expect(servers.roles_for([:app]).length).to eq 2
|
30
29
|
end
|
31
30
|
|
32
|
-
it
|
33
|
-
servers.add_role(:app,
|
31
|
+
it "accepts non-enumerable types" do
|
32
|
+
servers.add_role(:app, "1")
|
34
33
|
expect(servers.roles_for([:app]).count).to eq 1
|
35
34
|
end
|
36
35
|
|
37
|
-
it
|
38
|
-
servers.add_role(:db, %w{1 2}, db: { port: 1234 }
|
39
|
-
servers.add_host(
|
36
|
+
it "creates distinct server properties" do
|
37
|
+
servers.add_role(:db, %w{1 2}, db: { port: 1234 })
|
38
|
+
servers.add_host("1", db: { master: true })
|
40
39
|
expect(servers.count).to eq(2)
|
41
40
|
expect(servers.roles_for([:db]).count).to eq 2
|
42
|
-
expect(servers.find
|
43
|
-
expect(servers.find
|
41
|
+
expect(servers.find { |s| s.hostname == "1" }.properties.db).to eq(port: 1234, master: true)
|
42
|
+
expect(servers.find { |s| s.hostname == "2" }.properties.db).to eq(port: 1234)
|
44
43
|
end
|
45
|
-
|
46
44
|
end
|
47
45
|
|
48
|
-
describe
|
46
|
+
describe "adding a role to an existing server" do
|
49
47
|
before do
|
50
48
|
servers.add_role(:web, %w{1 2})
|
51
49
|
servers.add_role(:app, %w{1 2})
|
52
50
|
end
|
53
51
|
|
54
|
-
it
|
52
|
+
it "adds new roles to existing servers" do
|
55
53
|
expect(servers.count).to eq 2
|
56
54
|
end
|
57
|
-
|
58
55
|
end
|
59
56
|
|
60
|
-
describe
|
57
|
+
describe "collecting server roles" do
|
61
58
|
let(:app) { Set.new([:app]) }
|
62
|
-
let(:web_app) { Set.new(
|
59
|
+
let(:web_app) { Set.new(%i(web app)) }
|
63
60
|
let(:web) { Set.new([:web]) }
|
64
61
|
|
65
62
|
before do
|
@@ -67,280 +64,267 @@ module Capistrano
|
|
67
64
|
servers.add_role(:web, %w{2 3 4})
|
68
65
|
end
|
69
66
|
|
70
|
-
it
|
67
|
+
it "returns an array of the roles" do
|
71
68
|
expect(servers.roles_for([:app]).collect(&:roles)).to eq [app, web_app, web_app]
|
72
69
|
expect(servers.roles_for([:web]).collect(&:roles)).to eq [web_app, web_app, web]
|
73
70
|
end
|
74
71
|
end
|
75
72
|
|
76
|
-
describe
|
73
|
+
describe "finding the primary server" do
|
77
74
|
after do
|
78
75
|
Configuration.reset!
|
79
76
|
end
|
80
|
-
it
|
77
|
+
it "takes the first server if none have the primary property" do
|
81
78
|
servers.add_role(:app, %w{1 2})
|
82
|
-
expect(servers.fetch_primary(:app).hostname).to eq(
|
79
|
+
expect(servers.fetch_primary(:app).hostname).to eq("1")
|
83
80
|
end
|
84
81
|
|
85
|
-
it
|
82
|
+
it "takes the first server with the primary have the primary flag" do
|
86
83
|
servers.add_role(:app, %w{1 2})
|
87
|
-
servers.add_host(
|
88
|
-
expect(servers.fetch_primary(:app).hostname).to eq(
|
84
|
+
servers.add_host("2", primary: true)
|
85
|
+
expect(servers.fetch_primary(:app).hostname).to eq("2")
|
89
86
|
end
|
90
87
|
|
91
|
-
it
|
92
|
-
Configuration.env.set :filter,
|
88
|
+
it "ignores any on_filters" do
|
89
|
+
Configuration.env.set :filter, host: "1"
|
93
90
|
servers.add_role(:app, %w{1 2})
|
94
|
-
servers.add_host(
|
95
|
-
expect(servers.fetch_primary(:app).hostname).to eq(
|
91
|
+
servers.add_host("2", primary: true)
|
92
|
+
expect(servers.fetch_primary(:app).hostname).to eq("2")
|
96
93
|
end
|
97
94
|
end
|
98
95
|
|
99
|
-
describe
|
96
|
+
describe "fetching servers" do
|
100
97
|
before do
|
101
98
|
servers.add_role(:app, %w{1 2})
|
102
99
|
servers.add_role(:web, %w{2 3})
|
103
100
|
end
|
104
101
|
|
105
|
-
it
|
102
|
+
it "returns the correct app servers" do
|
106
103
|
expect(servers.roles_for([:app]).map(&:hostname)).to eq %w{1 2}
|
107
104
|
end
|
108
105
|
|
109
|
-
it
|
106
|
+
it "returns the correct web servers" do
|
110
107
|
expect(servers.roles_for([:web]).map(&:hostname)).to eq %w{2 3}
|
111
108
|
end
|
112
109
|
|
113
|
-
it
|
114
|
-
expect(servers.roles_for(
|
110
|
+
it "returns the correct app and web servers" do
|
111
|
+
expect(servers.roles_for(%i(app web)).map(&:hostname)).to eq %w{1 2 3}
|
115
112
|
end
|
116
113
|
|
117
|
-
it
|
114
|
+
it "returns all servers" do
|
118
115
|
expect(servers.roles_for([:all]).map(&:hostname)).to eq %w{1 2 3}
|
119
116
|
end
|
120
117
|
end
|
121
118
|
|
122
|
-
describe
|
123
|
-
|
119
|
+
describe "adding a server" do
|
124
120
|
before do
|
125
|
-
servers.add_host(
|
121
|
+
servers.add_host("1", roles: [:app, "web"], test: :value)
|
126
122
|
end
|
127
123
|
|
128
|
-
it
|
129
|
-
expect(servers.roles_for([:app]).first.hostname).to eq
|
130
|
-
expect(servers.roles_for([:web]).first.hostname).to eq
|
124
|
+
it "can create a server with properties" do
|
125
|
+
expect(servers.roles_for([:app]).first.hostname).to eq "1"
|
126
|
+
expect(servers.roles_for([:web]).first.hostname).to eq "1"
|
131
127
|
expect(servers.roles_for([:all]).first.properties.test).to eq :value
|
132
128
|
expect(servers.roles_for([:all]).first.properties.keys).to eq [:test]
|
133
129
|
end
|
134
130
|
|
135
|
-
it
|
136
|
-
servers.add_host(
|
137
|
-
servers.
|
138
|
-
servers.add_host(
|
139
|
-
servers.add_host(
|
140
|
-
servers.add_host(
|
141
|
-
servers.add_host(
|
142
|
-
servers.add_host(
|
143
|
-
|
131
|
+
it "can accept multiple servers with the same hostname but different ports or users" do
|
132
|
+
servers.add_host("1", roles: [:app, "web"], test: :value, port: 12)
|
133
|
+
expect(servers.count).to eq(2)
|
134
|
+
servers.add_host("1", roles: [:app, "web"], test: :value, port: 34)
|
135
|
+
servers.add_host("1", roles: [:app, "web"], test: :value, user: "root")
|
136
|
+
servers.add_host("1", roles: [:app, "web"], test: :value, user: "deployer")
|
137
|
+
servers.add_host("1", roles: [:app, "web"], test: :value, user: "root", port: 34)
|
138
|
+
servers.add_host("1", roles: [:app, "web"], test: :value, user: "deployer", port: 34)
|
139
|
+
servers.add_host("1", roles: [:app, "web"], test: :value, user: "deployer", port: 56)
|
140
|
+
expect(servers.count).to eq(4)
|
144
141
|
end
|
145
142
|
|
146
143
|
describe "with a :user property" do
|
147
|
-
|
148
|
-
|
149
|
-
servers.add_host('1', roles: [:app, 'web'], user: 'nick')
|
144
|
+
it "sets the server ssh username" do
|
145
|
+
servers.add_host("1", roles: [:app, "web"], user: "nick")
|
150
146
|
expect(servers.count).to eq(1)
|
151
|
-
expect(servers.roles_for([:all]).first.user).to eq
|
147
|
+
expect(servers.roles_for([:all]).first.user).to eq "nick"
|
152
148
|
end
|
153
149
|
|
154
|
-
it
|
155
|
-
servers.add_host(
|
150
|
+
it "overwrites the value of a user specified in the hostname" do
|
151
|
+
servers.add_host("brian@1", roles: [:app, "web"], user: "nick")
|
156
152
|
expect(servers.count).to eq(1)
|
157
|
-
expect(servers.roles_for([:all]).first.user).to eq
|
153
|
+
expect(servers.roles_for([:all]).first.user).to eq "nick"
|
158
154
|
end
|
159
|
-
|
160
155
|
end
|
161
156
|
|
162
|
-
it
|
163
|
-
servers.add_host(
|
157
|
+
it "overwrites the value of a previously defined scalar property" do
|
158
|
+
servers.add_host("1", roles: [:app, "web"], test: :volatile)
|
164
159
|
expect(servers.count).to eq(1)
|
165
160
|
expect(servers.roles_for([:all]).first.properties.test).to eq :volatile
|
166
161
|
end
|
167
162
|
|
168
|
-
it
|
169
|
-
servers.add_host(
|
170
|
-
servers.add_host(
|
163
|
+
it "merges previously defined hash properties" do
|
164
|
+
servers.add_host("1", roles: [:b], db: { port: 1234 })
|
165
|
+
servers.add_host("1", roles: [:b], db: { master: true })
|
171
166
|
expect(servers.count).to eq(1)
|
172
|
-
expect(servers.roles_for([:b]).first.properties.db).to eq(
|
167
|
+
expect(servers.roles_for([:b]).first.properties.db).to eq(port: 1234, master: true)
|
173
168
|
end
|
174
169
|
|
175
|
-
it
|
176
|
-
servers.add_host(
|
177
|
-
servers.add_host(
|
170
|
+
it "concatenates previously defined array properties" do
|
171
|
+
servers.add_host("1", roles: [:b], steps: [1, 3, 5])
|
172
|
+
servers.add_host("1", roles: [:b], steps: [1, 9])
|
178
173
|
expect(servers.count).to eq(1)
|
179
|
-
expect(servers.roles_for([:b]).first.properties.steps).to eq([1,3,5,1,9])
|
174
|
+
expect(servers.roles_for([:b]).first.properties.steps).to eq([1, 3, 5, 1, 9])
|
180
175
|
end
|
181
176
|
|
182
|
-
it
|
183
|
-
servers.add_host(
|
184
|
-
servers.add_host(
|
177
|
+
it "merges previously defined set properties" do
|
178
|
+
servers.add_host("1", roles: [:b], endpoints: Set[123, 333])
|
179
|
+
servers.add_host("1", roles: [:b], endpoints: Set[222, 333])
|
185
180
|
expect(servers.count).to eq(1)
|
186
|
-
expect(servers.roles_for([:b]).first.properties.endpoints).to eq(Set[123,222,333])
|
181
|
+
expect(servers.roles_for([:b]).first.properties.endpoints).to eq(Set[123, 222, 333])
|
187
182
|
end
|
188
183
|
|
189
|
-
it
|
190
|
-
servers.add_host(
|
191
|
-
expect(servers.roles_for([:array_test]).first.properties.array_property).to eq [1,2]
|
184
|
+
it "adds array property value only ones for a new host" do
|
185
|
+
servers.add_host("2", roles: [:array_test], array_property: [1, 2])
|
186
|
+
expect(servers.roles_for([:array_test]).first.properties.array_property).to eq [1, 2]
|
192
187
|
end
|
193
188
|
|
194
|
-
it
|
195
|
-
servers.add_host(
|
196
|
-
servers.add_host(
|
197
|
-
expect(servers.roles_for([:foo]).first.hostname).to eq
|
198
|
-
expect(servers.roles_for([:bar]).first.hostname).to eq
|
189
|
+
it "updates roles when custom user defined" do
|
190
|
+
servers.add_host("1", roles: ["foo"], user: "custom")
|
191
|
+
servers.add_host("1", roles: ["bar"], user: "custom")
|
192
|
+
expect(servers.roles_for([:foo]).first.hostname).to eq "1"
|
193
|
+
expect(servers.roles_for([:bar]).first.hostname).to eq "1"
|
199
194
|
end
|
200
195
|
|
201
|
-
it
|
202
|
-
servers.add_host(
|
203
|
-
servers.add_host(
|
204
|
-
expect(servers.roles_for([:foo]).first.hostname).to eq
|
205
|
-
expect(servers.roles_for([:bar]).first.hostname).to eq
|
196
|
+
it "updates roles when custom port defined" do
|
197
|
+
servers.add_host("1", roles: ["foo"], port: 1234)
|
198
|
+
servers.add_host("1", roles: ["bar"], port: 1234)
|
199
|
+
expect(servers.roles_for([:foo]).first.hostname).to eq "1"
|
200
|
+
expect(servers.roles_for([:bar]).first.hostname).to eq "1"
|
206
201
|
end
|
207
|
-
|
208
202
|
end
|
209
203
|
|
210
|
-
describe
|
211
|
-
|
204
|
+
describe "selecting roles" do
|
212
205
|
before do
|
213
|
-
servers.add_host(
|
214
|
-
servers.add_host(
|
206
|
+
servers.add_host("1", roles: :app, active: true)
|
207
|
+
servers.add_host("2", roles: :app)
|
215
208
|
end
|
216
209
|
|
217
|
-
it
|
210
|
+
it "is empty if the filter would remove all matching hosts" do
|
218
211
|
expect(servers.roles_for([:app, select: :inactive])).to be_empty
|
219
212
|
end
|
220
213
|
|
221
|
-
it
|
214
|
+
it "can filter hosts by properties on the host object using symbol as shorthand" do
|
222
215
|
expect(servers.roles_for([:app, filter: :active]).length).to eq 1
|
223
216
|
end
|
224
217
|
|
225
|
-
it
|
218
|
+
it "can select hosts by properties on the host object using symbol as shorthand" do
|
226
219
|
expect(servers.roles_for([:app, select: :active]).length).to eq 1
|
227
220
|
end
|
228
221
|
|
229
|
-
it
|
222
|
+
it "can filter hosts by properties on the host using a regular proc" do
|
230
223
|
expect(servers.roles_for([:app, filter: ->(h) { h.properties.active }]).length).to eq 1
|
231
224
|
end
|
232
225
|
|
233
|
-
it
|
226
|
+
it "can select hosts by properties on the host using a regular proc" do
|
234
227
|
expect(servers.roles_for([:app, select: ->(h) { h.properties.active }]).length).to eq 1
|
235
228
|
end
|
236
229
|
|
237
|
-
it
|
230
|
+
it "is empty if the regular proc filter would remove all matching hosts" do
|
238
231
|
expect(servers.roles_for([:app, select: ->(h) { h.properties.inactive }])).to be_empty
|
239
232
|
end
|
240
|
-
|
241
233
|
end
|
242
234
|
|
243
|
-
describe
|
244
|
-
|
235
|
+
describe "excluding by property" do
|
245
236
|
before do
|
246
|
-
servers.add_host(
|
247
|
-
servers.add_host(
|
237
|
+
servers.add_host("1", roles: :app, active: true)
|
238
|
+
servers.add_host("2", roles: :app, active: true, no_release: true)
|
248
239
|
end
|
249
240
|
|
250
|
-
it
|
241
|
+
it "is empty if the filter would remove all matching hosts" do
|
251
242
|
hosts = servers.roles_for([:app, exclude: :active])
|
252
243
|
expect(hosts.map(&:hostname)).to be_empty
|
253
244
|
end
|
254
245
|
|
255
|
-
it
|
246
|
+
it "returns the servers without the attributes specified" do
|
256
247
|
hosts = servers.roles_for([:app, exclude: :no_release])
|
257
248
|
expect(hosts.map(&:hostname)).to eq %w{1}
|
258
249
|
end
|
259
250
|
|
260
|
-
it
|
251
|
+
it "can exclude hosts by properties on the host using a regular proc" do
|
261
252
|
hosts = servers.roles_for([:app, exclude: ->(h) { h.properties.no_release }])
|
262
253
|
expect(hosts.map(&:hostname)).to eq %w{1}
|
263
254
|
end
|
264
255
|
|
265
|
-
it
|
256
|
+
it "is empty if the regular proc filter would remove all matching hosts" do
|
266
257
|
hosts = servers.roles_for([:app, exclude: ->(h) { h.properties.active }])
|
267
258
|
expect(hosts.map(&:hostname)).to be_empty
|
268
259
|
end
|
269
|
-
|
270
260
|
end
|
271
261
|
|
272
|
-
describe
|
273
|
-
|
262
|
+
describe "filtering roles internally" do
|
274
263
|
before do
|
275
|
-
servers.add_host(
|
276
|
-
servers.add_host(
|
277
|
-
servers.add_host(
|
278
|
-
servers.add_host(
|
279
|
-
servers.add_host(
|
264
|
+
servers.add_host("1", roles: :app, active: true)
|
265
|
+
servers.add_host("2", roles: :app)
|
266
|
+
servers.add_host("3", roles: :web)
|
267
|
+
servers.add_host("4", roles: :web)
|
268
|
+
servers.add_host("5", roles: :db)
|
280
269
|
end
|
281
270
|
|
282
271
|
subject { servers.roles_for(roles).map(&:hostname) }
|
283
272
|
|
284
|
-
context
|
285
|
-
|
273
|
+
context "with the ROLES environment variable set" do
|
286
274
|
before do
|
287
|
-
ENV.stubs(:[]).with(
|
288
|
-
ENV.stubs(:[]).with(
|
275
|
+
ENV.stubs(:[]).with("ROLES").returns("web,db")
|
276
|
+
ENV.stubs(:[]).with("HOSTS").returns(nil)
|
289
277
|
end
|
290
278
|
|
291
|
-
context
|
279
|
+
context "when selecting all roles" do
|
292
280
|
let(:roles) { [:all] }
|
293
|
-
it
|
281
|
+
it "ignores it" do
|
294
282
|
expect(subject).to eq %w{1 2 3 4 5}
|
295
283
|
end
|
296
284
|
end
|
297
285
|
|
298
|
-
context
|
299
|
-
let(:roles) {
|
300
|
-
it
|
286
|
+
context "when selecting specific roles" do
|
287
|
+
let(:roles) { %i(app web) }
|
288
|
+
it "ignores it" do
|
301
289
|
expect(subject).to eq %w{1 2 3 4}
|
302
290
|
end
|
303
291
|
end
|
304
292
|
|
305
|
-
context
|
293
|
+
context "when selecting roles not included in ROLE" do
|
306
294
|
let(:roles) { [:app] }
|
307
|
-
it
|
295
|
+
it "ignores it" do
|
308
296
|
expect(subject).to eq %w{1 2}
|
309
297
|
end
|
310
298
|
end
|
311
|
-
|
312
299
|
end
|
313
300
|
|
314
|
-
context
|
315
|
-
|
301
|
+
context "with the HOSTS environment variable set" do
|
316
302
|
before do
|
317
|
-
ENV.stubs(:[]).with(
|
318
|
-
ENV.stubs(:[]).with(
|
303
|
+
ENV.stubs(:[]).with("ROLES").returns(nil)
|
304
|
+
ENV.stubs(:[]).with("HOSTS").returns("3,5")
|
319
305
|
end
|
320
306
|
|
321
|
-
context
|
307
|
+
context "when selecting all roles" do
|
322
308
|
let(:roles) { [:all] }
|
323
|
-
it
|
309
|
+
it "ignores it" do
|
324
310
|
expect(subject).to eq %w{1 2 3 4 5}
|
325
311
|
end
|
326
312
|
end
|
327
313
|
|
328
|
-
context
|
329
|
-
let(:roles) {
|
330
|
-
it
|
314
|
+
context "when selecting specific roles" do
|
315
|
+
let(:roles) { %i(app web) }
|
316
|
+
it "ignores it" do
|
331
317
|
expect(subject).to eq %w{1 2 3 4}
|
332
318
|
end
|
333
319
|
end
|
334
320
|
|
335
|
-
context
|
321
|
+
context "when selecting no roles" do
|
336
322
|
let(:roles) { [] }
|
337
|
-
it
|
323
|
+
it "ignores it" do
|
338
324
|
expect(subject).to be_empty
|
339
325
|
end
|
340
326
|
end
|
341
|
-
|
342
327
|
end
|
343
|
-
|
344
328
|
end
|
345
329
|
end
|
346
330
|
end
|