automateit 0.71006 → 0.71012

Sign up to get free protection for your applications and to get access to all the features.
@@ -86,6 +86,10 @@ else
86
86
  end
87
87
 
88
88
  targets.each_pair do |driver_token, package|
89
+ # Run the following from the shell to skip package tests:
90
+ # export AUTOMATEIT_SPEC_SKIP_PACKAGES=1
91
+ next unless ENV["AUTOMATEIT_SPEC_SKIP_PACKAGES"].nil?
92
+
89
93
  driver = INTERPRETER.package_manager[driver_token]
90
94
  if driver.available?
91
95
  describe driver.class.to_s do
@@ -7,18 +7,10 @@ elsif not INTERPRETER.superuser?
7
7
  elsif not INTERPRETER.service_manager[:sysv].available?
8
8
  puts "NOTE: Can't check ServiceManager::SYSV on this platform, #{__FILE__}"
9
9
  else
10
- describe "AutomateIt::ServiceManager::SYSV" do
11
- begin
12
- INTERPRETER.service_manager.driver_for(:enabled?, @service_name)
13
- @has_enable = true
14
- rescue NotImplementedError
15
- @has_enable = false
16
- puts "NOTE: Can't check 'enabled?' on this platform, #{__FILE__}"
17
- end
18
-
10
+ #---[ Shared ]----------------------------------------------------------
11
+ describe AutomateIt::ServiceManager::SYSV, :shared => true do
19
12
  before(:all) do
20
13
  @a = AutomateIt.new(:verbosity => Logger::WARN)
21
- @m = @a.service_manager
22
14
 
23
15
  @service_name = "automateit_service_sysv_test"
24
16
  @service_file = "/etc/init.d/"+@service_name
@@ -29,13 +21,21 @@ else
29
21
  FileUtils.cp(@source_file, @service_file)
30
22
  FileUtils.chmod(0755, @service_file)
31
23
 
32
- @m.stop(@service_name, :quiet => true) if @m.running?(@service_name)
24
+ INTERPRETER.service_manager.stop(@service_name, :quiet => true)
25
+
26
+ @m = @a.service_manager
33
27
  end
34
28
 
35
29
  after(:all) do
36
- @m.stop(@service_name, :quiet => true) if @m.running?(@service_name)
30
+ INTERPRETER.service_manager.stop(@service_name, :quiet => true)
31
+
37
32
  FileUtils.rm(@service_file) if File.exists?(@service_file)
38
33
  end
34
+ end
35
+
36
+ #---[ Start ]-----------------------------------------------------------
37
+ describe AutomateIt::ServiceManager::SYSV, " with start" do
38
+ it_should_behave_like "AutomateIt::ServiceManager::SYSV"
39
39
 
40
40
  it "should start a service" do
41
41
  @m.start(@service_name, :quiet => true).should be_true
@@ -64,48 +64,103 @@ else
64
64
  @m.running?(@service_name).should be_true
65
65
  end
66
66
 
67
- it "should wait for service to restart" do
68
- # NOTE: Test depends on race condition because checks must pass before the service starts
67
+ end
69
68
 
70
- timeout = 1
71
- wait = timeout+2
72
- @a.edit(@service_file, :backup => false) do
73
- replace "touch $STATE", "sleep #{timeout} && touch $STATE &"
74
- end
69
+ #---[ Wait ]------------------------------------------------------------
70
+ describe AutomateIt::ServiceManager::SYSV, " when waiting", :shared => true do
71
+ it_should_behave_like "AutomateIt::ServiceManager::SYSV"
72
+
73
+ before(:all) do
74
+ @timeout = 1
75
+ @wait = @timeout+5
76
+ end
77
+
78
+ before(:each) do
79
+ # Mocks need concrete object, rather than dispatcher
80
+ @m = @a.service_manager[:sysv]
81
+ end
82
+ end
83
+
84
+ describe AutomateIt::ServiceManager::SYSV, " when waiting with mock" do
85
+ it_should_behave_like "AutomateIt::ServiceManager::SYSV when waiting"
86
+
87
+ it "should wait for service to checking started status" do
88
+ @m.should_receive(:tell).exactly(3).times.and_return(false, false, true)
75
89
 
76
- @m.start(@service_name, :quiet => true).should be_true
77
- @m.started?(@service_name).should be_false # Still starting
78
- @m.started?(@service_name, :wait => wait).should be_true
79
- @m.restart(@service_name, :quiet => true, :wait => wait).should be_true
80
90
  @m.started?(@service_name).should be_false
