plow 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/.yardopts +6 -0
- data/HISTORY +39 -0
- data/LICENSE +20 -0
- data/README.markdown +152 -0
- data/ROAD-MAP +10 -0
- data/Rakefile +52 -0
- data/SECURITY +14 -0
- data/VERSION +1 -0
- data/bin/plow +10 -0
- data/bin/plow1.9 +10 -0
- data/lib/plow/application.rb +66 -0
- data/lib/plow/binding_struct.rb +15 -0
- data/lib/plow/core_ext/object.rb +8 -0
- data/lib/plow/errors.rb +27 -0
- data/lib/plow/generator.rb +57 -0
- data/lib/plow/strategy/ubuntu_hardy/templates/README.txt +19 -0
- data/lib/plow/strategy/ubuntu_hardy/templates/apache2-vhost.conf +14 -0
- data/lib/plow/strategy/ubuntu_hardy/user_home_web_app.rb +304 -0
- data/lib/plow.rb +18 -0
- data/spec/fixtures/passwd.txt +27 -0
- data/spec/fixtures/vhost.conf +3 -0
- data/spec/plow/application_spec.rb +241 -0
- data/spec/plow/binding_struct_spec.rb +38 -0
- data/spec/plow/errors_spec.rb +36 -0
- data/spec/plow/generator_spec.rb +160 -0
- data/spec/plow/strategy/ubuntu_hardy/user_home_web_app_spec.rb +561 -0
- data/spec/plow_spec.rb +19 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +29 -0
- metadata +121 -0
@@ -0,0 +1,561 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
3
|
+
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
describe Plow::Strategy::UbuntuHardy::UserHomeWebApp do
|
7
|
+
before(:each) do
|
8
|
+
@context = Plow::Generator.new('steve', 'www.apple.com', 'apple.com')
|
9
|
+
@strategy = Plow::Strategy::UbuntuHardy::UserHomeWebApp.new(@context)
|
10
|
+
|
11
|
+
@parsed_users_fixture = [
|
12
|
+
{ name: "root", password: "x", id: 0, group_id: 0, info: "root", home_path: "/root", shell_path: "/bin/bash" },
|
13
|
+
{ name: "daemon", password: "x", id: 1, group_id: 1, info: "daemon", home_path: "/usr/sbin", shell_path: "/bin/sh" },
|
14
|
+
{ name: "bin", password: "x", id: 2, group_id: 2, info: "bin", home_path: "/bin", shell_path: "/bin/sh" },
|
15
|
+
{ name: "sys", password: "x", id: 3, group_id: 3, info: "sys", home_path: "/dev", shell_path: "/bin/sh" },
|
16
|
+
{ name: "sync", password: "x", id: 4, group_id: 65534, info: "sync", home_path: "/bin", shell_path: "/bin/sync" },
|
17
|
+
{ name: "games", password: "x", id: 5, group_id: 60, info: "games", home_path: "/usr/games", shell_path: "/bin/sh" },
|
18
|
+
{ name: "man", password: "x", id: 6, group_id: 12, info: "man", home_path: "/var/cache/man", shell_path: "/bin/sh" },
|
19
|
+
{ name: "lp", password: "x", id: 7, group_id: 7, info: "lp", home_path: "/var/spool/lpd", shell_path: "/bin/sh" },
|
20
|
+
{ name: "mail", password: "x", id: 8, group_id: 8, info: "mail", home_path: "/var/mail", shell_path: "/bin/sh" },
|
21
|
+
{ name: "news", password: "x", id: 9, group_id: 9, info: "news", home_path: "/var/spool/news", shell_path: "/bin/sh" },
|
22
|
+
{ name: "uucp", password: "x", id: 10, group_id: 10, info: "uucp", home_path: "/var/spool/uucp", shell_path: "/bin/sh" },
|
23
|
+
{ name: "proxy", password: "x", id: 13, group_id: 13, info: "proxy", home_path: "/bin", shell_path: "/bin/sh" },
|
24
|
+
{ name: "www-data", password: "x", id: 33, group_id: 33, info: "www-data", home_path: "/var/www", shell_path: "/bin/sh" },
|
25
|
+
{ name: "backup", password: "x", id: 34, group_id: 34, info: "backup", home_path: "/var/backups", shell_path: "/bin/sh" },
|
26
|
+
{ name: "list", password: "x", id: 38, group_id: 38, info: "Mailing List Manager", home_path: "/var/list", shell_path: "/bin/sh" },
|
27
|
+
{ name: "irc", password: "x", id: 39, group_id: 39, info: "ircd", home_path: "/var/run/ircd", shell_path: "/bin/sh" },
|
28
|
+
{ name: "gnats", password: "x", id: 41, group_id: 41, info: "Gnats Bug-Reporting System (admin)", home_path: "/var/lib/gnats", shell_path: "/bin/sh" },
|
29
|
+
{ name: "nobody", password: "x", id: 65534, group_id: 65534, info: "nobody", home_path: "/nonexistent", shell_path: "/bin/sh" },
|
30
|
+
{ name: "libuuid", password: "x", id: 100, group_id: 101, info: "", home_path: "/var/lib/libuuid", shell_path: "/bin/sh" },
|
31
|
+
{ name: "dhcp", password: "x", id: 101, group_id: 102, info: "", home_path: "/nonexistent", shell_path: "/bin/false" },
|
32
|
+
{ name: "syslog", password: "x", id: 102, group_id: 103, info: "", home_path: "/home/syslog", shell_path: "/bin/false" },
|
33
|
+
{ name: "klog", password: "x", id: 103, group_id: 104, info: "", home_path: "/home/klog", shell_path: "/bin/false" },
|
34
|
+
{ name: "sshd", password: "x", id: 104, group_id: 65534, info: "", home_path: "/var/run/sshd", shell_path: "/usr/sbin/nologin" },
|
35
|
+
{ name: "Debian-exim", password: "x", id: 105, group_id: 109, info: "", home_path: "/var/spool/exim4", shell_path: "/bin/false" },
|
36
|
+
{ name: "sadmin", password: "x", id: 1000, group_id: 1000, info: ",,,", home_path: "/home/sadmin", shell_path: "/bin/bash" },
|
37
|
+
{ name: "mysql", password: "x", id: 106, group_id: 111, info: "MySQL Server,,,", home_path: "/var/lib/mysql", shell_path: "/bin/false" },
|
38
|
+
{ name: "steve", password: "x", id: 1001, group_id: 1001, info: ",,,", home_path: "/home/steve", shell_path: "/bin/bash" }
|
39
|
+
]
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
##################################################################################################
|
44
|
+
|
45
|
+
describe ".new" do
|
46
|
+
it "should set context" do
|
47
|
+
@strategy.context.should == @context
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should set users file path" do
|
51
|
+
@strategy.users_file_path.should == '/etc/passwd'
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should set virtual host configuration file name" do
|
55
|
+
@strategy.vhost_file_name.should == "www.apple.com.conf"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should set virtual host configuration file path" do
|
59
|
+
@strategy.vhost_file_path.should == "/etc/apache2/sites-available/www.apple.com.conf"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should set virtual host configuration template file path" do
|
63
|
+
expected = File.expand_path(File.dirname(__FILE__) + '/../../../../lib/plow/strategy/ubuntu_hardy/templates/apache2-vhost.conf')
|
64
|
+
@strategy.vhost_template_file_path.should == expected
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
##################################################################################################
|
69
|
+
|
70
|
+
describe '#say (private)' do
|
71
|
+
it 'should proxy to Plow::Generator#say' do
|
72
|
+
@context.should_receive(:say).with("something amazing happened!")
|
73
|
+
@strategy.send(:say, "something amazing happened!")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
##################################################################################################
|
78
|
+
|
79
|
+
describe '#shell (private)' do
|
80
|
+
it 'should proxy to Plow::Generator#shell' do
|
81
|
+
@context.should_receive(:shell).with("echo *")
|
82
|
+
@strategy.send(:shell, "echo *")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
##################################################################################################
|
87
|
+
|
88
|
+
describe '#users (private)' do
|
89
|
+
it "should read and parse a system accounts file (e.g. /etc/passwd)" do
|
90
|
+
@strategy.stub!(:users_file_path).and_return(FIXTURES_PATH + '/passwd.txt')
|
91
|
+
@strategy.send(:users) { |user| user.should == @parsed_users_fixture.shift }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
##################################################################################################
|
96
|
+
|
97
|
+
describe '#user_exists? (private)' do
|
98
|
+
before(:each) do
|
99
|
+
@strategy.stub!(:users_file_path).and_return(FIXTURES_PATH + '/passwd.txt')
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should raise Plow::ReservedSystemUserNameError for a system account where user id < 1000" do
|
103
|
+
@context.stub!(:user_name).and_return('sshd')
|
104
|
+
lambda { @strategy.send(:user_exists?) }.should raise_error(Plow::ReservedSystemUserNameError, 'sshd')
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should raise Plow::ReservedSystemUserNameError for a system account where user id == 65534" do
|
108
|
+
@context.stub!(:user_name).and_return('nobody')
|
109
|
+
lambda { @strategy.send(:user_exists?) }.should raise_error(Plow::ReservedSystemUserNameError, 'nobody')
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should return false when no matching non-system account is found" do
|
113
|
+
@context.stub!(:user_name).and_return('microsoft-steve')
|
114
|
+
@strategy.send(:user_exists?).should be_false
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should return true when a matching non-system account is found" do
|
118
|
+
@context.stub!(:user_name).and_return('steve')
|
119
|
+
@strategy.send(:user_exists?).should be_true
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
##################################################################################################
|
124
|
+
|
125
|
+
describe '#create_user (private)' do
|
126
|
+
it "should invoke a adduser as a system call" do
|
127
|
+
@strategy.should_receive(:shell).with("adduser steve")
|
128
|
+
@strategy.send(:create_user)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
##################################################################################################
|
133
|
+
|
134
|
+
describe '#user_home_exists? (private)' do
|
135
|
+
before(:each) do
|
136
|
+
@strategy.stub!(:users_file_path).and_return(FIXTURES_PATH + '/passwd.txt')
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should raise Plow::SystemUserNameNotFoundError if no matching user name is found" do
|
140
|
+
@context.stub!(:user_name).and_return('microsoft-steve')
|
141
|
+
lambda { @strategy.send(:user_home_exists?) }.should raise_error(Plow::SystemUserNameNotFoundError, 'microsoft-steve')
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "when home directory exists for existing user" do
|
145
|
+
before(:each) do
|
146
|
+
@user = @parsed_users_fixture.last
|
147
|
+
@context.stub!(:user_name).and_return(@user[:name])
|
148
|
+
Dir.should_receive(:exists?).and_return(true)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should return true" do
|
152
|
+
@strategy.send(:user_home_exists?).should be_true
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should set user home variable to correct home path" do
|
156
|
+
@strategy.send(:user_home_exists?)
|
157
|
+
@strategy.user_home_path.should == '/home/steve'
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
describe "when home directory does not exist for existing user" do
|
162
|
+
before(:each) do
|
163
|
+
@user = @parsed_users_fixture.last
|
164
|
+
@context.stub!(:user_name).and_return(@user[:name])
|
165
|
+
Dir.should_receive(:exists?).and_return(false)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should return false" do
|
169
|
+
@strategy.send(:user_home_exists?).should be_false
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should set user home variable to correct home path" do
|
173
|
+
@strategy.send(:user_home_exists?)
|
174
|
+
@strategy.user_home_path.should == '/home/steve'
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
##################################################################################################
|
180
|
+
|
181
|
+
describe '#create_user_home (private)' do
|
182
|
+
it "should create a user home with the correct ownership" do
|
183
|
+
@strategy.stub!(:user_home_path).and_return("/home/steve")
|
184
|
+
@strategy.should_receive(:shell).with(<<-COMMANDS)
|
185
|
+
mkdir /home/steve
|
186
|
+
chown steve:steve /home/steve
|
187
|
+
COMMANDS
|
188
|
+
@strategy.send(:create_user_home)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
##################################################################################################
|
193
|
+
|
194
|
+
describe '#sites_home_exists? (private)' do
|
195
|
+
before(:each) do
|
196
|
+
@user = @parsed_users_fixture.last
|
197
|
+
@strategy.stub!(:user_home_path).and_return(@user[:home_path])
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should set sites home variable" do
|
201
|
+
@strategy.send(:sites_home_exists?)
|
202
|
+
@strategy.sites_home_path.should == "/home/steve/sites"
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should return true if the directory exists" do
|
206
|
+
Dir.should_receive(:exists?).and_return(true)
|
207
|
+
@strategy.send(:sites_home_exists?).should be_true
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should return false if the directory does not exist" do
|
211
|
+
Dir.should_receive(:exists?).and_return(false)
|
212
|
+
@strategy.send(:sites_home_exists?).should be_false
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
##################################################################################################
|
217
|
+
|
218
|
+
describe '#create_sites_home (private)' do
|
219
|
+
it "should create a sites home with the correct ownership" do
|
220
|
+
@strategy.stub!(:sites_home_path).and_return("/home/steve/sites")
|
221
|
+
@strategy.should_receive(:shell).with(<<-COMMANDS)
|
222
|
+
mkdir /home/steve/sites
|
223
|
+
chown steve:steve /home/steve/sites
|
224
|
+
COMMANDS
|
225
|
+
@strategy.send(:create_sites_home)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
##################################################################################################
|
230
|
+
|
231
|
+
describe '#app_root_exists? (private)' do
|
232
|
+
before(:each) do
|
233
|
+
@user = @parsed_users_fixture.last
|
234
|
+
@strategy.stub!(:sites_home_path).and_return("#{@user[:home_path]}/sites")
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should set sites home variable" do
|
238
|
+
@strategy.send(:app_root_exists?)
|
239
|
+
@strategy.app_root_path.should == "/home/steve/sites/www.apple.com"
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should return true if the directory exists" do
|
243
|
+
Dir.should_receive(:exists?).and_return(true)
|
244
|
+
@strategy.send(:app_root_exists?).should be_true
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should return false if the directory does not exist" do
|
248
|
+
Dir.should_receive(:exists?).and_return(false)
|
249
|
+
@strategy.send(:app_root_exists?).should be_false
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
##################################################################################################
|
254
|
+
|
255
|
+
describe '#create_app_root (private)' do
|
256
|
+
it "should create an application home correctly" do
|
257
|
+
@strategy.stub!(:app_root_path).and_return('/home/steve/sites/www.apple.com')
|
258
|
+
@strategy.should_receive(:shell).with(<<-COMMANDS)
|
259
|
+
mkdir /home/steve/sites/www.apple.com
|
260
|
+
chown steve:steve /home/steve/sites/www.apple.com
|
261
|
+
COMMANDS
|
262
|
+
@strategy.send(:create_app_root)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
##################################################################################################
|
267
|
+
|
268
|
+
describe '#create_app_public (private)' do
|
269
|
+
it "should build an application's public files correctly" do
|
270
|
+
@strategy.stub!(:app_public_path).and_return('/home/steve/sites/www.apple.com/public')
|
271
|
+
@strategy.should_receive(:shell).with(<<-COMMANDS)
|
272
|
+
mkdir /home/steve/sites/www.apple.com/public
|
273
|
+
touch /home/steve/sites/www.apple.com/public/index.html
|
274
|
+
chown -R steve:steve /home/steve/sites/www.apple.com/public
|
275
|
+
COMMANDS
|
276
|
+
@strategy.send(:create_app_public)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
##################################################################################################
|
281
|
+
|
282
|
+
describe '#create_app_logs (private)' do
|
283
|
+
it "should build an application's log files correctly" do
|
284
|
+
@strategy.stub!(:app_log_path).and_return('/home/steve/sites/www.apple.com/log')
|
285
|
+
@strategy.should_receive(:shell).with(<<-COMMANDS)
|
286
|
+
mkdir /home/steve/sites/www.apple.com/log
|
287
|
+
mkdir /home/steve/sites/www.apple.com/log/apache2
|
288
|
+
chmod 750 /home/steve/sites/www.apple.com/log/apache2
|
289
|
+
|
290
|
+
touch /home/steve/sites/www.apple.com/log/apache2/access.log
|
291
|
+
touch /home/steve/sites/www.apple.com/log/apache2/error.log
|
292
|
+
|
293
|
+
chmod 640 /home/steve/sites/www.apple.com/log/apache2/*.log
|
294
|
+
chown -R steve:steve /home/steve/sites/www.apple.com/log
|
295
|
+
chown root -R /home/steve/sites/www.apple.com/log/apache2
|
296
|
+
COMMANDS
|
297
|
+
@strategy.send(:create_app_logs)
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
##################################################################################################
|
302
|
+
|
303
|
+
describe '#vhost_config_exists? (private)' do
|
304
|
+
it "should return true if the directory exists" do
|
305
|
+
Dir.should_receive(:exists?).and_return(true)
|
306
|
+
@strategy.send(:vhost_config_exists?).should be_true
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should return false if the directory does not exist" do
|
310
|
+
Dir.should_receive(:exists?).and_return(false)
|
311
|
+
@strategy.send(:vhost_config_exists?).should be_false
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
##################################################################################################
|
316
|
+
|
317
|
+
describe '#create_vhost_config (private)' do
|
318
|
+
before(:each) do
|
319
|
+
@temp_file = Tempfile.new('generate_vhost_config')
|
320
|
+
@strategy.stub!(:vhost_file_path).and_return(@temp_file.path)
|
321
|
+
@strategy.stub!(:app_public_path).and_return('/home/steve/sites/www.apple.com/public')
|
322
|
+
@strategy.stub!(:app_log_path).and_return('/home/steve/sites/www.apple.com/log')
|
323
|
+
end
|
324
|
+
|
325
|
+
it "should create a vhost config file from template file without site aliases" do
|
326
|
+
@context.stub!(:site_aliases).and_return([])
|
327
|
+
@strategy.send(:create_vhost_config)
|
328
|
+
|
329
|
+
File.read(@temp_file.path).should == <<-CONFIG
|
330
|
+
|
331
|
+
<VirtualHost *:80>
|
332
|
+
ServerAdmin webmaster
|
333
|
+
ServerName www.apple.com
|
334
|
+
|
335
|
+
DirectoryIndex index.html
|
336
|
+
DocumentRoot /home/steve/sites/www.apple.com/public
|
337
|
+
|
338
|
+
LogLevel warn
|
339
|
+
ErrorLog /home/steve/sites/www.apple.com/log/apache2/error.log
|
340
|
+
CustomLog /home/steve/sites/www.apple.com/log/apache2/access.log combined
|
341
|
+
</VirtualHost>
|
342
|
+
CONFIG
|
343
|
+
end
|
344
|
+
|
345
|
+
it "should create a vhost config file from template file with site aliases" do
|
346
|
+
@strategy.send(:create_vhost_config)
|
347
|
+
File.read(@temp_file.path).should == <<-CONFIG
|
348
|
+
|
349
|
+
<VirtualHost *:80>
|
350
|
+
ServerAdmin webmaster
|
351
|
+
ServerName www.apple.com
|
352
|
+
|
353
|
+
ServerAlias apple.com
|
354
|
+
|
355
|
+
DirectoryIndex index.html
|
356
|
+
DocumentRoot /home/steve/sites/www.apple.com/public
|
357
|
+
|
358
|
+
LogLevel warn
|
359
|
+
ErrorLog /home/steve/sites/www.apple.com/log/apache2/error.log
|
360
|
+
CustomLog /home/steve/sites/www.apple.com/log/apache2/access.log combined
|
361
|
+
</VirtualHost>
|
362
|
+
CONFIG
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
##################################################################################################
|
367
|
+
|
368
|
+
describe '#install_vhost_config (private)' do
|
369
|
+
it "should enable vhost and restart apache2" do
|
370
|
+
@strategy.should_receive(:shell).with(<<-COMMANDS)
|
371
|
+
a2ensite www.apple.com.conf
|
372
|
+
apache2ctl graceful
|
373
|
+
COMMANDS
|
374
|
+
@strategy.send(:install_vhost_config)
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
##################################################################################################
|
379
|
+
|
380
|
+
describe '#execute' do
|
381
|
+
before(:each) do
|
382
|
+
@strategy.stub!(:user_exists?).and_return(false)
|
383
|
+
@strategy.stub!(:user_home_exists?).and_return(true)
|
384
|
+
@strategy.stub!(:sites_home_exists?).and_return(false)
|
385
|
+
@strategy.stub!(:app_root_exists?).and_return(false)
|
386
|
+
@strategy.stub!(:vhost_config_exists?).and_return(false)
|
387
|
+
|
388
|
+
@strategy.stub!(:user_home_path).and_return('/home/steve')
|
389
|
+
@strategy.stub!(:sites_home_path).and_return('/home/steve/sites')
|
390
|
+
@strategy.stub!(:app_root_path).and_return('/home/steve/sites/www.apple.com')
|
391
|
+
|
392
|
+
$stdout = StringIO.new
|
393
|
+
end
|
394
|
+
|
395
|
+
after(:each) do
|
396
|
+
$stdout = STDOUT
|
397
|
+
end
|
398
|
+
|
399
|
+
it "should run the default process" do
|
400
|
+
@strategy.should_receive(:create_user)
|
401
|
+
@strategy.should_not_receive(:create_user_home)
|
402
|
+
@strategy.should_receive(:create_sites_home)
|
403
|
+
@strategy.should_receive(:create_app_root)
|
404
|
+
@strategy.should_receive(:create_app_public)
|
405
|
+
@strategy.should_receive(:create_app_logs)
|
406
|
+
@strategy.should_receive(:create_vhost_config)
|
407
|
+
@strategy.should_receive(:install_vhost_config)
|
408
|
+
|
409
|
+
@strategy.execute
|
410
|
+
|
411
|
+
@strategy.app_public_path.should == '/home/steve/sites/www.apple.com/public'
|
412
|
+
@strategy.app_log_path.should == '/home/steve/sites/www.apple.com/log'
|
413
|
+
|
414
|
+
$stdout.string.should == <<-OUTPUT
|
415
|
+
==> creating steve user
|
416
|
+
==> existing /home/steve
|
417
|
+
==> creating /home/steve/sites
|
418
|
+
==> creating /home/steve/sites/www.apple.com
|
419
|
+
==> creating /home/steve/sites/www.apple.com/public
|
420
|
+
==> creating /home/steve/sites/www.apple.com/log
|
421
|
+
==> creating /etc/apache2/sites-available/www.apple.com.conf
|
422
|
+
==> installing /etc/apache2/sites-available/www.apple.com.conf
|
423
|
+
OUTPUT
|
424
|
+
end
|
425
|
+
|
426
|
+
it "should run the existing user process" do
|
427
|
+
@strategy.stub!(:user_exists?).and_return(true)
|
428
|
+
|
429
|
+
@strategy.should_not_receive(:create_user)
|
430
|
+
@strategy.should_not_receive(:create_user_home)
|
431
|
+
@strategy.should_receive(:create_sites_home)
|
432
|
+
@strategy.should_receive(:create_app_root)
|
433
|
+
@strategy.should_receive(:create_app_public)
|
434
|
+
@strategy.should_receive(:create_app_logs)
|
435
|
+
@strategy.should_receive(:create_vhost_config)
|
436
|
+
@strategy.should_receive(:install_vhost_config)
|
437
|
+
|
438
|
+
@strategy.execute
|
439
|
+
|
440
|
+
@strategy.app_public_path.should == '/home/steve/sites/www.apple.com/public'
|
441
|
+
@strategy.app_log_path.should == '/home/steve/sites/www.apple.com/log'
|
442
|
+
|
443
|
+
$stdout.string.should == <<-OUTPUT
|
444
|
+
==> existing steve user
|
445
|
+
==> existing /home/steve
|
446
|
+
==> creating /home/steve/sites
|
447
|
+
==> creating /home/steve/sites/www.apple.com
|
448
|
+
==> creating /home/steve/sites/www.apple.com/public
|
449
|
+
==> creating /home/steve/sites/www.apple.com/log
|
450
|
+
==> creating /etc/apache2/sites-available/www.apple.com.conf
|
451
|
+
==> installing /etc/apache2/sites-available/www.apple.com.conf
|
452
|
+
OUTPUT
|
453
|
+
end
|
454
|
+
|
455
|
+
it "should run the missing user home process" do
|
456
|
+
@strategy.stub!(:user_home_exists?).and_return(false)
|
457
|
+
|
458
|
+
@strategy.should_receive(:create_user)
|
459
|
+
@strategy.should_receive(:create_user_home)
|
460
|
+
@strategy.should_receive(:create_sites_home)
|
461
|
+
@strategy.should_receive(:create_app_root)
|
462
|
+
@strategy.should_receive(:create_app_public)
|
463
|
+
@strategy.should_receive(:create_app_logs)
|
464
|
+
@strategy.should_receive(:create_vhost_config)
|
465
|
+
@strategy.should_receive(:install_vhost_config)
|
466
|
+
|
467
|
+
@strategy.execute
|
468
|
+
|
469
|
+
@strategy.app_public_path.should == '/home/steve/sites/www.apple.com/public'
|
470
|
+
@strategy.app_log_path.should == '/home/steve/sites/www.apple.com/log'
|
471
|
+
|
472
|
+
$stdout.string.should == <<-OUTPUT
|
473
|
+
==> creating steve user
|
474
|
+
==> creating /home/steve
|
475
|
+
==> creating /home/steve/sites
|
476
|
+
==> creating /home/steve/sites/www.apple.com
|
477
|
+
==> creating /home/steve/sites/www.apple.com/public
|
478
|
+
==> creating /home/steve/sites/www.apple.com/log
|
479
|
+
==> creating /etc/apache2/sites-available/www.apple.com.conf
|
480
|
+
==> installing /etc/apache2/sites-available/www.apple.com.conf
|
481
|
+
OUTPUT
|
482
|
+
end
|
483
|
+
|
484
|
+
it "should run the existing sites home process" do
|
485
|
+
@strategy.stub!(:sites_home_exists?).and_return(true)
|
486
|
+
|
487
|
+
@strategy.should_receive(:create_user)
|
488
|
+
@strategy.should_not_receive(:create_user_home)
|
489
|
+
@strategy.should_not_receive(:create_sites_home)
|
490
|
+
@strategy.should_receive(:create_app_root)
|
491
|
+
@strategy.should_receive(:create_app_public)
|
492
|
+
@strategy.should_receive(:create_app_logs)
|
493
|
+
@strategy.should_receive(:create_vhost_config)
|
494
|
+
@strategy.should_receive(:install_vhost_config)
|
495
|
+
|
496
|
+
@strategy.execute
|
497
|
+
|
498
|
+
@strategy.app_public_path.should == '/home/steve/sites/www.apple.com/public'
|
499
|
+
@strategy.app_log_path.should == '/home/steve/sites/www.apple.com/log'
|
500
|
+
|
501
|
+
$stdout.string.should == <<-OUTPUT
|
502
|
+
==> creating steve user
|
503
|
+
==> existing /home/steve
|
504
|
+
==> existing /home/steve/sites
|
505
|
+
==> creating /home/steve/sites/www.apple.com
|
506
|
+
==> creating /home/steve/sites/www.apple.com/public
|
507
|
+
==> creating /home/steve/sites/www.apple.com/log
|
508
|
+
==> creating /etc/apache2/sites-available/www.apple.com.conf
|
509
|
+
==> installing /etc/apache2/sites-available/www.apple.com.conf
|
510
|
+
OUTPUT
|
511
|
+
end
|
512
|
+
|
513
|
+
it "should run the existing app root process" do
|
514
|
+
@strategy.stub!(:app_root_exists?).and_return(true)
|
515
|
+
|
516
|
+
@strategy.should_receive(:create_user)
|
517
|
+
@strategy.should_not_receive(:create_user_home)
|
518
|
+
@strategy.should_receive(:create_sites_home)
|
519
|
+
@strategy.should_not_receive(:create_app_root)
|
520
|
+
@strategy.should_not_receive(:create_app_public)
|
521
|
+
@strategy.should_not_receive(:create_app_logs)
|
522
|
+
@strategy.should_not_receive(:create_vhost_config)
|
523
|
+
@strategy.should_not_receive(:install_vhost_config)
|
524
|
+
|
525
|
+
lambda { @strategy.execute }.should raise_error(Plow::AppRootAlreadyExistsError, '/home/steve/sites/www.apple.com')
|
526
|
+
|
527
|
+
$stdout.string.should == <<-OUTPUT
|
528
|
+
==> creating steve user
|
529
|
+
==> existing /home/steve
|
530
|
+
==> creating /home/steve/sites
|
531
|
+
OUTPUT
|
532
|
+
end
|
533
|
+
|
534
|
+
it "should run the existing vhost config process" do
|
535
|
+
@strategy.stub!(:vhost_config_exists?).and_return(true)
|
536
|
+
|
537
|
+
@strategy.should_receive(:create_user)
|
538
|
+
@strategy.should_not_receive(:create_user_home)
|
539
|
+
@strategy.should_receive(:create_sites_home)
|
540
|
+
@strategy.should_receive(:create_app_root)
|
541
|
+
@strategy.should_receive(:create_app_public)
|
542
|
+
@strategy.should_receive(:create_app_logs)
|
543
|
+
@strategy.should_not_receive(:create_vhost_config)
|
544
|
+
@strategy.should_not_receive(:install_vhost_config)
|
545
|
+
|
546
|
+
lambda { @strategy.execute }.should raise_error(Plow::ConfigFileAlreadyExistsError, '/etc/apache2/sites-available/www.apple.com.conf')
|
547
|
+
|
548
|
+
@strategy.app_public_path.should == '/home/steve/sites/www.apple.com/public'
|
549
|
+
@strategy.app_log_path.should == '/home/steve/sites/www.apple.com/log'
|
550
|
+
|
551
|
+
$stdout.string.should == <<-OUTPUT
|
552
|
+
==> creating steve user
|
553
|
+
==> existing /home/steve
|
554
|
+
==> creating /home/steve/sites
|
555
|
+
==> creating /home/steve/sites/www.apple.com
|
556
|
+
==> creating /home/steve/sites/www.apple.com/public
|
557
|
+
==> creating /home/steve/sites/www.apple.com/log
|
558
|
+
OUTPUT
|
559
|
+
end
|
560
|
+
end
|
561
|
+
end
|
data/spec/plow_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
describe "Plow" do
|
5
|
+
describe "version synchronizing" do
|
6
|
+
before(:each) do
|
7
|
+
@expected = "0.1.0"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be correct for Plow::VERSION" do
|
11
|
+
Plow::VERSION.should == @expected
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be correct for the VERSION rubygem file" do
|
15
|
+
actual = File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'VERSION'))).chomp
|
16
|
+
actual.should == @expected
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
unless $LOAD_PATH.include?(File.dirname(__FILE__))
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
end
|
6
|
+
|
7
|
+
unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__) + '/../lib'))
|
8
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'spec'
|
13
|
+
require 'spec/autorun'
|
14
|
+
rescue LoadError
|
15
|
+
abort <<-ERROR
|
16
|
+
Unexpected LoadError exception caught in #{__FILE__} on #{__LINE__}
|
17
|
+
|
18
|
+
This file depends on the rspec library, which is not available.
|
19
|
+
You may install the library via rubygems with: sudo gem install rspec
|
20
|
+
ERROR
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'plow'
|
24
|
+
|
25
|
+
FIXTURES_PATH = File.dirname(__FILE__) + '/fixtures'
|
26
|
+
|
27
|
+
Spec::Runner.configure do |config|
|
28
|
+
|
29
|
+
end
|