diff options
| author | Luke Kanies <luke@madstop.com> | 2008-08-28 23:28:22 -0700 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-08-28 23:28:22 -0700 |
| commit | 93fc1139550bd97a11529b812e77ac0fc00c6079 (patch) | |
| tree | 66ef90dc4dcfa02c012307f80d84a2b194877d9d /spec | |
| parent | bd1163a339ff66dbb9a50a1cb13f6320cb056cc3 (diff) | |
Files now use the Indirector to recurse locally.
I don't yet have integration tests for remote recursion
or link recursion, but we're nearly there.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/integration/type/file.rb | 53 | ||||
| -rwxr-xr-x | spec/unit/type/file.rb | 29 |
2 files changed, 78 insertions, 4 deletions
diff --git a/spec/integration/type/file.rb b/spec/integration/type/file.rb new file mode 100755 index 000000000..39d0b62dc --- /dev/null +++ b/spec/integration/type/file.rb @@ -0,0 +1,53 @@ +#!/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 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 +end diff --git a/spec/unit/type/file.rb b/spec/unit/type/file.rb index 27a077bed..9578a2d17 100755 --- a/spec/unit/type/file.rb +++ b/spec/unit/type/file.rb @@ -143,6 +143,14 @@ describe Puppet::Type.type(:file) do @file.recurse_local end + it "should not create a new child resource for the '.' directory" do + @metadata.stubs(:relative_path).returns "." + + @file.expects(:perform_recursion).returns [@metadata] + @file.expects(:newchild).never + @file.recurse_local + end + it "should return a hash of the created resources with the relative paths as the hash keys" do @file.expects(:perform_recursion).returns [@metadata] @file.expects(:newchild).with("my/file").returns "fiebar" @@ -366,6 +374,19 @@ describe Puppet::Type.type(:file) do @file.eval_generate.should == [foo] end + it "should add each resource to the catalog" do + foo = stub 'foo', :[] => "/foo" + bar = stub 'bar', :[] => "/bar" + bar2 = stub 'bar2', :[] => "/bar" + + @catalog.expects(:add_resource).with(foo) + @catalog.expects(:add_resource).with(bar) + + @file.expects(:recurse).returns [foo, bar] + + @file.eval_generate + end + it "should add a relationshp edge for each returned resource" do foo = stub 'foo', :[] => "/foo" @@ -422,25 +443,25 @@ describe Puppet::Type.type(:file) do describe "and making a new child resource" do it "should create an implicit resource using the provided relative path joined with the file's path" do path = File.join(@file[:path], "my/path") - @catalog.expects(:create_implicit_resource).with { |klass, options| options[:path] == path } + Puppet::Type.type(:file).expects(:create).with { |options| options[:implicit] == true and options[:path] == path } @file.newchild("my/path") end it "should copy most of the parent resource's 'should' values to the new resource" do @file.expects(:to_hash).returns :foo => "bar", :fee => "fum" - @catalog.expects(:create_implicit_resource).with { |klass, options| options[:foo] == "bar" and options[:fee] == "fum" } + Puppet::Type.type(:file).expects(:create).with { |options| options[:foo] == "bar" and options[:fee] == "fum" } @file.newchild("my/path") end it "should not copy the parent resource's parent" do @file.expects(:to_hash).returns :parent => "foo" - @catalog.expects(:create_implicit_resource).with { |klass, options| ! options.include?(:parent) } + Puppet::Type.type(:file).expects(:create).with { |options| ! options.include?(:parent) } @file.newchild("my/path") end it "should not copy the parent resource's recurse value" do @file.expects(:to_hash).returns :recurse => true - @catalog.expects(:create_implicit_resource).with { |klass, options| ! options.include?(:recurse) } + Puppet::Type.type(:file).expects(:create).with { |options| ! options.include?(:recurse) } @file.newchild("my/path") end end |
