diff options
| author | Luke Kanies <luke@reductivelabs.com> | 2009-12-21 16:23:44 -0800 |
|---|---|---|
| committer | Luke Kanies <luke@reductivelabs.com> | 2009-12-21 16:23:44 -0800 |
| commit | 740fd6b301af89ab3aad89bca183ad1fcdc24ac4 (patch) | |
| tree | f34617a229509c373d28d67abb453e7ae2136c39 /spec/unit/util | |
| parent | 8971d8beae2c409f9052f27c3f80ad3bdfff4de2 (diff) | |
| parent | 4a06379f8770c164e42bcc410d874076c6e95f24 (diff) | |
| download | puppet-740fd6b301af89ab3aad89bca183ad1fcdc24ac4.tar.gz puppet-740fd6b301af89ab3aad89bca183ad1fcdc24ac4.tar.xz puppet-740fd6b301af89ab3aad89bca183ad1fcdc24ac4.zip | |
Merge branch '0.25.x'
Conflicts:
lib/puppet/agent.rb
lib/puppet/application/puppetd.rb
lib/puppet/parser/ast/leaf.rb
lib/puppet/util/rdoc/parser.rb
Diffstat (limited to 'spec/unit/util')
| -rwxr-xr-x | spec/unit/util/log.rb | 36 | ||||
| -rw-r--r-- | spec/unit/util/monkey_patches.rb | 103 | ||||
| -rwxr-xr-x | spec/unit/util/selinux.rb | 42 | ||||
| -rwxr-xr-x | spec/unit/util/tagging.rb | 10 |
4 files changed, 191 insertions, 0 deletions
diff --git a/spec/unit/util/log.rb b/spec/unit/util/log.rb index 4e2c8dcc5..35e6a71e8 100755 --- a/spec/unit/util/log.rb +++ b/spec/unit/util/log.rb @@ -13,6 +13,42 @@ describe Puppet::Util::Log do Puppet::Util::Log.close_all end + describe Puppet::Util::Log::DestConsole do + before do + @console = Puppet::Util::Log::DestConsole.new + end + + it "should colorize if Puppet[:color] is :ansi" do + Puppet[:color] = :ansi + + @console.colorize(:alert, "abc").should == "\e[0;31mabc\e[0m" + end + + it "should colorize if Puppet[:color] is 'yes'" do + Puppet[:color] = "yes" + + @console.colorize(:alert, "abc").should == "\e[0;31mabc\e[0m" + end + + it "should htmlize if Puppet[:color] is :html" do + Puppet[:color] = :html + + @console.colorize(:alert, "abc").should == "<span style=\"color: FFA0A0\">abc</span>" + end + + it "should do nothing if Puppet[:color] is false" do + Puppet[:color] = false + + @console.colorize(:alert, "abc").should == "abc" + end + + it "should do nothing if Puppet[:color] is invalid" do + Puppet[:color] = "invalid option" + + @console.colorize(:alert, "abc").should == "abc" + end + end + describe "instances" do before do Puppet::Util::Log.stubs(:newmessage) diff --git a/spec/unit/util/monkey_patches.rb b/spec/unit/util/monkey_patches.rb new file mode 100644 index 000000000..335f90b86 --- /dev/null +++ b/spec/unit/util/monkey_patches.rb @@ -0,0 +1,103 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + +require 'puppet/util/monkey_patches' + +describe RDoc do + it "should return the call stack if a script is called directly" do + stack = [ + "/usr/lib/ruby/1.8/rdoc/usage.rb:99:in `usage_no_exit'", + "/usr/lib/ruby/1.8/rdoc/usage.rb:93:in `usage'", + "./puppet/application.rb:295:in `help'", + "./puppet/application.rb:207:in `handle_help'", + "./puppet/application.rb:141:in `send'", + "./puppet/application.rb:141:in `option'", + "/usr/lib/ruby/1.8/optparse.rb:1267:in `call'", + "/usr/lib/ruby/1.8/optparse.rb:1267:in `parse_in_order'", + "/usr/lib/ruby/1.8/optparse.rb:1254:in `catch'", + "/usr/lib/ruby/1.8/optparse.rb:1254:in `parse_in_order'", + "/usr/lib/ruby/1.8/optparse.rb:1248:in `order!'", + "/usr/lib/ruby/1.8/optparse.rb:1339:in `permute!'", + "/usr/lib/ruby/1.8/optparse.rb:1360:in `parse!'", + "./puppet/application.rb:262:in `parse_options'", + "./puppet/application.rb:214:in `run'", + "./puppet/application.rb:306:in `exit_on_fail'", + "./puppet/application.rb:214:in `run'", + "../bin/puppet:71" + ] + + old_dollar_zero = $0 + $0 = "../bin/puppet" + + # Mocha explodes if you try to mock :caller directly + Kernel.expects( :mock_caller ).returns( stack ) + Kernel.instance_eval { alias orig_caller caller } + Kernel.instance_eval { alias caller mock_caller } + + RDoc.caller.must == stack + + $0 = old_dollar_zero + Kernel.instance_eval { alias caller orig_caller } + end + + it "should return a truncated call stack if a script is called from a rubygems stub" do + gem_stack = [ + "/usr/lib/ruby/1.8/rdoc/usage.rb:99:in `usage_no_exit'", + "/usr/lib/ruby/1.8/rdoc/usage.rb:93:in `usage'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:295:in `help'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:207:in `handle_help'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:141:in `send'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:141:in `option'", + "/usr/lib/ruby/1.8/optparse.rb:1267:in `call'", + "/usr/lib/ruby/1.8/optparse.rb:1267:in `parse_in_order'", + "/usr/lib/ruby/1.8/optparse.rb:1254:in `catch'", + "/usr/lib/ruby/1.8/optparse.rb:1254:in `parse_in_order'", + "/usr/lib/ruby/1.8/optparse.rb:1248:in `order!'", + "/usr/lib/ruby/1.8/optparse.rb:1339:in `permute!'", + "/usr/lib/ruby/1.8/optparse.rb:1360:in `parse!'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:262:in `parse_options'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:214:in `run'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:306:in `exit_on_fail'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:214:in `run'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/bin/puppet:71", + "/usr/bin/puppet:19:in `load'", + "/usr/bin/puppet:19" + ] + + real_stack = [ + "/usr/lib/ruby/1.8/rdoc/usage.rb:99:in `usage_no_exit'", + "/usr/lib/ruby/1.8/rdoc/usage.rb:93:in `usage'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:295:in `help'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:207:in `handle_help'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:141:in `send'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:141:in `option'", + "/usr/lib/ruby/1.8/optparse.rb:1267:in `call'", + "/usr/lib/ruby/1.8/optparse.rb:1267:in `parse_in_order'", + "/usr/lib/ruby/1.8/optparse.rb:1254:in `catch'", + "/usr/lib/ruby/1.8/optparse.rb:1254:in `parse_in_order'", + "/usr/lib/ruby/1.8/optparse.rb:1248:in `order!'", + "/usr/lib/ruby/1.8/optparse.rb:1339:in `permute!'", + "/usr/lib/ruby/1.8/optparse.rb:1360:in `parse!'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:262:in `parse_options'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:214:in `run'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:306:in `exit_on_fail'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/lib/puppet/application.rb:214:in `run'", + "/usr/lib/ruby/gems/1.8/gems/puppet-0.25.1/bin/puppet:71", + ] + + old_dollar_zero = $0 + $0 = '/usr/bin/puppet' + + # Mocha explodes if you try to mock :caller directly + Kernel.expects( :mock_caller ).returns( gem_stack ) + Kernel.instance_eval { alias orig_caller caller } + Kernel.instance_eval { alias caller mock_caller } + + RDoc.caller.must == real_stack + + $0 = old_dollar_zero + Kernel.instance_eval { alias caller orig_caller } + end +end + diff --git a/spec/unit/util/selinux.rb b/spec/unit/util/selinux.rb index da4686ec4..7e6cdaf30 100755 --- a/spec/unit/util/selinux.rb +++ b/spec/unit/util/selinux.rb @@ -61,6 +61,42 @@ describe Puppet::Util::SELinux do selinux_label_support?('/mnt/nfs/testfile').should be_false end + it "should follow symlinks when determining file systems" do + self.stubs(:realpath).with('/mnt/symlink/testfile').returns('/mnt/nfs/dest/testfile') + + selinux_label_support?('/mnt/symlink/testfile').should be_false + end + + end + + describe "realpath" do + it "should handle files that don't exist" do + + # Since I'm stubbing Pathname.new for this test, + # I need to also stub the internal calls to Pathname.new, + # which happen in Pathname.dirname and Parthname.basename + # I want those to return real Pathname objects, + # so I'm creating them before the stub is in place. + realpaths = Hash.new {|hash, path| hash[path] = Pathname.new(path) } + paths = ['symlink', '/mnt'] + paths.each { |path| realpaths[path] } + + realpaths['/mnt/symlink'] = stubs "Pathname" + realpaths['/mnt/symlink'].stubs(:realpath).returns(realpaths['/mnt/nfs/dest']) + realpaths['/mnt/symlink'].stubs(:exist?).returns(true) + + realpaths['/mnt/symlink/nonexistant'] = stubs "Pathname" + realpaths['/mnt/symlink/nonexistant'].stubs(:realpath).raises(Errno::ENOENT) + realpaths['/mnt/symlink/nonexistant'].stubs(:exist?).returns(false) + realpaths['/mnt/symlink/nonexistant'].stubs(:dirname).returns(realpaths['/mnt/symlink']) + realpaths['/mnt/symlink/nonexistant'].stubs(:basename).returns(realpaths['nonexistant']) + + realpaths.each do |path, value| + Pathname.stubs(:new).with(path).returns(value) + end + + realpath('/mnt/symlink/nonexistant').should == '/mnt/nfs/dest/nonexistant' + end end describe "get_selinux_current_context" do @@ -158,6 +194,12 @@ describe Puppet::Util::SELinux do set_selinux_context("/foo", "user_u:role_r:type_t:s0").should be_nil end + it "should return nil if selinux_label_support returns false" do + self.expects(:selinux_support?).returns true + self.expects(:selinux_label_support?).with("/foo").returns false + set_selinux_context("/foo", "user_u:role_r:type_t:s0").should be_nil + end + it "should use lsetfilecon to set a context" do self.expects(:selinux_support?).returns true Selinux.expects(:lsetfilecon).with("/foo", "user_u:role_r:type_t:s0").returns 0 diff --git a/spec/unit/util/tagging.rb b/spec/unit/util/tagging.rb index d61ee8ccb..3486f46f2 100755 --- a/spec/unit/util/tagging.rb +++ b/spec/unit/util/tagging.rb @@ -89,4 +89,14 @@ describe Puppet::Util::Tagging, "when adding tags" do it "should indicate when the object is not tagged with a provided tag" do @tagger.should_not be_tagged("one") end + + it "should indicate when the object is tagged with any tag in an array" do + @tagger.tag("one") + @tagger.should be_tagged("one","two","three") + end + + it "should indicate when the object is not tagged with any tag in an array" do + @tagger.tag("one") + @tagger.should_not be_tagged("two","three") + end end |
