diff options
Diffstat (limited to 'spec/integration')
| -rwxr-xr-x | spec/integration/file_serving/configuration.rb | 4 | ||||
| -rwxr-xr-x | spec/integration/file_serving/content.rb | 2 | ||||
| -rwxr-xr-x | spec/integration/file_serving/fileset.rb | 14 | ||||
| -rwxr-xr-x | spec/integration/file_serving/metadata.rb | 2 | ||||
| -rwxr-xr-x | spec/integration/file_serving/terminus_helper.rb | 22 | ||||
| -rwxr-xr-x | spec/integration/indirector/direct_file_server.rb | 31 | ||||
| -rwxr-xr-x | spec/integration/indirector/module_files.rb | 28 | ||||
| -rwxr-xr-x | spec/integration/type/file.rb | 128 |
8 files changed, 196 insertions, 35 deletions
diff --git a/spec/integration/file_serving/configuration.rb b/spec/integration/file_serving/configuration.rb index cb5a23d3b..dfdda402d 100755 --- a/spec/integration/file_serving/configuration.rb +++ b/spec/integration/file_serving/configuration.rb @@ -29,12 +29,12 @@ describe Puppet::FileServing::Configuration, " when finding files with Puppet::F it "should return nil if the file does not exist" do FileTest.expects(:exists?).with("/my/path/my/file").returns(false) - @config.file_path("/mymount/my/file").should be_nil + @config.file_path("mymount/my/file").should be_nil end it "should return the full file path if the file exists" do FileTest.expects(:exists?).with("/my/path/my/file").returns(true) - @config.file_path("/mymount/my/file").should == "/my/path/my/file" + @config.file_path("mymount/my/file").should == "/my/path/my/file" end after do diff --git a/spec/integration/file_serving/content.rb b/spec/integration/file_serving/content.rb index aee2a9f2d..af0181393 100755 --- a/spec/integration/file_serving/content.rb +++ b/spec/integration/file_serving/content.rb @@ -15,4 +15,6 @@ describe Puppet::FileServing::Content, " when finding files" do @test_class = Puppet::FileServing::Content @indirection = Puppet::FileServing::Content.indirection end + + after { Puppet::Util::Cacher.invalidate } end diff --git a/spec/integration/file_serving/fileset.rb b/spec/integration/file_serving/fileset.rb new file mode 100755 index 000000000..80bf0f376 --- /dev/null +++ b/spec/integration/file_serving/fileset.rb @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/file_serving/fileset' + +describe Puppet::FileServing::Fileset do + it "should be able to recurse on a single file" do + @path = Tempfile.new("fileset_integration") + + fileset = Puppet::FileServing::Fileset.new(@path.path) + lambda { fileset.files }.should_not raise_error + end +end diff --git a/spec/integration/file_serving/metadata.rb b/spec/integration/file_serving/metadata.rb index 067cb566a..af3e16324 100755 --- a/spec/integration/file_serving/metadata.rb +++ b/spec/integration/file_serving/metadata.rb @@ -15,4 +15,6 @@ describe Puppet::FileServing::Metadata, " when finding files" do @test_class = Puppet::FileServing::Metadata @indirection = Puppet::FileServing::Metadata.indirection end + + after { Puppet::Util::Cacher.invalidate } end diff --git a/spec/integration/file_serving/terminus_helper.rb b/spec/integration/file_serving/terminus_helper.rb new file mode 100755 index 000000000..7d2587af1 --- /dev/null +++ b/spec/integration/file_serving/terminus_helper.rb @@ -0,0 +1,22 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/file_serving/terminus_helper' + +class TerminusHelperIntegrationTester + include Puppet::FileServing::TerminusHelper + def model + Puppet::FileServing::Metadata + end +end + +describe Puppet::FileServing::TerminusHelper do + it "should be able to recurse on a single file" do + @path = Tempfile.new("fileset_integration") + request = Puppet::Indirector::Request.new(:metadata, :find, @path.path, :recurse => true) + + tester = TerminusHelperIntegrationTester.new + lambda { tester.path2instances(request, @path.path) }.should_not raise_error + end +end diff --git a/spec/integration/indirector/direct_file_server.rb b/spec/integration/indirector/direct_file_server.rb index 40b753a6c..417d661e8 100755 --- a/spec/integration/indirector/direct_file_server.rb +++ b/spec/integration/indirector/direct_file_server.rb @@ -37,21 +37,19 @@ describe Puppet::Indirector::DirectFileServer, " when interacting with FileServi before do @terminus = Puppet::Indirector::FileContent::File.new - @filepath = "/my/file" - FileTest.stubs(:exists?).with(@filepath).returns(true) + @path = Tempfile.new("direct_file_server_testing") + @path.close! + @path = @path.path - stat = stub 'stat', :directory? => true - File.stubs(:lstat).with(@filepath).returns(stat) + Dir.mkdir(@path) + File.open(File.join(@path, "one"), "w") { |f| f.print "one content" } + File.open(File.join(@path, "two"), "w") { |f| f.print "two content" } - @subfiles = %w{one two} - @subfiles.each do |f| - path = File.join(@filepath, f) - FileTest.stubs(:exists?).with(@path).returns(true) - end - - Dir.expects(:entries).with(@filepath).returns @subfiles + @request = @terminus.indirection.request(:search, "file:///%s" % @path, :recurse => true) + end - @request = @terminus.indirection.request(:search, "file:///my/file", :recurse => true) + after do + system("rm -rf %s" % @path) end it "should return an instance for every file in the fileset" do @@ -62,18 +60,13 @@ describe Puppet::Indirector::DirectFileServer, " when interacting with FileServi end it "should return instances capable of returning their content" do - @subfiles.each do |name| - File.stubs(:lstat).with(File.join(@filepath, name)).returns stub("#{name} stat", :ftype => "file", :directory? => false) - File.expects(:read).with(File.join(@filepath, name)).returns("#{name} content") - end - @terminus.search(@request).each do |instance| - case instance.key + case instance.full_path when /one/: instance.content.should == "one content" when /two/: instance.content.should == "two content" when /\.$/: else - raise "No valid key for %s" % instance.key.inspect + raise "No valid key for %s" % instance.path.inspect end end end diff --git a/spec/integration/indirector/module_files.rb b/spec/integration/indirector/module_files.rb index ae14aa5a7..a54588ec5 100755 --- a/spec/integration/indirector/module_files.rb +++ b/spec/integration/indirector/module_files.rb @@ -20,7 +20,7 @@ describe Puppet::Indirector::ModuleFiles, " when interacting with Puppet::Module FileTest.expects(:exists?).with(filepath).returns(true) - @request = Puppet::Indirector::Request.new(:content, :find, "puppetmounts://host/modules/mymod/myfile") + @request = Puppet::Indirector::Request.new(:content, :find, "puppet://host/modules/mymod/myfile") @terminus.find(@request).should be_instance_of(Puppet::FileServing::Content) end @@ -30,24 +30,24 @@ describe Puppet::Indirector::ModuleFiles, " when interacting with FileServing::F it "should return an instance for every file in the fileset" do Puppet::Node::Environment.stubs(:new).returns(stub('env', :name => "myenv")) @terminus = Puppet::Indirector::FileContent::Modules.new - @module = Puppet::Module.new("mymod", "/some/path/mymod") - Puppet::Module.expects(:find).with("mymod", "myenv").returns(@module) - filepath = "/some/path/mymod/files/myfile" - FileTest.stubs(:exists?).with(filepath).returns(true) + @path = Tempfile.new("module_file_testing") + @path.close! + @path = @path.path - stat = stub 'stat', :directory? => true - File.stubs(:lstat).with(filepath).returns(stat) + Dir.mkdir(@path) + Dir.mkdir(File.join(@path, "files")) - subfiles = %w{one two} - subfiles.each do |f| - path = File.join(filepath, f) - FileTest.stubs(:exists?).with(path).returns(true) - end + basedir = File.join(@path, "files", "myfile") + Dir.mkdir(basedir) - Dir.expects(:entries).with(filepath).returns(%w{one two}) + File.open(File.join(basedir, "one"), "w") { |f| f.print "one content" } + File.open(File.join(basedir, "two"), "w") { |f| f.print "two content" } + + @module = Puppet::Module.new("mymod", @path) + Puppet::Module.expects(:find).with("mymod", "myenv").returns(@module) - @request = Puppet::Indirector::Request.new(:content, :search, "puppetmounts://host/modules/mymod/myfile", :recurse => true) + @request = Puppet::Indirector::Request.new(:content, :search, "puppet://host/modules/mymod/myfile", :recurse => true) result = @terminus.search(@request) result.should be_instance_of(Array) diff --git a/spec/integration/type/file.rb b/spec/integration/type/file.rb new file mode 100755 index 000000000..b59fa3294 --- /dev/null +++ b/spec/integration/type/file.rb @@ -0,0 +1,128 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +describe Puppet::Type.type(:file), "when recursing" do + def mkdir + end + + def build_path(dir) + Dir.mkdir(dir) + File.chmod(0750, dir) + + @dirs = [dir] + @files = [] + + %w{one two}.each do |subdir| + fdir = File.join(dir, subdir) + Dir.mkdir(fdir) + File.chmod(0750, fdir) + @dirs << fdir + + %w{three}.each do |file| + ffile = File.join(fdir, file) + @files << ffile + File.open(ffile, "w") { |f| f.puts "test %s" % file } + File.chmod(0640, ffile) + end + end + end + + it "should be able to recurse over a nonexistent file" do + @path = Tempfile.new("file_integration_tests") + @path.close!() + @path = @path.path + + @file = Puppet::Type::File.create(:name => @path, :mode => 0644, :recurse => true) + + @catalog = Puppet::Node::Catalog.new + @catalog.add_resource @file + + lambda { @file.eval_generate }.should_not raise_error + end + + it "should be able to recursively set properties on existing files" do + @path = Tempfile.new("file_integration_tests") + @path.close!() + @path = @path.path + + build_path(@path) + + @file = Puppet::Type::File.create(:name => @path, :mode => 0644, :recurse => true) + + @catalog = Puppet::Node::Catalog.new + @catalog.add_resource @file + + @catalog.apply + + @dirs.each do |path| + (File.stat(path).mode & 007777).should == 0755 + end + + @files.each do |path| + (File.stat(path).mode & 007777).should == 0644 + end + end + + it "should be able to recursively make links to other files" do + source = Tempfile.new("file_link_integration_source") + source.close!() + source = source.path + + build_path(source) + + dest = Tempfile.new("file_link_integration_dest") + dest.close!() + dest = dest.path + + @file = Puppet::Type::File.create(:name => dest, :target => source, :recurse => true, :ensure => :link) + + @catalog = Puppet::Node::Catalog.new + @catalog.add_resource @file + + @catalog.apply + + @dirs.each do |path| + link_path = path.sub(source, dest) + + File.lstat(link_path).should be_directory + end + + @files.each do |path| + link_path = path.sub(source, dest) + + File.lstat(link_path).ftype.should == "link" + end + end + + it "should be able to recursively copy files" do + source = Tempfile.new("file_source_integration_source") + source.close!() + source = source.path + + build_path(source) + + dest = Tempfile.new("file_source_integration_dest") + dest.close!() + dest = dest.path + + @file = Puppet::Type::File.create(:name => dest, :source => source, :recurse => true) + + @catalog = Puppet::Node::Catalog.new + @catalog.add_resource @file + + @catalog.apply + + @dirs.each do |path| + newpath = path.sub(source, dest) + + File.lstat(newpath).should be_directory + end + + @files.each do |path| + newpath = path.sub(source, dest) + + File.lstat(newpath).ftype.should == "file" + end + end +end |
