summaryrefslogtreecommitdiffstats
path: root/spec/unit/agent
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/agent')
-rwxr-xr-xspec/unit/agent/downloader.rb182
-rwxr-xr-xspec/unit/agent/fact_handler.rb90
-rwxr-xr-xspec/unit/agent/locker.rb14
-rwxr-xr-xspec/unit/agent/plugin_handler.rb100
4 files changed, 14 insertions, 372 deletions
diff --git a/spec/unit/agent/downloader.rb b/spec/unit/agent/downloader.rb
deleted file mode 100755
index 28c5d030f..000000000
--- a/spec/unit/agent/downloader.rb
+++ /dev/null
@@ -1,182 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../spec_helper'
-
-require 'puppet/agent/downloader'
-
-describe Puppet::Agent::Downloader do
- it "should require a name" do
- lambda { Puppet::Agent::Downloader.new }.should raise_error(ArgumentError)
- end
-
- it "should require a path and a source at initialization" do
- lambda { Puppet::Agent::Downloader.new("name") }.should raise_error(ArgumentError)
- end
-
- it "should set the name, path and source appropriately" do
- dler = Puppet::Agent::Downloader.new("facts", "path", "source")
- dler.name.should == "facts"
- dler.path.should == "path"
- 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")
- end
-
- it "should create a file instance with the right path and source" do
- Puppet::Type.type(:file).expects(:create).with { |opts| opts[:path] == "path" and opts[:source] == "source" }
- @dler.file
- end
-
- it "should tag the file with the downloader name" do
- Puppet::Type.type(:file).expects(:create).with { |opts| opts[:tag] == "foo" }
- @dler.file
- end
-
- it "should always recurse" do
- Puppet::Type.type(:file).expects(:create).with { |opts| opts[:recurse] == true }
- @dler.file
- end
-
- it "should always purge" do
- Puppet::Type.type(:file).expects(:create).with { |opts| opts[:purge] == true }
- @dler.file
- end
-
- it "should never be in noop" do
- Puppet::Type.type(:file).expects(:create).with { |opts| opts[:noop] == false }
- @dler.file
- end
-
- it "should always set the owner to the current UID" do
- Process.expects(:uid).returns 51
- Puppet::Type.type(:file).expects(:create).with { |opts| opts[:owner] == 51 }
- @dler.file
- end
-
- it "should always set the group to the current GID" do
- Process.expects(:gid).returns 61
- Puppet::Type.type(:file).expects(:create).with { |opts| opts[:group] == 61 }
- @dler.file
- end
-
- it "should always force the download" do
- Puppet::Type.type(:file).expects(:create).with { |opts| opts[:force] == true }
- @dler.file
- end
-
- it "should never back up when downloading" do
- Puppet::Type.type(:file).expects(:create).with { |opts| opts[:backup] == false }
- @dler.file
- end
-
- it "should support providing an 'ignore' parameter" do
- Puppet::Type.type(:file).expects(:create).with { |opts| opts[:ignore] == ".svn" }
- @dler = Puppet::Agent::Downloader.new("foo", "path", "source", ".svn")
- @dler.file
- end
- end
-
- describe "when creating the catalog to do the downloading" do
- before do
- @dler = Puppet::Agent::Downloader.new("foo", "path", "source")
- end
-
- it "should create a catalog and add the file to it" do
- file = mock 'file'
- catalog = mock 'catalog'
-
- @dler.expects(:file).returns file
-
- Puppet::Resource::Catalog.expects(:new).returns catalog
- catalog.expects(:add_resource).with(file)
-
- @dler.catalog.should equal(catalog)
- end
- end
-
- describe "when downloading" do
- before do
- @dler = Puppet::Agent::Downloader.new("foo", "path", "source")
- end
-
- it "should log that it is downloading" do
- Puppet.expects(:info)
- Timeout.stubs(:timeout)
-
- @dler.evaluate
- end
-
- it "should set a timeout for the download" do
- Puppet::Agent::Downloader.expects(:timeout).returns 50
- Timeout.expects(:timeout).with(50)
-
- @dler.evaluate
- end
-
- it "should apply the catalog within the timeout block" do
- catalog = mock 'catalog'
- @dler.expects(:catalog).returns(catalog)
-
- Timeout.expects(:timeout).yields
-
- catalog.expects(:apply)
-
- @dler.evaluate
- end
-
- it "should return all changed file paths" do
- trans = mock 'transaction'
-
- catalog = mock 'catalog'
- @dler.expects(:catalog).returns(catalog)
- catalog.expects(:apply).yields(trans)
-
- Timeout.expects(:timeout).yields
-
- resource = mock 'resource'
- resource.expects(:[]).with(:path).returns "/changed/file"
-
- trans.expects(:changed?).returns([resource])
-
- @dler.evaluate.should == %w{/changed/file}
- end
-
- it "should yield the resources if a block is given" do
- trans = mock 'transaction'
-
- catalog = mock 'catalog'
- @dler.expects(:catalog).returns(catalog)
- catalog.expects(:apply).yields(trans)
-
- Timeout.expects(:timeout).yields
-
- resource = mock 'resource'
- resource.expects(:[]).with(:path).returns "/changed/file"
-
- trans.expects(:changed?).returns([resource])
-
- yielded = nil
- @dler.evaluate { |r| yielded = r }
- yielded.should == resource
- end
-
- it "should catch and log exceptions" do
- Puppet.expects(:err)
- Timeout.stubs(:timeout).raises(Puppet::Error, "testing")
-
- lambda { @dler.evaluate }.should_not raise_error
- end
- end
-end
diff --git a/spec/unit/agent/fact_handler.rb b/spec/unit/agent/fact_handler.rb
deleted file mode 100755
index 9622b0649..000000000
--- a/spec/unit/agent/fact_handler.rb
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../spec_helper'
-require 'puppet/agent'
-require 'puppet/agent/fact_handler'
-
-class FactHandlerTester
- include Puppet::Agent::FactHandler
-end
-
-describe Puppet::Agent::FactHandler do
- before do
- @facthandler = FactHandlerTester.new
- end
-
- it "should have a method for downloading fact plugins" do
- @facthandler.should respond_to(:download_fact_plugins)
- end
-
- it "should have a boolean method for determining whether fact plugins should be downloaded" do
- @facthandler.should respond_to(:download_fact_plugins?)
- end
-
- it "should download fact plugins when :factsync is true" do
- Puppet.settings.expects(:value).with(:factsync).returns true
- @facthandler.should be_download_fact_plugins
- end
-
- it "should not download fact plugins when :factsync is false" do
- Puppet.settings.expects(:value).with(:factsync).returns false
- @facthandler.should_not be_download_fact_plugins
- end
-
- it "should not download fact plugins when downloading is disabled" do
- Puppet::Agent::Downloader.expects(:new).never
- @facthandler.expects(:download_fact_plugins?).returns false
- @facthandler.download_fact_plugins
- end
-
- it "should use an Agent Downloader, with the name, source, destination, and ignore set correctly, to download fact plugins when downloading is enabled" do
- downloader = mock 'downloader'
-
- Puppet.settings.expects(:value).with(:factsource).returns "fsource"
- Puppet.settings.expects(:value).with(:factdest).returns "fdest"
- Puppet.settings.expects(:value).with(:factsignore).returns "fignore"
-
- Puppet::Agent::Downloader.expects(:new).with("fact", "fsource", "fdest", "fignore").returns downloader
-
- downloader.expects(:evaluate)
-
- @facthandler.expects(:download_fact_plugins?).returns true
- @facthandler.download_fact_plugins
- end
-
- it "should have a method for uploading facts" do
- @facthandler.should respond_to(:upload_facts)
- end
-
- it "should reload Facter and find local facts when asked to upload facts" do
- @facthandler.expects(:reload_facter)
-
- Puppet.settings.expects(:value).with(:certname).returns "myhost"
- Puppet::Node::Facts.expects(:find).with("myhost")
-
- @facthandler.upload_facts
- end
-
- describe "when reloading Facter" do
- before do
- Facter.stubs(:clear)
- Facter.stubs(:load)
- Facter.stubs(:loadfacts)
- end
-
- it "should clear Facter" do
- Facter.expects(:clear)
- @facthandler.reload_facter
- end
-
- it "should load all Facter facts" do
- Facter.expects(:loadfacts)
- @facthandler.reload_facter
- end
-
- it "should use the Facter terminus load all Puppet Fact plugins" do
- Puppet::Node::Facts::Facter.expects(:load_fact_plugins)
- @facthandler.reload_facter
- end
- end
-end
diff --git a/spec/unit/agent/locker.rb b/spec/unit/agent/locker.rb
index aae7c0c7b..1477c824e 100755
--- a/spec/unit/agent/locker.rb
+++ b/spec/unit/agent/locker.rb
@@ -11,12 +11,21 @@ end
describe Puppet::Agent::Locker do
before do
@locker = LockerTester.new
+ @locker.stubs(:lockfile_path).returns "/my/lock"
end
it "should use a Pidlock instance as its lockfile" do
@locker.lockfile.should be_instance_of(Puppet::Util::Pidlock)
end
+ it "should use 'lockfile_path' to determine its lockfile path" do
+ @locker.expects(:lockfile_path).returns "/my/lock"
+ lock = Puppet::Util::Pidlock.new("/my/lock")
+ Puppet::Util::Pidlock.expects(:new).with("/my/lock").returns lock
+
+ @locker.lockfile
+ end
+
it "should reuse the same lock file each time" do
@locker.lockfile.should equal(@locker.lockfile)
end
@@ -83,4 +92,9 @@ describe Puppet::Agent::Locker do
lambda { @locker.lock { raise "foo" } }.should raise_error(RuntimeError)
end
+
+ it "should be considered running if the lockfile is locked" do
+ @locker.lockfile.expects(:locked?).returns true
+ @locker.should be_running
+ end
end
diff --git a/spec/unit/agent/plugin_handler.rb b/spec/unit/agent/plugin_handler.rb
deleted file mode 100755
index 44603bc6c..000000000
--- a/spec/unit/agent/plugin_handler.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../spec_helper'
-require 'puppet/agent'
-require 'puppet/agent/plugin_handler'
-
-class PluginHandlerTester
- include Puppet::Agent::PluginHandler
-end
-
-describe Puppet::Agent::PluginHandler do
- before do
- @pluginhandler = PluginHandlerTester.new
- end
-
- it "should have a method for downloading plugins" do
- @pluginhandler.should respond_to(:download_plugins)
- end
-
- it "should have a boolean method for determining whether plugins should be downloaded" do
- @pluginhandler.should respond_to(:download_plugins?)
- end
-
- it "should download plugins when :pluginsync is true" do
- Puppet.settings.expects(:value).with(:pluginsync).returns true
- @pluginhandler.should be_download_plugins
- end
-
- it "should not download plugins when :pluginsync is false" do
- Puppet.settings.expects(:value).with(:pluginsync).returns false
- @pluginhandler.should_not be_download_plugins
- end
-
- it "should not download plugins when downloading is disabled" do
- Puppet::Agent::Downloader.expects(:new).never
- @pluginhandler.expects(:download_plugins?).returns false
- @pluginhandler.download_plugins
- end
-
- it "should use an Agent Downloader, with the name, source, destination, and ignore set correctly, to download plugins when downloading is enabled" do
- downloader = mock 'downloader'
-
- Puppet.settings.expects(:value).with(:pluginsource).returns "psource"
- Puppet.settings.expects(:value).with(:plugindest).returns "pdest"
- Puppet.settings.expects(:value).with(:pluginsignore).returns "pignore"
-
- Puppet::Agent::Downloader.expects(:new).with("plugin", "psource", "pdest", "pignore").returns downloader
-
- downloader.expects(:evaluate).returns []
-
- @pluginhandler.expects(:download_plugins?).returns true
- @pluginhandler.download_plugins
- end
-
- it "should be able to load plugins" do
- @pluginhandler.should respond_to(:load_plugin)
- end
-
- it "should load each downloaded file" do
- downloader = mock 'downloader'
-
- Puppet::Agent::Downloader.expects(:new).returns downloader
-
- downloader.expects(:evaluate).returns %w{one two}
-
- @pluginhandler.expects(:download_plugins?).returns true
-
- @pluginhandler.expects(:load_plugin).with("one")
- @pluginhandler.expects(:load_plugin).with("two")
-
- @pluginhandler.download_plugins
- end
-
- it "should load plugins when asked to do so" do
- @pluginhandler.expects(:load).with("foo")
-
- @pluginhandler.load_plugin("foo")
- end
-
- it "should not try to load directories" do
- FileTest.expects(:directory?).with("foo").returns true
- @pluginhandler.expects(:load).never
-
- @pluginhandler.load_plugin("foo")
- end
-
- it "should warn but not fail if loading a file raises an exception" do
- @pluginhandler.expects(:load).with("foo").raises "eh"
-
- Puppet.expects(:err)
- @pluginhandler.load_plugin("foo")
- end
-
- it "should warn but not fail if loading a file raises a LoadError" do
- @pluginhandler.expects(:load).with("foo").raises LoadError.new("eh")
-
- Puppet.expects(:err)
- @pluginhandler.load_plugin("foo")
- end
-end