summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-01-19 16:29:17 -0600
committerLuke Kanies <luke@madstop.com>2009-02-06 18:08:39 -0600
commit8f5cbc349daa868020b009851ee97ea3f29fcfbf (patch)
tree5cfc7826cb90d7daf8aa1014b83ee1877255ebee /spec
parent25b28c58c22bae718794dc679f10c61665af0b15 (diff)
downloadpuppet-8f5cbc349daa868020b009851ee97ea3f29fcfbf.tar.gz
puppet-8f5cbc349daa868020b009851ee97ea3f29fcfbf.tar.xz
puppet-8f5cbc349daa868020b009851ee97ea3f29fcfbf.zip
This is work that I've decided not to keep
so I'm just applying it here so it continues to show up in the history in case I ever want to look at it again. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/agent.rb219
-rwxr-xr-xspec/unit/agent/downloader.rb19
-rwxr-xr-xspec/unit/agent/splayer.rb42
3 files changed, 238 insertions, 42 deletions
diff --git a/spec/unit/agent.rb b/spec/unit/agent.rb
index 63914c3a3..a564308be 100755
--- a/spec/unit/agent.rb
+++ b/spec/unit/agent.rb
@@ -5,6 +5,66 @@ require File.dirname(__FILE__) + '/../spec_helper'
require 'puppet/agent'
describe Puppet::Agent do
+ it "should be able to provide a timeout value" do
+ Puppet::Agent.should respond_to(:timeout)
+ end
+
+ it "should use the configtimeout, converted to an integer, as its timeout" do
+ Puppet.settings.expects(:value).with(:configtimeout).returns "50"
+ Puppet::Agent.timeout.should == 50
+ end
+
+ describe "when managing the lockfile" do
+ after do
+ Puppet::Agent.instance_variable_set("@lockfile", nil)
+ end
+
+ it "should use Pidlock to manage the lock file itself" do
+ Puppet::Agent.instance_variable_set("@lockfile", nil)
+
+ Puppet.settings.expects(:value).with(:puppetdlockfile).returns "/lock/file"
+ Puppet::Util::Pidlock.expects(:new).with("/lock/file").returns "mylock"
+
+ Puppet::Agent.lockfile.should == "mylock"
+ end
+
+ it "should always reuse the same lock file instance" do
+ Puppet::Agent.lockfile.should equal(Puppet::Agent.lockfile)
+ end
+
+ it "should have a class method for disabling the agent" do
+ Puppet::Agent.should respond_to(:disable)
+ end
+
+ it "should have a class method for enabling the agent" do
+ Puppet::Agent.should respond_to(:enable)
+ end
+
+ it "should use the lockfile to disable the agent anonymously" do
+ Puppet::Agent.lockfile.expects(:lock).with(:anonymous => true)
+ Puppet::Agent.disable
+ end
+
+ it "should use the lockfile to enable the agent anonymously" do
+ Puppet::Agent.lockfile.expects(:unlock).with(:anonymous => true)
+ Puppet::Agent.enable
+ end
+
+ it "should have a class method for determining whether the agent is enabled" do
+ Puppet::Agent.should respond_to(:enabled?)
+ end
+
+ it "should consider the agent enabled if the lockfile is not locked" do
+ Puppet::Agent.lockfile.expects(:locked?).returns false
+ Puppet::Agent.should be_enabled
+ end
+
+ it "should consider the agent disabled if the lockfile is locked" do
+ Puppet::Agent.lockfile.expects(:locked?).returns true
+ Puppet::Agent.should_not be_enabled
+ end
+ end
+
it "should have a start method" do
Puppet::Agent.new.should respond_to(:start)
end
@@ -32,22 +92,22 @@ describe Puppet::Agent do
@agent.stubs(:name).returns "foo"
Puppet.settings.stubs(:value).with(:splaylimit).returns "1800"
- Puppet.settings.stubs(:value).with(:splaylimit).returns "1800"
+ Puppet.settings.stubs(:value).with(:splay).returns true
end
- it "should do nothing if splay is disabled" do
- Puppet.settings.expects(:value).with(:splay).returns false
- @agent.expects(:sleep).never
- @agent.splay
- end
-
- it "should sleep if splay is enabled" do
+ it "should sleep if it has not previously splayed" do
Puppet.settings.expects(:value).with(:splay).returns true
@agent.expects(:sleep)
@agent.splay
end
+
+ it "should do nothing if it has already splayed" do
+ @agent.expects(:sleep).once
+ @agent.splay
+ @agent.splay
+ end
- it "should log when splay is enabled" do
+ it "should log if it is sleeping" do
Puppet.settings.expects(:value).with(:splay).returns true
@agent.stubs(:sleep)
@@ -57,22 +117,125 @@ describe Puppet::Agent do
end
end
- it "should default to using splay time"
+ describe "when running" do
+ before do
+ @agent = Puppet::Agent.new
+ [:upload_facts, :download_catalog, :apply].each { |m| @agent.stubs(m) }
+ end
- it "should be able to ignore splay time"
+ it "should splay if splay is enabled" do
+ @agent.expects(:splay?).returns true
+ @agent.expects(:splay)
+ @agent.run
+ end
- it "should be able to retrieve facts"
+ it "should not splay if splay is disabled" do
+ @agent.expects(:splay?).returns false
+ @agent.expects(:splay).never
+ @agent.run
+ end
- describe "when running" do
- it "should download plugins"
+ it "should download plugins if plugin downloading is enabled" do
+ @agent.expects(:download_plugins?).returns true
+ @agent.expects(:download_plugins)
+ @agent.run
+ end
+
+ it "should not download plugins if plugin downloading is disabled" do
+ @agent.expects(:download_plugins?).returns false
+ @agent.expects(:download_plugins).never
+ @agent.run
+ end
+
+ it "should download facts if fact downloading is enabled" do
+ @agent.expects(:download_facts?).returns true
+ @agent.expects(:download_facts)
+ @agent.run
+ end
+
+ it "should not download facts if fact downloading is disabled" do
+ @agent.expects(:download_facts?).returns false
+ @agent.expects(:download_facts).never
+ @agent.run
+ end
+
+ it "should retrieve the facts and save them to the server" do
+ @agent.expects(:upload_facts)
+ @agent.run
+ end
+
+ it "should retrieve the catalog" do
+ @agent.expects(:download_catalog)
+ @agent.run
+ end
+
+ it "should apply the catalog" do
+ catalog = mock("catalog")
+ @agent.expects(:download_catalog).returns catalog
+ @agent.expects(:apply).with(catalog)
+ @agent.run
+ end
+ end
+
+ describe "when downloading plugins" do
+ before do
+ @agent = Puppet::Agent.new
+ @downloader = stub 'downloader', :evaluate
+ end
- it "should download facts"
+ it "should download plugins if the :pluginsync setting is true" do
+ Puppet.settings.expects(:value).with(:pluginsync).returns true
+ @agent.should be_download_plugins
+ end
- it "should retrieve the facts and save them to the server"
+ it "should not download plugins if the :pluginsync setting is false" do
+ Puppet.settings.expects(:value).with(:pluginsync).returns false
+ @agent.should_not be_download_plugins
+ end
+
+ it "should use a Downloader instance with its name set to 'plugin' and the pluginsource, plugindest, and pluginsignore settings" do
+ Puppet.settings.expects(:value).with(:pluginsource).returns "plugsource"
+ Puppet.settings.expects(:value).with(:plugindest).returns "plugdest"
+ Puppet.settings.expects(:value).with(:pluginsignore).returns "plugig"
+ Puppet::Agent::Downloader.expects(:new).with("plugin", "plugsource", "plugdest", "plugig").returns @downloader
+ @downloader.expects(:evaluate)
+ @agent.download_plugins
+ end
+ end
- it "should retrieve the catalog"
+ describe "when downloading facts" do
+ before do
+ @agent = Puppet::Agent.new
+ @downloader = stub 'downloader', :evaluate
+ end
- it "should apply the catalog"
+ it "should download facts if the :factsync setting is true" do
+ Puppet.settings.expects(:value).with(:factsync).returns true
+ @agent.should be_download_facts
+ end
+
+ it "should not download facts if the :factsync setting is false" do
+ Puppet.settings.expects(:value).with(:factsync).returns false
+ @agent.should_not be_download_facts
+ end
+
+ it "should use a Downloader instance with its name set to 'facts' and the factssource, factsdest, and factsignore settings" do
+ Puppet.settings.expects(:value).with(:factsource).returns "factsource"
+ Puppet.settings.expects(:value).with(:factdest).returns "factdest"
+ Puppet.settings.expects(:value).with(:factsignore).returns "factig"
+ Puppet::Agent::Downloader.expects(:new).with("fact", "factsource", "factdest", "factig").returns @downloader
+ @downloader.expects(:evaluate)
+ @agent.download_facts
+ end
+ end
+
+ describe "when uploading facts" do
+ it "should just retrieve the facts for the current host" do
+ @agent = Puppet::Agent.new
+
+ Puppet::Node::Facts.expects(:find).with(Puppet[:certname])
+ @agent.upload_facts
+ end
end
describe "when retrieving the catalog" do
@@ -84,34 +247,34 @@ describe Puppet::Agent do
end
it "should use the Catalog class to find the catalog" do
- Puppet::Node::Catalog.expects(:find).with { |name, options| name == "me" }.returns @catalog
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| name == "me" }.returns @catalog
- @agent.catalog.should equal(@catalog)
+ @agent.download_catalog.should equal(@catalog)
end
it "should default to allowing use of the cache" do
- Puppet::Node::Catalog.expects(:find).with { |name, options| options[:use_cache] == true }.returns @catalog
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == true }.returns @catalog
- @agent.catalog
+ @agent.download_catalog
end
it "should ignore a cached catalog if configured to do so" do
Puppet.settings.expects(:value).with(:ignorecache).returns true
- Puppet::Node::Catalog.expects(:find).with { |name, options| options[:use_cache] == false }.returns @catalog
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == false }.returns @catalog
- @agent.catalog
+ @agent.download_catalog
end
it "should mark the catalog as a host catalog" do
@catalog.expects(:host_config=).with true
- Puppet::Node::Catalog.expects(:find).returns @catalog
+ Puppet::Resource::Catalog.expects(:find).returns @catalog
- @agent.catalog
+ @agent.download_catalog
end
it "should fail if a catalog can not be retrieved" do
- Puppet::Node::Catalog.expects(:find).returns nil
- lambda { @agent.catalog }.should raise_error(RuntimeError)
+ Puppet::Resource::Catalog.expects(:find).returns nil
+ lambda { @agent.download_catalog }.should raise_error(RuntimeError)
end
end
end
diff --git a/spec/unit/agent/downloader.rb b/spec/unit/agent/downloader.rb
index 6b07e5bb4..5c53de824 100755
--- a/spec/unit/agent/downloader.rb
+++ b/spec/unit/agent/downloader.rb
@@ -20,15 +20,6 @@ describe Puppet::Agent::Downloader do
dler.source.should == "source"
end
- it "should be able to provide a timeout value" do
- Puppet::Agent::Downloader.should respond_to(:timeout)
- end
-
- it "should use the configtimeout, converted to an integer, as its timeout" do
- Puppet.settings.expects(:value).with(:configtimeout).returns "50"
- Puppet::Agent::Downloader.timeout.should == 50
- end
-
describe "when creating the file that does the downloading" do
before do
@dler = Puppet::Agent::Downloader.new("foo", "path", "source")
@@ -118,8 +109,8 @@ describe Puppet::Agent::Downloader do
@dler.evaluate
end
- it "should set a timeout for the download" do
- Puppet::Agent::Downloader.expects(:timeout).returns 50
+ it "should use the agent timeout for the download" do
+ Puppet::Agent.expects(:timeout).returns 50
Timeout.expects(:timeout).with(50)
@dler.evaluate
@@ -153,7 +144,7 @@ describe Puppet::Agent::Downloader do
@dler.evaluate.should == %w{/changed/file}
end
- it "should yield the resources if a block is given" do
+ it "should yield the downloaded file's path if a block is given" do
trans = mock 'transaction'
catalog = mock 'catalog'
@@ -163,13 +154,13 @@ describe Puppet::Agent::Downloader do
Timeout.expects(:timeout).yields
resource = mock 'resource'
- resource.expects(:[]).with(:path).returns "/changed/file"
+ resource.stubs(:[]).with(:path).returns "/changed/file"
trans.expects(:changed?).returns([resource])
yielded = nil
@dler.evaluate { |r| yielded = r }
- yielded.should == resource
+ yielded.should == "/changed/file"
end
it "should catch and log exceptions" do
diff --git a/spec/unit/agent/splayer.rb b/spec/unit/agent/splayer.rb
new file mode 100755
index 000000000..e097cc98b
--- /dev/null
+++ b/spec/unit/agent/splayer.rb
@@ -0,0 +1,42 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/agent/splayer'
+
+describe Puppet::Agent::Splayer do
+ it "should be able to splay" do
+ Puppet::Agent::Splayer.new.should respond_to(:splay)
+ end
+
+ describe "when splaying" do
+ before do
+ @agent = Puppet::Agent::Splayer.new
+ @agent.stubs(:name).returns "foo"
+
+ Puppet.settings.stubs(:value).with(:splaylimit).returns "1800"
+ Puppet.settings.stubs(:value).with(:splay).returns true
+ end
+
+ it "should sleep if it has not previously splayed" do
+ Puppet.settings.expects(:value).with(:splay).returns true
+ @agent.expects(:sleep)
+ @agent.splay
+ end
+
+ it "should do nothing if it has already splayed" do
+ @agent.expects(:sleep).once
+ @agent.splay
+ @agent.splay
+ end
+
+ it "should log if it is sleeping" do
+ Puppet.settings.expects(:value).with(:splay).returns true
+ @agent.stubs(:sleep)
+
+ Puppet.expects(:info)
+
+ @agent.splay
+ end
+ end
+end