81
- @m.started?(@service_name, :wait => wait).should be_true
91
+ @m.started?(@service_name, :wait => @wait).should be_true
92
+ end
93
+
94
+ it "should wait for service to checking stopped status" do
95
+ @m.should_receive(:tell).exactly(3).times.and_return(true, true, false)
96
+
97
+ @m.stopped?(@service_name).should be_false
98
+ @m.stopped?(@service_name, :wait => @wait).should be_true
99
+ end
100
+
101
+ it "should pause for service to restart" do
102
+ @m.should_receive(:tell).exactly(3).times.
103
+ with(@service_name, :status, anything).and_return(false, false, true)
104
+ @m.should_receive(:tell).once.
105
+ with(@service_name, :stop, anything).and_return(true)
106
+ @m.should_receive(:tell).once.
107
+ with(@service_name, :start, anything).and_return(true)
108
+
109
+ @m.restart(@service_name, :pause => @wait).should be_true
82
110
  end
111
+ end
112
+
113
+ if false
114
+ # TODO: How to test waiting for real without long waits and race conditions? The example below does the same thing as the mocked version above, except by actually manipulating a service. The trouble with the real version is that there's a race condition between processes, which may cause the test to fail. For example, the #started? call might get the wrong value if the 'timeout' is too short or the 'wait' is too long. Increasing these reduces the likelihood that heavy system load will cause an error, but the test will take a very long time to run because of the sleep periods.
115
+
116
+ describe AutomateIt::ServiceManager::SYSV, " when waiting with service" do
117
+ it_should_behave_like "AutomateIt::ServiceManager::SYSV when waiting"
83
118
 
84
- if @has_enable
85
- # It's more correct to disable the service using before/after, but the
86
- # platform-specific scripts are ridiculously slow, so manually disabling
87
- # the service only when necessary significantly speeds the test.
88
- @disable_manually = true
119
+ it "should wait for service to restart" do
120
+ @a.edit(@service_file, :backup => false, :params => {:timeout => @timeout}) do
121
+ replace "touch $STATE", "sleep #{params[:timeout]} && touch $STATE &"
122
+ end
123
+
124
+ @m.start(@service_name, :quiet => true).should be_true
125
+ @m.started?(@service_name).should be_false # Still starting
126
+ @m.started?(@service_name, :wait => @wait).should be_true
127
+ @m.restart(@service_name, :quiet => true, :wait => @wait).should be_true
128
+ @m.started?(@service_name).should be_false # Still stopping
129
+ @m.started?(@service_name, :wait => @wait).should be_true
130
+ end
131
+ end
132
+ end
133
+
134
+ #---[ Enable ]----------------------------------------------------------
135
+ if INTERPRETER.service_manager.available?(:enabled?)
136
+ describe AutomateIt::ServiceManager::SYSV, " with enable" do
137
+ it_should_behave_like "AutomateIt::ServiceManager::SYSV"
138
+
139
+ # Make tests independent? True is correct and lets you run individual
140
+ # tests. False is faster but requires you to run the full suite.
141
+ @independent = true
89
142
 
90
143
  before(:each) do
91
- @m.disable(@service_name, :quiet => true) if not @disable_manually
144
+ @m.disable(@service_name, :quiet => true) unless @independent
92
145
  end
93
146
 
94
147
  after(:all) do
95
- @m.disable(@service_name, :quiet => true) if not @disable_manually
148
+ @m.disable(@service_name, :quiet => true) unless @independent
96
149
  end
97
150
 
98
151
  it "should enable a service" do
99
152
  @m.enable(@service_name, :quiet => true).should be_true
153
+
100
154
  # Tear down
101
- @m.disable(@service_name, :quiet => true).should be_true if @disable_manually
155
+ @m.disable(@service_name, :quiet => true).should be_true if @independent
102
156
  end
103
157
 
104
158
  it "should not enable an enabled service" do
105
159
  @m.enable(@service_name, :quiet => true).should be_true
106
160
  @m.enable(@service_name, :quiet => true).should be_false
161
+
107
162
  # Tear down
108
- @m.disable(@service_name, :quiet => true).should be_true if @disable_manually
163
+ @m.disable(@service_name, :quiet => true).should be_true if @independent
109
164
  end
110
165
 
111
166
  it "should disable a service" do
@@ -124,9 +179,12 @@ else
124
179
  it "should identify an enabled service" do
125
180
  @m.enable(@service_name, :quiet => true).should be_true
126
181
  @m.enabled?(@service_name).should be_true
182
+
127
183
  # Tear down
128
- @m.disable(@service_name, :quiet => true).should be_true if @disable_manually
184
+ @m.disable(@service_name, :quiet => true).should be_true if @independent
129
185
  end
