diff options
| author | Luke Kanies <luke@madstop.com> | 2007-10-22 19:28:22 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-10-22 19:28:22 -0500 |
| commit | 688fcdf11a685dfda297beff50de8d4c751494d9 (patch) | |
| tree | f2d737a2382de16a43e3d37f09dab2c76ad57d91 /spec/unit/file_serving | |
| parent | 393a3e8743f503543ad34a874e9296d684b0d49b (diff) | |
| download | puppet-688fcdf11a685dfda297beff50de8d4c751494d9.tar.gz puppet-688fcdf11a685dfda297beff50de8d4c751494d9.tar.xz puppet-688fcdf11a685dfda297beff50de8d4c751494d9.zip | |
Adding searchability to the fileserving termini, using the
new Fileset class.
The tests aren't the cleanest, in that there is still
a good bit of duplication in them, but it's what we got.
Diffstat (limited to 'spec/unit/file_serving')
| -rwxr-xr-x | spec/unit/file_serving/fileset.rb | 22 | ||||
| -rwxr-xr-x | spec/unit/file_serving/terminus_helper.rb | 38 |
2 files changed, 49 insertions, 11 deletions
diff --git a/spec/unit/file_serving/fileset.rb b/spec/unit/file_serving/fileset.rb index 518d7298d..2cd3e83dd 100755 --- a/spec/unit/file_serving/fileset.rb +++ b/spec/unit/file_serving/fileset.rb @@ -83,7 +83,7 @@ describe Puppet::FileServing::Fileset, " when determining whether to recurse" do @fileset.recurse?(1).should be_true end - it "should not recurse if :recurse is set to an integer and the current depth is great than that integer" do + it "should not recurse if :recurse is set to an integer and the current depth is greater than that integer" do @fileset.recurse = 1 @fileset.recurse?(2).should be_false end @@ -126,13 +126,13 @@ describe Puppet::FileServing::Fileset, " when recursing" do it "should recurse through the whole file tree if :recurse is set to 'true'" do mock_dir_structure(@path) @fileset.stubs(:recurse?).returns(true) - @fileset.find.sort.should == @files.sort + @fileset.files.sort.should == @files.sort end it "should not recurse if :recurse is set to 'false'" do mock_dir_structure(@path) @fileset.stubs(:recurse?).returns(false) - @fileset.find.should == %w{.} + @fileset.files.should == %w{.} end # It seems like I should stub :recurse? here, or that I shouldn't stub the @@ -140,41 +140,41 @@ describe Puppet::FileServing::Fileset, " when recursing" do it "should recurse to the level set if :recurse is set to an integer" do mock_dir_structure(@path) @fileset.recurse = 1 - @fileset.find.should == %w{. one two .svn CVS} + @fileset.files.should == %w{. one two .svn CVS} end it "should ignore the '.' and '..' directories in subdirectories" do mock_dir_structure(@path) @fileset.recurse = true - @fileset.find.sort.should == @files.sort + @fileset.files.sort.should == @files.sort end it "should ignore files that match a single pattern in the ignore list" do mock_dir_structure(@path) @fileset.recurse = true @fileset.ignore = ".svn" - @fileset.find.find { |file| file.include?(".svn") }.should be_nil + @fileset.files.find { |file| file.include?(".svn") }.should be_nil end it "should ignore files that match any of multiple patterns in the ignore list" do mock_dir_structure(@path) @fileset.recurse = true @fileset.ignore = %w{.svn CVS} - @fileset.find.find { |file| file.include?(".svn") or file.include?("CVS") }.should be_nil + @fileset.files.find { |file| file.include?(".svn") or file.include?("CVS") }.should be_nil end it "should use File.stat if :links is set to :follow" do mock_dir_structure(@path, :stat) @fileset.recurse = true @fileset.links = :follow - @fileset.find.sort.should == @files.sort + @fileset.files.sort.should == @files.sort end it "should use File.lstat if :links is set to :manage" do mock_dir_structure(@path, :lstat) @fileset.recurse = true @fileset.links = :manage - @fileset.find.sort.should == @files.sort + @fileset.files.sort.should == @files.sort end end @@ -194,11 +194,11 @@ describe Puppet::FileServing::Fileset, " when following links that point to miss end it "should not fail" do - proc { @fileset.find }.should_not raise_error + proc { @fileset.files }.should_not raise_error end it "should still manage the link" do - @fileset.find.sort.should == %w{. mylink}.sort + @fileset.files.sort.should == %w{. mylink}.sort end end diff --git a/spec/unit/file_serving/terminus_helper.rb b/spec/unit/file_serving/terminus_helper.rb new file mode 100755 index 000000000..3a5274b5a --- /dev/null +++ b/spec/unit/file_serving/terminus_helper.rb @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2007-10-22. +# Copyright (c) 2007. All rights reserved. + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/file_serving/terminus_helper' + +describe Puppet::FileServing::TerminusHelper do + before do + @helper = Object.new + @helper.extend(Puppet::FileServing::TerminusHelper) + + @model = mock 'model' + @helper.stubs(:model).returns(@model) + end + + it "should use a fileset to find paths" do + fileset = mock 'fileset', :files => [] + Puppet::FileServing::Fileset.expects(:new).with("/my/file", {}).returns(fileset) + @helper.path2instances("/my/file") + end + + it "should pass :recurse, :ignore, and :links settings on to the fileset if present" do + fileset = mock 'fileset', :files => [] + Puppet::FileServing::Fileset.expects(:new).with("/my/file", :links => :a, :ignore => :b, :recurse => :c).returns(fileset) + @helper.path2instances("/my/file", :links => :a, :ignore => :b, :recurse => :c) + end + + it "should return an instance of the model for each path returned by the fileset" do + fileset = mock 'fileset', :files => %w{one two} + Puppet::FileServing::Fileset.expects(:new).with("/my/file", {}).returns(fileset) + @model.expects(:new).with("one").returns(:one) + @model.expects(:new).with("two").returns(:two) + @helper.path2instances("/my/file").should == [:one, :two] + end +end |
