summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-10-22 19:28:22 -0500
committerLuke Kanies <luke@madstop.com>2007-10-22 19:28:22 -0500
commit688fcdf11a685dfda297beff50de8d4c751494d9 (patch)
treef2d737a2382de16a43e3d37f09dab2c76ad57d91 /spec
parent393a3e8743f503543ad34a874e9296d684b0d49b (diff)
downloadpuppet-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')
-rwxr-xr-xspec/unit/file_serving/fileset.rb22
-rwxr-xr-xspec/unit/file_serving/terminus_helper.rb38
-rwxr-xr-xspec/unit/indirector/file_content/local.rb24
-rwxr-xr-xspec/unit/indirector/file_metadata/local.rb38
-rwxr-xr-xspec/unit/indirector/file_server.rb54
-rwxr-xr-xspec/unit/indirector/module_files.rb71
6 files changed, 214 insertions, 33 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
diff --git a/spec/unit/indirector/file_content/local.rb b/spec/unit/indirector/file_content/local.rb
index 361628767..ca7202ae1 100755
--- a/spec/unit/indirector/file_content/local.rb
+++ b/spec/unit/indirector/file_content/local.rb
@@ -35,3 +35,27 @@ describe Puppet::Indirector::FileContent::Local, "when finding a single file" do
@content.find(@uri).should be_nil
end
end
+
+describe Puppet::Indirector::FileContent::Local, "when searching for multiple files" do
+ before do
+ @content = Puppet::Indirector::FileContent::Local.new
+ @uri = "file:///my/local"
+ end
+
+ it "should return nil if the file does not exist" do
+ FileTest.expects(:exists?).with("/my/local").returns false
+ @content.find(@uri).should be_nil
+ end
+
+ it "should use :path2instances from the terminus_helper to return instances if the file exists" do
+ FileTest.expects(:exists?).with("/my/local").returns true
+ @content.expects(:path2instances).with("/my/local", {})
+ @content.search(@uri)
+ end
+
+ it "should pass any options on to :path2instances" do
+ FileTest.expects(:exists?).with("/my/local").returns true
+ @content.expects(:path2instances).with("/my/local", :testing => :one, :other => :two)
+ @content.search(@uri, :testing => :one, :other => :two)
+ end
+end
diff --git a/spec/unit/indirector/file_metadata/local.rb b/spec/unit/indirector/file_metadata/local.rb
index 604cdf6af..f613d35c7 100755
--- a/spec/unit/indirector/file_metadata/local.rb
+++ b/spec/unit/indirector/file_metadata/local.rb
@@ -15,7 +15,7 @@ end
describe Puppet::Indirector::FileMetadata::Local, "when finding a single file" do
before do
- @content = Puppet::Indirector::FileMetadata::Local.new
+ @metadata = Puppet::Indirector::FileMetadata::Local.new
@uri = "file:///my/local"
@data = mock 'metadata'
@@ -25,7 +25,7 @@ describe Puppet::Indirector::FileMetadata::Local, "when finding a single file" d
FileTest.expects(:exists?).with("/my/local").returns true
Puppet::FileServing::Metadata.expects(:new).with("/my/local").returns(@data)
- @content.find(@uri).should == @data
+ @metadata.find(@uri).should == @data
end
it "should collect its attributes when a file is found" do
@@ -33,11 +33,41 @@ describe Puppet::Indirector::FileMetadata::Local, "when finding a single file" d
FileTest.expects(:exists?).with("/my/local").returns true
Puppet::FileServing::Metadata.expects(:new).with("/my/local").returns(@data)
- @content.find(@uri).should == @data
+ @metadata.find(@uri).should == @data
end
it "should return nil if the file does not exist" do
FileTest.expects(:exists?).with("/my/local").returns false
- @content.find(@uri).should be_nil
+ @metadata.find(@uri).should be_nil
+ end
+end
+
+describe Puppet::Indirector::FileMetadata::Local, "when searching for multiple files" do
+ before do
+ @metadata = Puppet::Indirector::FileMetadata::Local.new
+ @uri = "file:///my/local"
+ end
+
+ it "should return nil if the file does not exist" do
+ FileTest.expects(:exists?).with("/my/local").returns false
+ @metadata.find(@uri).should be_nil
+ end
+
+ it "should use :path2instances from the terminus_helper to return instances if the file exists" do
+ FileTest.expects(:exists?).with("/my/local").returns true
+ @metadata.expects(:path2instances).with("/my/local", {}).returns([])
+ @metadata.search(@uri)
+ end
+
+ it "should pass any options on to :path2instances" do
+ FileTest.expects(:exists?).with("/my/local").returns true
+ @metadata.expects(:path2instances).with("/my/local", :testing => :one, :other => :two).returns([])
+ @metadata.search(@uri, :testing => :one, :other => :two)
+ end
+
+ it "should collect the attributes of the instances returned" do
+ FileTest.expects(:exists?).with("/my/local").returns true
+ @metadata.expects(:path2instances).with("/my/local", {}).returns( [mock("one", :get_attributes => nil), mock("two", :get_attributes => nil)] )
+ @metadata.search(@uri)
end
end
diff --git a/spec/unit/indirector/file_server.rb b/spec/unit/indirector/file_server.rb
index 7bd55c650..4bc56ce7d 100755
--- a/spec/unit/indirector/file_server.rb
+++ b/spec/unit/indirector/file_server.rb
@@ -26,9 +26,6 @@ module FileServerTerminusTesting
@uri = "puppetmounts://host/my/local/file"
@configuration = mock 'configuration'
Puppet::FileServing::Configuration.stubs(:create).returns(@configuration)
-
- @module_server = mock 'module_server'
- @indirection.stubs(:terminus).with(:modules).returns(@module_server)
end
end
@@ -37,39 +34,26 @@ describe Puppet::Indirector::FileServer, " when finding files" do
it "should use the path portion of the URI as the file name" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil)
- @module_server.stubs(:find).returns(nil)
@file_server.find(@uri)
end
it "should use the FileServing configuration to convert the file name to a fully qualified path" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil)
- @module_server.stubs(:find).returns(nil)
@file_server.find(@uri)
end
it "should pass the node name to the FileServing configuration if one is provided" do
@configuration.expects(:file_path).with("/my/local/file", :node => "testing")
- @module_server.stubs(:find)
@file_server.find(@uri, :node => "testing")
end
it "should return nil if no fully qualified path is found" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil).returns(nil)
- @module_server.stubs(:find).returns(nil)
@file_server.find(@uri).should be_nil
end
- it "should return nil if the configuration returns a file path that does not exist" do
+ it "should return an instance of the model created with the full path if a file is found" do
@configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/some/file")
- FileTest.expects(:exists?).with("/some/file").returns(false)
- @module_server.stubs(:find).returns(nil)
- @file_server.find(@uri).should be_nil
- end
-
- it "should return an instance of the model created with the full path if a file is found and it exists" do
- @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/some/file")
- FileTest.expects(:exists?).with("/some/file").returns(true)
- @module_server.stubs(:find).returns(nil)
@model.expects(:new).with("/some/file").returns(:myinstance)
@file_server.find(@uri).should == :myinstance
end
@@ -127,3 +111,39 @@ describe Puppet::Indirector::FileServer, " when checking authorization" do
@file_server.authorized?(:find, "puppetmounts://host/my/file").should be_true
end
end
+
+describe Puppet::Indirector::FileServer, " when searching for files" do
+ include FileServerTerminusTesting
+
+ it "should use the path portion of the URI as the file name" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil)
+ @file_server.search(@uri)
+ end
+
+ it "should use the FileServing configuration to convert the file name to a fully qualified path" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil)
+ @file_server.search(@uri)
+ end
+
+ it "should pass the node name to the FileServing configuration if one is provided" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => "testing")
+ @file_server.search(@uri, :node => "testing")
+ end
+
+ it "should return nil if no fully qualified path is found" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns(nil)
+ @file_server.search(@uri).should be_nil
+ end
+
+ it "should use :path2instances from the terminus_helper to return instances if a module is found and the file exists" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/my/file")
+ @file_server.expects(:path2instances).with("/my/file", {})
+ @file_server.search(@uri)
+ end
+
+ it "should pass any options on to :path2instances" do
+ @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/my/file")
+ @file_server.expects(:path2instances).with("/my/file", :testing => :one, :other => :two)
+ @file_server.search(@uri, :testing => :one, :other => :two)
+ end
+end
diff --git a/spec/unit/indirector/module_files.rb b/spec/unit/indirector/module_files.rb
index a6c27b84b..e65f15697 100755
--- a/spec/unit/indirector/module_files.rb
+++ b/spec/unit/indirector/module_files.rb
@@ -82,7 +82,7 @@ describe Puppet::Indirector::ModuleFiles, " when finding files" do
@module_files.find(@uri)
end
- it "should not us an environment when looking up the module if the node name is not provided and the environment is set to ''" do
+ it "should not use an environment when looking up the module if the node name is not provided and the environment is set to ''" do
Puppet.settings.stubs(:value).with(:environment).returns("")
Puppet::Module.expects(:find).with('my', nil)
@module_files.find(@uri)
@@ -150,3 +150,72 @@ describe Puppet::Indirector::ModuleFiles, " when authorizing" do
@module_files.authorized?(:find, "puppetmounts://host/my/file").should be_true
end
end
+
+describe Puppet::Indirector::ModuleFiles, " when searching for files" do
+ include ModuleFilesTerminusTesting
+
+ it "should strip off the leading '/modules' mount name" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ @module_files.search(@uri)
+ end
+
+ it "should not strip off leading terms that start with '/modules' but are longer words" do
+ Puppet::Module.expects(:find).with('modulestart', nil).returns nil
+ @module_files.search("puppetmounts://host/modulestart/my/local/file")
+ end
+
+ it "should search for a module whose name is the first term in the remaining file path" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ @module_files.search(@uri)
+ end
+
+ it "should search for a file relative to the module's files directory" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ FileTest.expects(:exists?).with("/module/path/files/local/file")
+ @module_files.search(@uri)
+ end
+
+ it "should return nil if the module does not exist" do
+ Puppet::Module.expects(:find).with('my', nil).returns nil
+ @module_files.search(@uri).should be_nil
+ end
+
+ it "should return nil if the module exists but the file does not" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ FileTest.expects(:exists?).with("/module/path/files/local/file").returns(false)
+ @module_files.search(@uri).should be_nil
+ end
+
+ it "should use the node's environment to look up the module if the node name is provided" do
+ node = stub "node", :environment => "testing"
+ Puppet::Node.expects(:find).with("mynode").returns(node)
+ Puppet::Module.expects(:find).with('my', "testing")
+ @module_files.search(@uri, :node => "mynode")
+ end
+
+ it "should use the local environment setting to look up the module if the node name is not provided and the environment is not set to ''" do
+ Puppet.settings.stubs(:value).with(:environment).returns("testing")
+ Puppet::Module.expects(:find).with('my', "testing")
+ @module_files.search(@uri)
+ end
+
+ it "should not use an environment when looking up the module if the node name is not provided and the environment is set to ''" do
+ Puppet.settings.stubs(:value).with(:environment).returns("")
+ Puppet::Module.expects(:find).with('my', nil)
+ @module_files.search(@uri)
+ end
+
+ it "should use :path2instances from the terminus_helper to return instances if a module is found and the file exists" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true)
+ @module_files.expects(:path2instances).with("/module/path/files/local/file", {})
+ @module_files.search(@uri)
+ end
+
+ it "should pass any options on to :path2instances" do
+ Puppet::Module.expects(:find).with('my', nil).returns @module
+ FileTest.expects(:exists?).with("/module/path/files/local/file").returns(true)
+ @module_files.expects(:path2instances).with("/module/path/files/local/file", :testing => :one, :other => :two)
+ @module_files.search(@uri, :testing => :one, :other => :two)
+ end
+end