summaryrefslogtreecommitdiffstats
path: root/spec/unit/util
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2010-01-13 08:07:30 +1100
committerJames Turnbull <james@lovedthanlost.net>2010-01-13 08:07:30 +1100
commitb6f90dfcd96123c245b6f5fd93753790006387c0 (patch)
tree1668fd8ed480dc0d0cb49c4a3d7f8a13c77dbeb9 /spec/unit/util
parente26e8319186c57a41ea7ca58b0e8e853e9b452e3 (diff)
parentf7e14356ad7781fafa52a459d3c24372fa6c0900 (diff)
downloadpuppet-b6f90dfcd96123c245b6f5fd93753790006387c0.tar.gz
puppet-b6f90dfcd96123c245b6f5fd93753790006387c0.tar.xz
puppet-b6f90dfcd96123c245b6f5fd93753790006387c0.zip
Merge branch '0.25.x'
Conflicts: lib/puppet/ssl/host.rb spec/spec_helper.rb
Diffstat (limited to 'spec/unit/util')
-rwxr-xr-xspec/unit/util/autoload.rb2
-rwxr-xr-xspec/unit/util/ldap/connection.rb2
-rwxr-xr-xspec/unit/util/log.rb14
-rwxr-xr-xspec/unit/util/queue.rb12
-rwxr-xr-xspec/unit/util/selinux.rb21
-rwxr-xr-xspec/unit/util/settings.rb19
6 files changed, 65 insertions, 5 deletions
diff --git a/spec/unit/util/autoload.rb b/spec/unit/util/autoload.rb
index 18938125d..4e1384246 100755
--- a/spec/unit/util/autoload.rb
+++ b/spec/unit/util/autoload.rb
@@ -111,6 +111,8 @@ describe Puppet::Util::Autoload do
before do
@autoload.stubs(:searchpath).returns %w{/a}
Dir.stubs(:glob).returns "/path/to/file.rb"
+
+ @autoload.class.stubs(:loaded?).returns(false)
end
[RuntimeError, LoadError, SyntaxError].each do |error|
diff --git a/spec/unit/util/ldap/connection.rb b/spec/unit/util/ldap/connection.rb
index 8bc85a620..bead64d01 100755
--- a/spec/unit/util/ldap/connection.rb
+++ b/spec/unit/util/ldap/connection.rb
@@ -8,7 +8,7 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/util/ldap/connection'
# So our mocks and such all work, even when ldap isn't available.
-unless defined?(LDAP::Conn)
+unless Puppet.features.ldap?
class LDAP
class Conn
def initialize(*args)
diff --git a/spec/unit/util/log.rb b/spec/unit/util/log.rb
index 35e6a71e8..97fb2f297 100755
--- a/spec/unit/util/log.rb
+++ b/spec/unit/util/log.rb
@@ -157,6 +157,20 @@ describe Puppet::Util::Log do
end
end
+ it "should use the source_descriptors" do
+ source = stub "source"
+ source.stubs(:source_descriptors).returns(:tags => ["tag","tag2"], :path => "path", :version => 100)
+
+ log = Puppet::Util::Log.new(:level => "notice", :message => :foo)
+ log.expects(:tag).with("tag")
+ log.expects(:tag).with("tag2")
+ log.expects(:version=).with(100)
+
+ log.source = source
+
+ log.source.should == "path"
+ end
+
it "should copy over any version information" do
catalog = Puppet::Resource::Catalog.new
catalog.version = 25
diff --git a/spec/unit/util/queue.rb b/spec/unit/util/queue.rb
index 19af9430e..c8a75550e 100755
--- a/spec/unit/util/queue.rb
+++ b/spec/unit/util/queue.rb
@@ -19,16 +19,24 @@ end
mod = Puppet::Util::Queue
client_classes = { :default => make_test_client_class('Bogus::Default'), :setup => make_test_client_class('Bogus::Setup') }
-mod.register_queue_type(client_classes[:default], :default)
-mod.register_queue_type(client_classes[:setup], :setup)
describe Puppet::Util::Queue do
+ before :all do
+ mod.register_queue_type(client_classes[:default], :default)
+ mod.register_queue_type(client_classes[:setup], :setup)
+ end
+
before :each do
@class = Class.new do
extend mod
end
end
+ after :all do
+ instances = mod.instance_hash(:queue_clients)
+ [:default, :setup, :bogus, :aardvark, :conflict, :test_a, :test_b].each{ |x| instances.delete(x) }
+ end
+
context 'when determining a type name from a class' do
it 'should handle a simple one-word class name' do
mod.queue_type_from_class(make_test_client_class('Foo')).should == :foo
diff --git a/spec/unit/util/selinux.rb b/spec/unit/util/selinux.rb
index 7e6cdaf30..88f4ac809 100755
--- a/spec/unit/util/selinux.rb
+++ b/spec/unit/util/selinux.rb
@@ -27,7 +27,12 @@ describe Puppet::Util::SELinux do
Selinux.expects(:is_selinux_enabled).returns 0
selinux_support?.should be_false
end
- end
+
+ it "should return nil if /proc/mounts does not exist" do
+ File.stubs(:open).with("/proc/mounts").raises("No such file or directory - /proc/mounts")
+ read_mounts.should == nil
+ end
+ end
describe "filesystem detection" do
before :each do
@@ -189,7 +194,19 @@ describe Puppet::Util::SELinux do
end
describe "set_selinux_context" do
- it "should return nil if there is no SELinux support" do
+ before :each do
+ fh = stub 'fh', :close => nil
+ File.stubs(:open).with("/proc/mounts").returns fh
+ fh.stubs(:read_nonblock).returns(
+ "rootfs / rootfs rw 0 0\n"+
+ "/dev/root / ext3 rw,relatime,errors=continue,user_xattr,acl,data=ordered 0 0\n"+
+ "/dev /dev tmpfs rw,relatime,mode=755 0 0\n"+
+ "/proc /proc proc rw,relatime 0 0\n"+
+ "/sys /sys sysfs rw,relatime 0 0\n"
+ ).then.raises EOFError
+ end
+
+ it "should return nil if there is no SELinux support" do
self.expects(:selinux_support?).returns false
set_selinux_context("/foo", "user_u:role_r:type_t:s0").should be_nil
end
diff --git a/spec/unit/util/settings.rb b/spec/unit/util/settings.rb
index 7527031de..4855df4b8 100755
--- a/spec/unit/util/settings.rb
+++ b/spec/unit/util/settings.rb
@@ -579,6 +579,25 @@ describe Puppet::Util::Settings do
# and we should now have the new value in memory
@settings[:two].should == "disk-replace"
end
+
+ it "should retain in-memory values if the file has a syntax error" do
+ # Init the value
+ text = "[main]\none = initial-value\n"
+ @settings.expects(:read_file).returns(text)
+ @settings.parse
+ @settings[:one].should == "initial-value"
+
+ # Now replace the value with something bogus
+ text = "[main]\nkenny = killed-by-what-follows\n1 is 2, blah blah florp\n"
+ @settings.expects(:read_file).returns(text)
+ @settings.parse
+
+ # The originally-overridden value should not be replaced with the default
+ @settings[:one].should == "initial-value"
+
+ # and we should not have the new value in memory
+ @settings[:kenny].should be_nil
+ end
end
it "should provide a method for creating a catalog of resources from its configuration" do