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
@@ -1,63 +1,60 @@
|
|
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
59
|
let(:web_app) { Set.new([:web, :app]) }
|
63
60
|
let(:web) { Set.new([:web]) }
|
@@ -67,280 +64,266 @@ 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
|
110
|
+
it "returns the correct app and web servers" do
|
114
111
|
expect(servers.roles_for([: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.add_host(
|
138
|
-
servers.add_host(
|
139
|
-
servers.add_host(
|
140
|
-
servers.add_host(
|
141
|
-
servers.add_host(
|
142
|
-
servers.add_host(
|
143
|
-
expect(servers.count).to eq(
|
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
|
+
servers.add_host("1", roles: [:app, "web"], test: :value, port: 34)
|
134
|
+
servers.add_host("1", roles: [:app, "web"], test: :value, user: "root")
|
135
|
+
servers.add_host("1", roles: [:app, "web"], test: :value, user: "deployer")
|
136
|
+
servers.add_host("1", roles: [:app, "web"], test: :value, user: "root", port: 34)
|
137
|
+
servers.add_host("1", roles: [:app, "web"], test: :value, user: "deployer", port: 34)
|
138
|
+
servers.add_host("1", roles: [:app, "web"], test: :value, user: "deployer", port: 56)
|
139
|
+
expect(servers.count).to eq(5)
|
144
140
|
end
|
145
141
|
|
146
142
|
describe "with a :user property" do
|
147
|
-
|
148
|
-
|
149
|
-
servers.add_host('1', roles: [:app, 'web'], user: 'nick')
|
143
|
+
it "sets the server ssh username" do
|
144
|
+
servers.add_host("1", roles: [:app, "web"], user: "nick")
|
150
145
|
expect(servers.count).to eq(1)
|
151
|
-
expect(servers.roles_for([:all]).first.user).to eq
|
146
|
+
expect(servers.roles_for([:all]).first.user).to eq "nick"
|
152
147
|
end
|
153
148
|
|
154
|
-
it
|
155
|
-
servers.add_host(
|
149
|
+
it "overwrites the value of a user specified in the hostname" do
|
150
|
+
servers.add_host("brian@1", roles: [:app, "web"], user: "nick")
|
156
151
|
expect(servers.count).to eq(1)
|
157
|
-
expect(servers.roles_for([:all]).first.user).to eq
|
152
|
+
expect(servers.roles_for([:all]).first.user).to eq "nick"
|
158
153
|
end
|
159
|
-
|
160
154
|
end
|
161
155
|
|
162
|
-
it
|
163
|
-
servers.add_host(
|
156
|
+
it "overwrites the value of a previously defined scalar property" do
|
157
|
+
servers.add_host("1", roles: [:app, "web"], test: :volatile)
|
164
158
|
expect(servers.count).to eq(1)
|
165
159
|
expect(servers.roles_for([:all]).first.properties.test).to eq :volatile
|
166
160
|
end
|
167
161
|
|
168
|
-
it
|
169
|
-
servers.add_host(
|
170
|
-
servers.add_host(
|
162
|
+
it "merges previously defined hash properties" do
|
163
|
+
servers.add_host("1", roles: [:b], db: { port: 1234 })
|
164
|
+
servers.add_host("1", roles: [:b], db: { master: true })
|
171
165
|
expect(servers.count).to eq(1)
|
172
|
-
expect(servers.roles_for([:b]).first.properties.db).to eq(
|
166
|
+
expect(servers.roles_for([:b]).first.properties.db).to eq(port: 1234, master: true)
|
173
167
|
end
|
174
168
|
|
175
|
-
it
|
176
|
-
servers.add_host(
|
177
|
-
servers.add_host(
|
169
|
+
it "concatenates previously defined array properties" do
|
170
|
+
servers.add_host("1", roles: [:b], steps: [1, 3, 5])
|
171
|
+
servers.add_host("1", roles: [:b], steps: [1, 9])
|
178
172
|
expect(servers.count).to eq(1)
|
179
|
-
expect(servers.roles_for([:b]).first.properties.steps).to eq([1,3,5,1,9])
|
173
|
+
expect(servers.roles_for([:b]).first.properties.steps).to eq([1, 3, 5, 1, 9])
|
180
174
|
end
|
181
175
|
|
182
|
-
it
|
183
|
-
servers.add_host(
|
184
|
-
servers.add_host(
|
176
|
+
it "merges previously defined set properties" do
|
177
|
+
servers.add_host("1", roles: [:b], endpoints: Set[123, 333])
|
178
|
+
servers.add_host("1", roles: [:b], endpoints: Set[222, 333])
|
185
179
|
expect(servers.count).to eq(1)
|
186
|
-
expect(servers.roles_for([:b]).first.properties.endpoints).to eq(Set[123,222,333])
|
180
|
+
expect(servers.roles_for([:b]).first.properties.endpoints).to eq(Set[123, 222, 333])
|
187
181
|
end
|
188
182
|
|
189
|
-
it
|
190
|
-
servers.add_host(
|
191
|
-
expect(servers.roles_for([:array_test]).first.properties.array_property).to eq [1,2]
|
183
|
+
it "adds array property value only ones for a new host" do
|
184
|
+
servers.add_host("2", roles: [:array_test], array_property: [1, 2])
|
185
|
+
expect(servers.roles_for([:array_test]).first.properties.array_property).to eq [1, 2]
|
192
186
|
end
|
193
187
|
|
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
|
188
|
+
it "updates roles when custom user defined" do
|
189
|
+
servers.add_host("1", roles: ["foo"], user: "custom")
|
190
|
+
servers.add_host("1", roles: ["bar"], user: "custom")
|
191
|
+
expect(servers.roles_for([:foo]).first.hostname).to eq "1"
|
192
|
+
expect(servers.roles_for([:bar]).first.hostname).to eq "1"
|
199
193
|
end
|
200
194
|
|
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
|
195
|
+
it "updates roles when custom port defined" do
|
196
|
+
servers.add_host("1", roles: ["foo"], port: 1234)
|
197
|
+
servers.add_host("1", roles: ["bar"], port: 1234)
|
198
|
+
expect(servers.roles_for([:foo]).first.hostname).to eq "1"
|
199
|
+
expect(servers.roles_for([:bar]).first.hostname).to eq "1"
|
206
200
|
end
|
207
|
-
|
208
201
|
end
|
209
202
|
|
210
|
-
describe
|
211
|
-
|
203
|
+
describe "selecting roles" do
|
212
204
|
before do
|
213
|
-
servers.add_host(
|
214
|
-
servers.add_host(
|
205
|
+
servers.add_host("1", roles: :app, active: true)
|
206
|
+
servers.add_host("2", roles: :app)
|
215
207
|
end
|
216
208
|
|
217
|
-
it
|
209
|
+
it "is empty if the filter would remove all matching hosts" do
|
218
210
|
expect(servers.roles_for([:app, select: :inactive])).to be_empty
|
219
211
|
end
|
220
212
|
|
221
|
-
it
|
213
|
+
it "can filter hosts by properties on the host object using symbol as shorthand" do
|
222
214
|
expect(servers.roles_for([:app, filter: :active]).length).to eq 1
|
223
215
|
end
|
224
216
|
|
225
|
-
it
|
217
|
+
it "can select hosts by properties on the host object using symbol as shorthand" do
|
226
218
|
expect(servers.roles_for([:app, select: :active]).length).to eq 1
|
227
219
|
end
|
228
220
|
|
229
|
-
it
|
221
|
+
it "can filter hosts by properties on the host using a regular proc" do
|
230
222
|
expect(servers.roles_for([:app, filter: ->(h) { h.properties.active }]).length).to eq 1
|
231
223
|
end
|
232
224
|
|
233
|
-
it
|
225
|
+
it "can select hosts by properties on the host using a regular proc" do
|
234
226
|
expect(servers.roles_for([:app, select: ->(h) { h.properties.active }]).length).to eq 1
|
235
227
|
end
|
236
228
|
|
237
|
-
it
|
229
|
+
it "is empty if the regular proc filter would remove all matching hosts" do
|
238
230
|
expect(servers.roles_for([:app, select: ->(h) { h.properties.inactive }])).to be_empty
|
239
231
|
end
|
240
|
-
|
241
232
|
end
|
242
233
|
|
243
|
-
describe
|
244
|
-
|
234
|
+
describe "excluding by property" do
|
245
235
|
before do
|
246
|
-
servers.add_host(
|
247
|
-
servers.add_host(
|
236
|
+
servers.add_host("1", roles: :app, active: true)
|
237
|
+
servers.add_host("2", roles: :app, active: true, no_release: true)
|
248
238
|
end
|
249
239
|
|
250
|
-
it
|
240
|
+
it "is empty if the filter would remove all matching hosts" do
|
251
241
|
hosts = servers.roles_for([:app, exclude: :active])
|
252
242
|
expect(hosts.map(&:hostname)).to be_empty
|
253
243
|
end
|
254
244
|
|
255
|
-
it
|
245
|
+
it "returns the servers without the attributes specified" do
|
256
246
|
hosts = servers.roles_for([:app, exclude: :no_release])
|
257
247
|
expect(hosts.map(&:hostname)).to eq %w{1}
|
258
248
|
end
|
259
249
|
|
260
|
-
it
|
250
|
+
it "can exclude hosts by properties on the host using a regular proc" do
|
261
251
|
hosts = servers.roles_for([:app, exclude: ->(h) { h.properties.no_release }])
|
262
252
|
expect(hosts.map(&:hostname)).to eq %w{1}
|
263
253
|
end
|
264
254
|
|
265
|
-
it
|
255
|
+
it "is empty if the regular proc filter would remove all matching hosts" do
|
266
256
|
hosts = servers.roles_for([:app, exclude: ->(h) { h.properties.active }])
|
267
257
|
expect(hosts.map(&:hostname)).to be_empty
|
268
258
|
end
|
269
|
-
|
270
259
|
end
|
271
260
|
|
272
|
-
describe
|
273
|
-
|
261
|
+
describe "filtering roles internally" do
|
274
262
|
before do
|
275
|
-
servers.add_host(
|
276
|
-
servers.add_host(
|
277
|
-
servers.add_host(
|
278
|
-
servers.add_host(
|
279
|
-
servers.add_host(
|
263
|
+
servers.add_host("1", roles: :app, active: true)
|
264
|
+
servers.add_host("2", roles: :app)
|
265
|
+
servers.add_host("3", roles: :web)
|
266
|
+
servers.add_host("4", roles: :web)
|
267
|
+
servers.add_host("5", roles: :db)
|
280
268
|
end
|
281
269
|
|
282
270
|
subject { servers.roles_for(roles).map(&:hostname) }
|
283
271
|
|
284
|
-
context
|
285
|
-
|
272
|
+
context "with the ROLES environment variable set" do
|
286
273
|
before do
|
287
|
-
ENV.stubs(:[]).with(
|
288
|
-
ENV.stubs(:[]).with(
|
274
|
+
ENV.stubs(:[]).with("ROLES").returns("web,db")
|
275
|
+
ENV.stubs(:[]).with("HOSTS").returns(nil)
|
289
276
|
end
|
290
277
|
|
291
|
-
context
|
278
|
+
context "when selecting all roles" do
|
292
279
|
let(:roles) { [:all] }
|
293
|
-
it
|
280
|
+
it "ignores it" do
|
294
281
|
expect(subject).to eq %w{1 2 3 4 5}
|
295
282
|
end
|
296
283
|
end
|
297
284
|
|
298
|
-
context
|
285
|
+
context "when selecting specific roles" do
|
299
286
|
let(:roles) { [:app, :web] }
|
300
|
-
it
|
287
|
+
it "ignores it" do
|
301
288
|
expect(subject).to eq %w{1 2 3 4}
|
302
289
|
end
|
303
290
|
end
|
304
291
|
|
305
|
-
context
|
292
|
+
context "when selecting roles not included in ROLE" do
|
306
293
|
let(:roles) { [:app] }
|
307
|
-
it
|
294
|
+
it "ignores it" do
|
308
295
|
expect(subject).to eq %w{1 2}
|
309
296
|
end
|
310
297
|
end
|
311
|
-
|
312
298
|
end
|
313
299
|
|
314
|
-
context
|
315
|
-
|
300
|
+
context "with the HOSTS environment variable set" do
|
316
301
|
before do
|
317
|
-
ENV.stubs(:[]).with(
|
318
|
-
ENV.stubs(:[]).with(
|
302
|
+
ENV.stubs(:[]).with("ROLES").returns(nil)
|
303
|
+
ENV.stubs(:[]).with("HOSTS").returns("3,5")
|
319
304
|
end
|
320
305
|
|
321
|
-
context
|
306
|
+
context "when selecting all roles" do
|
322
307
|
let(:roles) { [:all] }
|
323
|
-
it
|
308
|
+
it "ignores it" do
|
324
309
|
expect(subject).to eq %w{1 2 3 4 5}
|
325
310
|
end
|
326
311
|
end
|
327
312
|
|
328
|
-
context
|
313
|
+
context "when selecting specific roles" do
|
329
314
|
let(:roles) { [:app, :web] }
|
330
|
-
it
|
315
|
+
it "ignores it" do
|
331
316
|
expect(subject).to eq %w{1 2 3 4}
|
332
317
|
end
|
333
318
|
end
|
334
319
|
|
335
|
-
context
|
320
|
+
context "when selecting no roles" do
|
336
321
|
let(:roles) { [] }
|
337
|
-
it
|
322
|
+
it "ignores it" do
|
338
323
|
expect(subject).to be_empty
|
339
324
|
end
|
340
325
|
end
|
341
|
-
|
342
326
|
end
|
343
|
-
|
344
327
|
end
|
345
328
|
end
|
346
329
|
end
|