plow 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,160 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
|
+
|
4
|
+
describe Plow::Generator do
|
5
|
+
|
6
|
+
##################################################################################################
|
7
|
+
|
8
|
+
describe ".new when failing" do
|
9
|
+
it "should raise Plow::InvalidSystemUserNameError if first argument is blank" do
|
10
|
+
lambda { Plow::Generator.new(nil, 'not-blank') }.should raise_error(Plow::InvalidSystemUserNameError, nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should raise Plow::InvalidSystemUserNameError if first argument contains a blank space" do
|
14
|
+
lambda { Plow::Generator.new('oh noes!', 'not-blank') }.should raise_error(Plow::InvalidSystemUserNameError, 'oh noes!')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise Plow::InvalidWebSiteNameError if second argument is blank" do
|
18
|
+
lambda { Plow::Generator.new('not-blank', nil) }.should raise_error(Plow::InvalidWebSiteNameError, nil)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should raise Plow::InvalidWebSiteNameError if second argument contains a blank space" do
|
22
|
+
lambda { Plow::Generator.new('not-blank', 'oh noes!') }.should raise_error(Plow::InvalidWebSiteNameError, 'oh noes!')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should raise Plow::InvalidWebSiteAliasError if third argument is blank" do
|
26
|
+
lambda { Plow::Generator.new('not-blank', 'not-blank', nil) }.should raise_error(Plow::InvalidWebSiteAliasError, nil)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should raise Plow::InvalidWebSiteAliasError if third argument contains a blank space" do
|
30
|
+
lambda { Plow::Generator.new('not-blank', 'not-blank', 'oh noes!') }.should raise_error(Plow::InvalidWebSiteAliasError, 'oh noes!')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
##################################################################################################
|
35
|
+
|
36
|
+
describe ".new when passing with two good arguments" do
|
37
|
+
before(:each) do
|
38
|
+
@generator = Plow::Generator.new('steve', 'www.apple.com')
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should set user_name" do
|
42
|
+
@generator.user_name.should == 'steve'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should set site_name" do
|
46
|
+
@generator.site_name.should == 'www.apple.com'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should set site_aliases to an empty Array" do
|
50
|
+
@generator.site_aliases.should == []
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should set strategy to an instance of Plow::Strategy::UbuntuHardy::UserHomeWebApp" do
|
54
|
+
@generator.strategy.should be_an_instance_of(Plow::Strategy::UbuntuHardy::UserHomeWebApp)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
##################################################################################################
|
59
|
+
|
60
|
+
describe ".new when passing with three good arguments" do
|
61
|
+
before(:each) do
|
62
|
+
@generator = Plow::Generator.new('steve', 'www.apple.com', 'apple.com')
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should set user_name" do
|
66
|
+
@generator.user_name.should == 'steve'
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should set site_name" do
|
70
|
+
@generator.site_name.should == 'www.apple.com'
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should set site_aliases to an single element Array" do
|
74
|
+
@generator.site_aliases.should == ['apple.com']
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should set strategy to an instance of Plow::Strategy::UbuntuHardy::UserHomeWebApp" do
|
78
|
+
@generator.strategy.should be_an_instance_of(Plow::Strategy::UbuntuHardy::UserHomeWebApp)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
##################################################################################################
|
83
|
+
|
84
|
+
describe ".run!" do
|
85
|
+
it "should raise Plow::NonRootProcessOwnerError when process is owned by non-root user" do
|
86
|
+
Process.stub!(:uid).and_return(1)
|
87
|
+
generator = Plow::Generator.new('steve', 'www.apple.com', 'apple.com')
|
88
|
+
lambda { generator.run! }.should raise_error(Plow::NonRootProcessOwnerError)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should execute the strategy when process is owned by root user" do
|
92
|
+
Process.stub!(:uid).and_return(0)
|
93
|
+
generator = Plow::Generator.new('steve', 'www.apple.com', 'apple.com')
|
94
|
+
generator.strategy.should_receive(:execute)
|
95
|
+
generator.run!
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
##################################################################################################
|
100
|
+
|
101
|
+
describe '#say' do
|
102
|
+
before(:each) do
|
103
|
+
$stdout = StringIO.new
|
104
|
+
@generator = Plow::Generator.new('steve', 'www.apple.com', 'apple.com')
|
105
|
+
end
|
106
|
+
|
107
|
+
after(:each) do
|
108
|
+
$stdout = STDOUT
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should output message to the user" do
|
112
|
+
message = "Something great happened!"
|
113
|
+
@generator.say(message)
|
114
|
+
$stdout.string.should == "==> #{message}\n"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
##################################################################################################
|
119
|
+
|
120
|
+
describe '#shell (private)' do
|
121
|
+
before(:each) do
|
122
|
+
@generator = Plow::Generator.new('steve', 'www.apple.com', 'apple.com')
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should invoke a system call for a single-line command String" do
|
126
|
+
command = " echo * "
|
127
|
+
@generator.should_receive(:system).with('echo *')
|
128
|
+
@generator.shell(command)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should invoke a system call for a multi-line command String" do
|
132
|
+
commands = <<-COMMANDS
|
133
|
+
echo *
|
134
|
+
|
135
|
+
ls -al
|
136
|
+
COMMANDS
|
137
|
+
|
138
|
+
@generator.should_receive(:system).with('echo *').ordered
|
139
|
+
@generator.should_receive(:system).with('ls -al').ordered
|
140
|
+
@generator.shell(commands)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
##################################################################################################
|
145
|
+
|
146
|
+
describe '#evaluate_template' do
|
147
|
+
it "should accept a template path and a context Hash and evaluate them together" do
|
148
|
+
template_path = FIXTURES_PATH + '/vhost.conf'
|
149
|
+
context_hash = { site_name: 'www.apple.com' }
|
150
|
+
expected_output = <<-OUTPUT
|
151
|
+
<VirtualHost *:80>
|
152
|
+
ServerName www.apple.com
|
153
|
+
</VirtualHost>
|
154
|
+
OUTPUT
|
155
|
+
|
156
|
+
generator = Plow::Generator.new('steve', 'www.apple.com', 'apple.com')
|
157
|
+
generator.evaluate_template(template_path, context_hash).should == expected_output
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|