diff options
author | Luke Kanies <luke@madstop.com> | 2008-02-25 18:28:26 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-02-25 18:28:26 -0500 |
commit | 9d2f45df3d951ef59a44a7fb81a38586f04884b4 (patch) | |
tree | 0c97adcca32ba9ad2e20b2457f3db0c4b91f8376 /spec/unit | |
parent | 0afea69c06742eff1e8d8bd7df13c9c0e4c397c0 (diff) | |
parent | 04892ee723d1a687c83eb6c99b5c6a6c76bbcbc9 (diff) | |
download | puppet-9d2f45df3d951ef59a44a7fb81a38586f04884b4.tar.gz puppet-9d2f45df3d951ef59a44a7fb81a38586f04884b4.tar.xz puppet-9d2f45df3d951ef59a44a7fb81a38586f04884b4.zip |
Merge branch '0.24.x'
Diffstat (limited to 'spec/unit')
-rwxr-xr-x | spec/unit/file_serving/file_base.rb | 119 | ||||
-rwxr-xr-x | spec/unit/file_serving/metadata.rb | 75 | ||||
-rwxr-xr-x | spec/unit/network/http_pool.rb | 4 | ||||
-rwxr-xr-x | spec/unit/node/catalog.rb | 22 | ||||
-rwxr-xr-x | spec/unit/other/pgraph.rb | 1 | ||||
-rwxr-xr-x | spec/unit/other/transaction.rb | 2 | ||||
-rwxr-xr-x | spec/unit/parser/interpreter.rb | 1 | ||||
-rwxr-xr-x | spec/unit/ral/types/file.rb | 37 | ||||
-rwxr-xr-x | spec/unit/util/checksums.rb | 8 | ||||
-rwxr-xr-x | spec/unit/util/tagging.rb | 4 |
10 files changed, 197 insertions, 76 deletions
diff --git a/spec/unit/file_serving/file_base.rb b/spec/unit/file_serving/file_base.rb index 4c7724f7c..e1a61cd65 100755 --- a/spec/unit/file_serving/file_base.rb +++ b/spec/unit/file_serving/file_base.rb @@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/file_serving/file_base' -describe Puppet::FileServing::FileBase, " when initializing" do +describe Puppet::FileServing::FileBase do it "should accept a key in the form of a URI" do Puppet::FileServing::FileBase.new("puppet://host/module/dir/file").key.should == "puppet://host/module/dir/file" end @@ -30,72 +30,91 @@ describe Puppet::FileServing::FileBase, " when initializing" do FileTest.stubs(:exists?).returns(true) Puppet::FileServing::FileBase.new("puppet://host/module/dir/file", :relative_path => "my/file").relative_path.should == "my/file" end -end -describe Puppet::FileServing::FileBase, " when setting the base path" do - before do - @file = Puppet::FileServing::FileBase.new("puppet://host/module/dir/file") + it "should have a means of determining if the file exists" do + Puppet::FileServing::FileBase.new("blah").should respond_to(:exist?) end - it "should require that the base path be fully qualified" do - FileTest.stubs(:exists?).returns(true) - proc { @file.path = "unqualified/file" }.should raise_error(ArgumentError) + it "should correctly indicate if the file is present" do + File.expects(:lstat).with("/my/file").returns(mock("stat")) + Puppet::FileServing::FileBase.new("blah", :path => "/my/file").exist?.should be_true end -end -describe Puppet::FileServing::FileBase, " when setting the relative path" do - it "should require that the relative path be unqualified" do - @file = Puppet::FileServing::FileBase.new("puppet://host/module/dir/file") - FileTest.stubs(:exists?).returns(true) - proc { @file.relative_path = "/qualified/file" }.should raise_error(ArgumentError) + it "should correctly indicate if the file is asbsent" do + File.expects(:lstat).with("/my/file").raises RuntimeError + Puppet::FileServing::FileBase.new("blah", :path => "/my/file").exist?.should be_false end -end -describe Puppet::FileServing::FileBase, " when determining the full file path" do - before do - @file = Puppet::FileServing::FileBase.new("mykey", :path => "/this/file") - end + describe "when setting the base path" do + before do + @file = Puppet::FileServing::FileBase.new("puppet://host/module/dir/file") + end - it "should return the path if there is no relative path" do - @file.full_path.should == "/this/file" + it "should require that the base path be fully qualified" do + FileTest.stubs(:exists?).returns(true) + proc { @file.path = "unqualified/file" }.should raise_error(ArgumentError) + end end - it "should return the path joined with the relative path if there is a relative path" do - @file.relative_path = "not/qualified" - @file.full_path.should == "/this/file/not/qualified" + describe "when setting the relative path" do + it "should require that the relative path be unqualified" do + @file = Puppet::FileServing::FileBase.new("puppet://host/module/dir/file") + FileTest.stubs(:exists?).returns(true) + proc { @file.relative_path = "/qualified/file" }.should raise_error(ArgumentError) + end end - it "should should fail if there is no path set" do - @file = Puppet::FileServing::FileBase.new("not/qualified") - proc { @file.full_path }.should raise_error(ArgumentError) - end -end + describe "when determining the full file path" do + before do + @file = Puppet::FileServing::FileBase.new("mykey", :path => "/this/file") + end -describe Puppet::FileServing::FileBase, " when stat'ing files" do - before do - @file = Puppet::FileServing::FileBase.new("mykey", :path => "/this/file") - end + it "should return the path if there is no relative path" do + @file.full_path.should == "/this/file" + end - it "should stat the file's full path" do - @file.stubs(:full_path).returns("/this/file") - File.expects(:lstat).with("/this/file").returns stub("stat", :ftype => "file") - @file.stat - end + it "should return the path if the relative_path is set to ''" do + @file.relative_path = "" + @file.full_path.should == "/this/file" + end - it "should fail if the file does not exist" do - @file.stubs(:full_path).returns("/this/file") - File.expects(:lstat).with("/this/file").raises(Errno::ENOENT) - proc { @file.stat }.should raise_error(Errno::ENOENT) - end + it "should return the path joined with the relative path if there is a relative path and it is not set to '/' or ''" do + @file.relative_path = "not/qualified" + @file.full_path.should == "/this/file/not/qualified" + end - it "should use :lstat if :links is set to :manage" do - File.expects(:lstat).with("/this/file").returns stub("stat", :ftype => "file") - @file.stat + it "should should fail if there is no path set" do + @file = Puppet::FileServing::FileBase.new("not/qualified") + proc { @file.full_path }.should raise_error(ArgumentError) + end end - it "should use :stat if :links is set to :follow" do - File.expects(:stat).with("/this/file").returns stub("stat", :ftype => "file") - @file.links = :follow - @file.stat + describe "when stat'ing files" do + before do + @file = Puppet::FileServing::FileBase.new("mykey", :path => "/this/file") + end + + it "should stat the file's full path" do + @file.stubs(:full_path).returns("/this/file") + File.expects(:lstat).with("/this/file").returns stub("stat", :ftype => "file") + @file.stat + end + + it "should fail if the file does not exist" do + @file.stubs(:full_path).returns("/this/file") + File.expects(:lstat).with("/this/file").raises(Errno::ENOENT) + proc { @file.stat }.should raise_error(Errno::ENOENT) + end + + it "should use :lstat if :links is set to :manage" do + File.expects(:lstat).with("/this/file").returns stub("stat", :ftype => "file") + @file.stat + end + + it "should use :stat if :links is set to :follow" do + File.expects(:stat).with("/this/file").returns stub("stat", :ftype => "file") + @file.links = :follow + @file.stat + end end end diff --git a/spec/unit/file_serving/metadata.rb b/spec/unit/file_serving/metadata.rb index d31dd21f0..9743370c1 100755 --- a/spec/unit/file_serving/metadata.rb +++ b/spec/unit/file_serving/metadata.rb @@ -26,8 +26,8 @@ describe Puppet::FileServing::Metadata, " when finding the file to use for setti @metadata.path = @full - # Use a symlink because it's easier to test -- no checksumming - @stat = stub "stat", :uid => 10, :gid => 20, :mode => 0755, :ftype => "symlink" + # Use a link because it's easier to test -- no checksumming + @stat = stub "stat", :uid => 10, :gid => 20, :mode => 0755, :ftype => "link" end it "should accept a base path path to which the file should be relative" do @@ -55,17 +55,19 @@ end describe Puppet::FileServing::Metadata, " when collecting attributes" do before do @path = "/my/file" - @stat = stub 'stat', :uid => 10, :gid => 20, :mode => 0755, :ftype => "file" + # Use a real file mode, so we can validate the masking is done. + @stat = stub 'stat', :uid => 10, :gid => 20, :mode => 33261, :ftype => "file" File.stubs(:lstat).returns(@stat) - @filehandle = mock 'filehandle' - #@filehandle.expects(:read).with(512).returns("some content\n").then.returns(nil) - File.stubs(:open).with(@path, 'r').yields(@filehandle) @checksum = Digest::MD5.hexdigest("some content\n") @metadata = Puppet::FileServing::Metadata.new("file", :path => "/my/file") - @metadata.expects(:md5_file).returns(@checksum) + @metadata.stubs(:md5_file).returns(@checksum) @metadata.collect_attributes end + it "should be able to produce xmlrpc-style attribute information" do + @metadata.should respond_to(:attributes_with_tabs) + end + # LAK:FIXME This should actually change at some point it "should set the owner by id" do @metadata.owner.should be_instance_of(Fixnum) @@ -84,28 +86,63 @@ describe Puppet::FileServing::Metadata, " when collecting attributes" do @metadata.group.should == 20 end - it "should set the mode to a string version of the mode in octal" do - @metadata.mode.should == "755" - end - - it "should set the mode to the file's current mode" do - @metadata.mode.should == "755" + it "should set the mode to the file's masked mode" do + @metadata.mode.should == 0755 end it "should set the checksum to the file's current checksum" do @metadata.checksum.should == "{md5}" + @checksum end - it "should default to a checksum of type MD5" do - @metadata.checksum.should == "{md5}" + @checksum + describe "when managing files" do + it "should default to a checksum of type MD5" do + @metadata.checksum.should == "{md5}" + @checksum + end + + it "should produce tab-separated mode, type, owner, group, and checksum for xmlrpc" do + @metadata.attributes_with_tabs.should == "#{0755.to_s}\tfile\t10\t20\t{md5}#{@checksum}" + end + end + + describe "when managing directories" do + before do + @stat.stubs(:ftype).returns("directory") + @time = Time.now + @metadata.expects(:ctime_file).returns(@time) + @metadata.collect_attributes + end + + it "should only use checksums of type 'ctime' for directories" do + @metadata.checksum.should == "{ctime}" + @time.to_s + end + + it "should produce tab-separated mode, type, owner, group, and checksum for xmlrpc" do + @metadata.attributes_with_tabs.should == "#{0755.to_s}\tdirectory\t10\t20\t{ctime}#{@time.to_s}" + end + end + + describe "when managing links" do + before do + @stat.stubs(:ftype).returns("link") + File.expects(:readlink).with("/my/file").returns("/path/to/link") + @metadata.collect_attributes + end + + it "should read links instead of returning their checksums" do + @metadata.destination.should == "/path/to/link" + end + + it "should produce tab-separated mode, type, owner, group, and destination for xmlrpc" do + @metadata.attributes_with_tabs.should == "#{0755.to_s}\tlink\t10\t20\t/path/to/link" + end end end -describe Puppet::FileServing::Metadata, " when pointing to a symlink" do - it "should store the destination of the symlink in :destination if links are :manage" do +describe Puppet::FileServing::Metadata, " when pointing to a link" do + it "should store the destination of the link in :destination if links are :manage" do file = Puppet::FileServing::Metadata.new("mykey", :links => :manage, :path => "/base/path/my/file") - File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "symlink", :mode => 0755) + File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "link", :mode => 0755) File.expects(:readlink).with("/base/path/my/file").returns "/some/other/path" file.collect_attributes @@ -115,7 +152,7 @@ describe Puppet::FileServing::Metadata, " when pointing to a symlink" do it "should not collect the checksum" do file = Puppet::FileServing::Metadata.new("my/file", :links => :manage, :path => "/base/path/my/file") - File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "symlink", :mode => 0755) + File.expects(:lstat).with("/base/path/my/file").returns stub("stat", :uid => 1, :gid => 2, :ftype => "link", :mode => 0755) File.expects(:readlink).with("/base/path/my/file").returns "/some/other/path" file.collect_attributes diff --git a/spec/unit/network/http_pool.rb b/spec/unit/network/http_pool.rb index 49da7d8f3..503440274 100755 --- a/spec/unit/network/http_pool.rb +++ b/spec/unit/network/http_pool.rb @@ -19,6 +19,7 @@ describe Puppet::Network::HttpPool, " when adding certificate information to htt it "should add a certificate store" do Puppet::Network::HttpPool.stubs(:read_cert).returns(true) + Puppet::Network::HttpPool.stubs(:key).returns(:mykey) store = stub "store" OpenSSL::X509::Store.expects(:new).returns(store) store.stubs(:add_file) @@ -47,6 +48,7 @@ describe Puppet::Network::HttpPool, " when adding certificate information to htt it "should set the purpose of the cert store to OpenSSL::X509::PURPOSE_SSL_CLIENT" do Puppet::Network::HttpPool.stubs(:read_cert).returns(true) + Puppet::Network::HttpPool.stubs(:key).returns(:mykey) store = stub "store" OpenSSL::X509::Store.expects(:new).returns(store) store.stubs(:add_file) @@ -60,6 +62,7 @@ describe Puppet::Network::HttpPool, " when adding certificate information to htt it "should add the client certificate" do Puppet::Network::HttpPool.stubs(:read_cert).returns(true) Puppet::Network::HttpPool.stubs(:cert).returns(:mycert) + Puppet::Network::HttpPool.stubs(:key).returns(:mykey) [:cert_store=, :verify_mode=, :ca_file=, :key=].each { |method| @http.stubs(method) } @http.expects(:cert=).with(:mycert) @@ -79,6 +82,7 @@ describe Puppet::Network::HttpPool, " when adding certificate information to htt it "should set the verify mode to OpenSSL::SSL::VERIFY_PEER" do Puppet::Network::HttpPool.stubs(:read_cert).returns(true) + Puppet::Network::HttpPool.stubs(:key).returns(:mykey) [:key=, :cert=, :cert_store=, :ca_file=].each { |method| @http.stubs(method) } @http.expects(:verify_mode=).with(OpenSSL::SSL::VERIFY_PEER) diff --git a/spec/unit/node/catalog.rb b/spec/unit/node/catalog.rb index ecbd20487..b1bf5abaa 100755 --- a/spec/unit/node/catalog.rb +++ b/spec/unit/node/catalog.rb @@ -460,6 +460,12 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do proc { @catalog.alias @one, "one" }.should_not raise_error end + it "should be able to look resources up by their aliases" do + @catalog.add_resource @one + @catalog.alias @one, "two" + @catalog.resource(:me, "two").should equal(@one) + end + it "should remove resource aliases when the target resource is removed" do @catalog.add_resource @one @catalog.alias(@one, "other") @@ -468,12 +474,21 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do @catalog.resource("me", "other").should be_nil end - it "should add an alias for the namevar when the title and name differ" do - @one.stubs(:name).returns "other" + it "should add an alias for the namevar when the title and name differ on isomorphic resource types" do resource = Puppet::Type.type(:file).create :path => "/something", :title => "other", :content => "blah" @catalog.add_resource(resource) @catalog.resource(:file, "other").should equal(resource) - @catalog.resource(:file, "/something").should equal(resource) + @catalog.resource(:file, "/something").ref.should == resource.ref + end + + it "should not add an alias for the namevar when the title and name differ on non-isomorphic resource types" do + resource = Puppet::Type.type(:exec).create :command => "/bin/true", :title => "other" + @catalog.add_resource(resource) + @catalog.resource(:exec, resource.title).should equal(resource) + # We can't use .should here, because the resources respond to that method. + if @catalog.resource(:exec, resource.name) + raise "Aliased non-isomorphic resource" + end end after do @@ -601,6 +616,7 @@ end describe Puppet::Node::Catalog, " when creating a relationship graph" do before do + Puppet::Type.type(:component) @catalog = Puppet::Node::Catalog.new("host") @compone = Puppet::Type::Component.create :name => "one" @comptwo = Puppet::Type::Component.create :name => "two", :require => ["class", "one"] diff --git a/spec/unit/other/pgraph.rb b/spec/unit/other/pgraph.rb index 7d66ae331..10ab934a6 100755 --- a/spec/unit/other/pgraph.rb +++ b/spec/unit/other/pgraph.rb @@ -5,6 +5,7 @@ require File.dirname(__FILE__) + '/../../spec_helper' +require 'puppet/pgraph' require 'puppet/util/graph' class Container diff --git a/spec/unit/other/transaction.rb b/spec/unit/other/transaction.rb index d88f03005..e277a24c0 100755 --- a/spec/unit/other/transaction.rb +++ b/spec/unit/other/transaction.rb @@ -2,6 +2,8 @@ require File.dirname(__FILE__) + '/../../spec_helper' +require 'puppet/transaction' + describe Puppet::Transaction, " when determining tags" do before do @config = Puppet::Node::Catalog.new diff --git a/spec/unit/parser/interpreter.rb b/spec/unit/parser/interpreter.rb index 7885f0542..eb5dd9aaf 100755 --- a/spec/unit/parser/interpreter.rb +++ b/spec/unit/parser/interpreter.rb @@ -127,6 +127,7 @@ describe Puppet::Parser::Interpreter, " when compiling catalog" do end it "should fail intelligently when no parser can be found" do + @node.stubs(:name).returns("whatever") @interp.expects(:parser).with(:myenv).returns(nil) proc { @interp.compile(@node) }.should raise_error(Puppet::ParseError) end diff --git a/spec/unit/ral/types/file.rb b/spec/unit/ral/types/file.rb index 62fe2f677..b213987bb 100755 --- a/spec/unit/ral/types/file.rb +++ b/spec/unit/ral/types/file.rb @@ -56,6 +56,43 @@ describe Puppet::Type::File do end end + describe "when managing links" do + require 'puppettest/support/assertions' + include PuppetTest + + before do + @basedir = tempfile() + Dir.mkdir(@basedir) + @file = File.join(@basedir, "file") + @link = File.join(@basedir, "link") + + File.open(@file, "w", 0644) { |f| f.puts "yayness"; f.flush } + File.symlink(@file, @link) + + @resource = Puppet.type(:file).create( + :path => @link, + :mode => "755" + ) + end + + after do + teardown + end + + it "should default to managing the link" do + assert_events([], @resource) + # I convert them to strings so they display correctly if there's an error. + ("%o" % (File.stat(@file).mode & 007777)).should == "%o" % 0644 + end + + it "should be able to follow links" do + @resource[:links] = :follow + assert_events([:file_changed], @resource) + + ("%o" % (File.stat(@file).mode & 007777)).should == "%o" % 0755 + end + end + after do Puppet::Type::File.clear end diff --git a/spec/unit/util/checksums.rb b/spec/unit/util/checksums.rb index 31cf24f5b..0e0d06c0d 100755 --- a/spec/unit/util/checksums.rb +++ b/spec/unit/util/checksums.rb @@ -14,7 +14,7 @@ describe Puppet::Util::Checksums do end content_sums = [:md5, :md5lite, :sha1, :sha1lite] - file_only = [:timestamp, :mtime] + file_only = [:ctime, :mtime] content_sums.each do |sumtype| it "should be able to calculate %s sums from strings" % sumtype do @@ -84,11 +84,11 @@ describe Puppet::Util::Checksums do end end - {:timestamp => :ctime, :mtime => :mtime}.each do |sum, method| + [:ctime, :mtime].each do |sum| describe("when using %s" % sum) do - it "should use the '#{method}' on the file to determine the timestamp" do + it "should use the '#{sum}' on the file to determine the ctime" do file = "/my/file" - stat = mock 'stat', method => "mysum" + stat = mock 'stat', sum => "mysum" File.expects(:stat).with(file).returns(stat) diff --git a/spec/unit/util/tagging.rb b/spec/unit/util/tagging.rb index 91cbb213d..d61ee8ccb 100755 --- a/spec/unit/util/tagging.rb +++ b/spec/unit/util/tagging.rb @@ -61,6 +61,10 @@ describe Puppet::Util::Tagging, "when adding tags" do lambda { @tagger.tag("good_tag") }.should_not raise_error(Puppet::ParseError) end + it "should allow tags containing '.' characters" do + lambda { @tagger.tag("good.tag") }.should_not raise_error(Puppet::ParseError) + end + it "should provide a method for testing tag validity" do @tagger.metaclass.publicize_methods(:valid_tag?) { @tagger.should be_respond_to(:valid_tag?) } end |