130
186
  end
187
+ else
188
+ puts "NOTE: Can't check 'enabled?' on this platform, #{__FILE__}"
131
189
  end
132
190
  end
@@ -1,6 +1,6 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), "/../spec_helper.rb")
2
2
 
3
- describe "AutomateIt::TemplateManager::ERB" do
3
+ describe AutomateIt::TemplateManager::ERB do
4
4
  before(:all) do
5
5
  @a = AutomateIt.new(:verbosity => Logger::WARN)
6
6
  @m = @a.template_manager
@@ -15,8 +15,8 @@ describe "AutomateIt::TemplateManager::ERB" do
15
15
 
16
16
  it "should set file's mode when rendering" do
17
17
  @a.mktempdircd do
18
- source = "foo"
19
- target = "bar"
18
+ source = "source"
19
+ target = "target"
20
20
  mode1 = 0646 if INTERPRETER.shell_manager.provides_mode?
21
21
  mode2 = 0100646
22
22
  File.open(source, "w+"){|h| h.write("<%=variable%>")}
@@ -35,14 +35,31 @@ describe "AutomateIt::TemplateManager::ERB" do
35
35
 
36
36
  it "should fail to render non-existent file" do
37
37
  @a.mktempdircd do
38
- lambda { @a.render(:file => "foo", :to => "bar") }.should raise_error(Errno::ENOENT)
38
+ lambda { @a.render(:file => "source", :to => "target") }.should raise_error(Errno::ENOENT)
39
39
  end
40
40
  end
41
41
 
42
42
  it "should not raise error with non-existent file in preview mode" do
43
43
  @a.mktempdircd do
44
44
  @a.preview = true
45
- @a.render(:file => "foo", :to => "bar").should be_true
45
+ @a.render(:file => "source", :to => "target").should be_true
46
+ end
47
+ end
48
+
49
+ it "should not backup non-existing files" do
50
+ @a.mktempdircd do
51
+ @a.render(:text => "source", :to => "target").should be_true
52
+
53
+ Dir.entries(".").grep(/\w/).size.should == 1
54
+ end
55
+ end
56
+
57
+ it "should backup existing files" do
58
+ @a.mktempdircd do
59
+ @a.touch "target"
60
+ @a.render(:text => "source", :to => "target").should be_true
61
+
62
+ Dir.entries(".").grep(/\w/).size.should == 2
46
63
  end
47
64
  end
48
65
  end
@@ -245,6 +245,11 @@ describe "MyManager's drivers" do
245
245
  it "should share object instances" do
246
246
  @m[:my_first_driver].should == @m.interpreter.my_manager[:my_first_driver]
247
247
  end
248
+
249
+ it "should have a manager" do
250
+ @m[:my_first_driver].manager.should == @m
251
+ end
252
+
248
253
  end
249
254
 
250
255
  describe AutomateIt::Interpreter do
@@ -50,6 +50,7 @@ describe "AutomateIt::TemplateManager::ERB" do
50
50
  @d.should_receive(:_read).once.with(@source).and_return("my template content")
51
51
  @d.should_receive(:_mtime).once.with(@source).and_return(timestamp+1)
52
52
  @d.should_receive(:_mtime).once.with(@target).and_return(timestamp)
53
+ @d.should_receive(:_backup).once.with(@target).and_return(true)
53
54
  @d.should_receive(:_write).once.with(@target, "my template content").and_return(true)
54
55
 
55
56
  @a.render(@source, @target, :check => :timestamp).should be_true
@@ -74,6 +75,7 @@ describe "AutomateIt::TemplateManager::ERB" do
74
75
  @d.should_receive(:_mtime).once.with("foo").and_return(timestamp+1)
75
76
  @d.should_receive(:_mtime).once.with(@source).and_return(timestamp)
76
77
  @d.should_receive(:_mtime).once.with(@target).and_return(timestamp)
78
+ @d.should_receive(:_backup).once.with(@target).and_return(true)
77
79
  @d.should_receive(:_write).once.with(@target, "my template content").and_return(true)
78
80
 
79
81
  @a.render(@source, @target, :check => :timestamp, :dependencies => ["foo"]).should be_true
@@ -95,6 +97,7 @@ describe "AutomateIt::TemplateManager::ERB" do
95
97
  @d.should_receive(:_exists?).once.with(@target).and_return(true)
96
98
  @d.should_receive(:_read).once.with(@target).and_return("my old content")
97
99
  @d.should_receive(:_read).once.with(@source).and_return("my template content")
100
+ @d.should_receive(:_backup).once.with(@target).and_return(true)
98
101
  @d.should_receive(:_write).once.with(@target, "my template content").and_return(true)
99
102
 
100
103
  @a.render(@source, @target, :check => :timestamp, :dependencies => ["foo"], :force => true).should be_true
@@ -121,6 +124,7 @@ describe "AutomateIt::TemplateManager::ERB" do
121
124
  @d.should_receive(:_exists?).once.with(@target).and_return(true)
122
125
  @d.should_receive(:_read).once.with(@target).and_return("my old content")
123
126
  @d.should_receive(:_read).once.with(@source).and_return("my template content")
127
+ @d.should_receive(:_backup).once.with(@target).and_return(true)
124
128
  @d.should_receive(:_write).once.with(@target, "my template content").and_return(true)
125
129
 
126
130
  @a.render(@source, @target, :check => :compare).should be_true
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: automateit
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.71006"
7
- date: 2007-10-08 00:00:00 -07:00
6
+ version: "0.71012"
7
+ date: 2007-10-13 00:00:00 -07:00
8
8
  summary: AutomateIt is an open-source tool for automating the setup and maintenance of UNIX-like systems
9
9
  require_paths:
10
10
  - lib
@@ -126,8 +126,11 @@ files:
126
126
  - lib/automateit/platform_manager/gentoo.rb
127
127
  - lib/automateit/platform_manager/darwin.rb
128
128
  - lib/automateit/platform_manager/freebsd.rb
129
+ - lib/automateit/platform_manager/sunos.rb
129
130
  - lib/automateit/address_manager/portable.rb
131
+ - lib/automateit/address_manager/sunos.rb
130
132
  - lib/automateit/address_manager/linux.rb
133
+ - lib/automateit/address_manager/base.rb
131
134
  - lib/automateit/shell_manager/portable.rb
132
135
  - lib/automateit/shell_manager/which.rb
133
136
  - lib/automateit/shell_manager/symlink.rb
@@ -146,6 +149,7 @@ files:
146
149
  - misc/which.cmd
147
150
  - misc/setup_gem_dependencies.sh
148
151
  - spec/spec_helper.rb
152
+ - spec/breaker.rb
149
153
  - spec/unit/plugins_spec.rb
150
154
  - spec/unit/template_manager_erb_spec.rb
151
155
  - spec/unit/field_manager_spec.rb
@@ -157,7 +161,6 @@ files:
157
161
  - spec/integration/service_manager_sysv_spec.rb
158
162
  - spec/integration/template_manager_erb_spec.rb
159
163
  - spec/integration/package_manager_spec.rb
160
- - spec/integration/address_manager_linux_spec.rb
161
164
  - spec/integration/platform_manager_spec.rb
162
165
  - spec/integration/edit_manager_spec.rb
163
166
  - spec/integration/shell_manager_spec.rb
@@ -168,6 +171,7 @@ files:
168
171
  - spec/integration/tempster_spec.rb
169
172
  - spec/integration/examples_spec_editor.rb
170
173
  - spec/integration/download_spec.rb
174
+ - spec/integration/address_manager_spec.rb
171
175
  - spec/extras/scratch.rb
172
176
  - spec/extras/automateit_service_sysv_test
173
177
  - spec/extras/simple_recipe.rb
@@ -175,6 +179,7 @@ test_files:
175
179
  - spec/spec_helper.rb
176
180
  - spec/unit
177
181
  - spec/integration
182
+ - spec/breaker.rb
178
183
  - spec/extras
179
184
  - spec/unit/plugins_spec.rb
180
185
  - spec/unit/template_manager_erb_spec.rb
@@ -187,7 +192,6 @@ test_files:
187
192
  - spec/integration/service_manager_sysv_spec.rb
188
193
  - spec/integration/template_manager_erb_spec.rb
189
194
  - spec/integration/package_manager_spec.rb
190
- - spec/integration/address_manager_linux_spec.rb
191
195
  - spec/integration/platform_manager_spec.rb
192
196
  - spec/integration/edit_manager_spec.rb
193
197
  - spec/integration/shell_manager_spec.rb
@@ -198,6 +202,7 @@ test_files:
198
202
  - spec/integration/tempster_spec.rb
199
203
  - spec/integration/examples_spec_editor.rb
200
204
  - spec/integration/download_spec.rb
205
+ - spec/integration/address_manager_spec.rb
201
206
  - spec/extras/scratch.rb
202
207
  - spec/extras/automateit_service_sysv_test
203
208
  - spec/extras/simple_recipe.rb
metadata.gz.sig CHANGED
Binary file