summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-08-24 13:32:33 -0500
committerLuke Kanies <luke@madstop.com>2008-08-26 22:40:40 -0700
commit5a195e0c06daa2bfa008cfd94c660e50b9d0ae56 (patch)
tree92f7ae0251603aaf7982af1e073c6666fbca6769 /spec
parent3101ea23e556081fe38502218034f02aafe0c5bf (diff)
Renaming FileServing::FileBase to FileServing::Base.
Also fixing a set of tests I broke last night. I'm looking at replacing autotest with rspactor, because my FSEvents hack to autotest means it's harder for me to rerun autotest. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/file_serving/content.rb14
-rwxr-xr-xspec/unit/file_serving/file_base.rb124
-rwxr-xr-xspec/unit/file_serving/metadata.rb4
-rwxr-xr-xspec/unit/indirector/file_server.rb30
4 files changed, 31 insertions, 141 deletions
diff --git a/spec/unit/file_serving/content.rb b/spec/unit/file_serving/content.rb
index e8de1d63e..b747ced78 100755
--- a/spec/unit/file_serving/content.rb
+++ b/spec/unit/file_serving/content.rb
@@ -16,6 +16,20 @@ describe Puppet::FileServing::Content do
it "should should include the IndirectionHooks module in its indirection" do
Puppet::FileServing::Content.indirection.metaclass.included_modules.should include(Puppet::FileServing::IndirectionHooks)
end
+
+ it "should have a method for collecting its attributes" do
+ Puppet::FileServing::Content.new("sub/path", :path => "/base").should respond_to(:collect)
+ end
+
+ it "should retrieve and store its contents when its attributes are collected" do
+ content = Puppet::FileServing::Content.new("sub/path", :path => "/base")
+
+ result = "foo"
+ File.stubs(:lstat).returns(stub("stat", :ftype => "file"))
+ File.expects(:read).with("/base/sub/path").returns result
+ content.collect
+ content.content.should equal(result)
+ end
end
describe Puppet::FileServing::Content, "when returning the contents" do
diff --git a/spec/unit/file_serving/file_base.rb b/spec/unit/file_serving/file_base.rb
deleted file mode 100755
index ded6ae4a8..000000000
--- a/spec/unit/file_serving/file_base.rb
+++ /dev/null
@@ -1,124 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../spec_helper'
-
-require 'puppet/file_serving/file_base'
-
-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
-
- it "should allow specification of whether links should be managed" do
- Puppet::FileServing::FileBase.new("puppet://host/module/dir/file", :links => :manage).links.should == :manage
- end
-
- it "should consider :ignore links equivalent to :manage links" do
- Puppet::FileServing::FileBase.new("puppet://host/module/dir/file", :links => :ignore).links.should == :manage
- end
-
- it "should fail if :links is set to anything other than :manage, :follow, or :ignore" do
- proc { Puppet::FileServing::FileBase.new("puppet://host/module/dir/file", :links => :else) }.should raise_error(ArgumentError)
- end
-
- it "should default to :manage for :links" do
- Puppet::FileServing::FileBase.new("puppet://host/module/dir/file").links.should == :manage
- end
-
- it "should allow specification of a path" do
- FileTest.stubs(:exists?).returns(true)
- Puppet::FileServing::FileBase.new("puppet://host/module/dir/file", :path => "/my/file").path.should == "/my/file"
- end
-
- it "should allow specification of a relative path" 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
-
- it "should have a means of determining if the file exists" do
- Puppet::FileServing::FileBase.new("blah").should respond_to(:exist?)
- end
-
- 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
-
- 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
-
- describe "when setting the base path" do
- before do
- @file = Puppet::FileServing::FileBase.new("puppet://host/module/dir/file")
- 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)
- end
- end
-
- 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
-
- describe "when determining the full file path" 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 return the path if the relative_path is set to ''" do
- @file.relative_path = ""
- @file.full_path.should == "/this/file"
- 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 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 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 9743370c1..e76ceb3e8 100755
--- a/spec/unit/file_serving/metadata.rb
+++ b/spec/unit/file_serving/metadata.rb
@@ -5,8 +5,8 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/file_serving/metadata'
describe Puppet::FileServing::Metadata do
- it "should should be a subclass of FileBase" do
- Puppet::FileServing::Metadata.superclass.should equal(Puppet::FileServing::FileBase)
+ it "should should be a subclass of Base" do
+ Puppet::FileServing::Metadata.superclass.should equal(Puppet::FileServing::Base)
end
it "should indirect file_metadata" do
diff --git a/spec/unit/indirector/file_server.rb b/spec/unit/indirector/file_server.rb
index ba951737a..544953932 100755
--- a/spec/unit/indirector/file_server.rb
+++ b/spec/unit/indirector/file_server.rb
@@ -24,7 +24,7 @@ describe Puppet::Indirector::FileServer do
@file_server = @file_server_class.new
- @uri = "puppetmounts://host/my/local/file"
+ @uri = "puppet://host/my/local/file"
@configuration = mock 'configuration'
Puppet::FileServing::Configuration.stubs(:create).returns(@configuration)
@@ -34,28 +34,28 @@ describe Puppet::Indirector::FileServer do
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)
+ @configuration.expects(:file_path).with("my/local/file", :node => nil)
@file_server.find(@request)
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)
+ @configuration.expects(:file_path).with("my/local/file", :node => nil)
@file_server.find(@request)
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")
+ @configuration.expects(:file_path).with("my/local/file", :node => "testing")
@request.node = "testing"
@file_server.find(@request)
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)
+ @configuration.expects(:file_path).with("my/local/file", :node => nil).returns(nil)
@file_server.find(@request).should be_nil
end
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")
+ @configuration.expects(:file_path).with("my/local/file", :node => nil).returns("/some/file")
@model.expects(:new).returns(:myinstance)
@file_server.find(@request).should == :myinstance
end
@@ -63,12 +63,12 @@ describe Puppet::Indirector::FileServer do
describe Puppet::Indirector::FileServer, " when returning instances" do
before :each do
- @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/some/file")
+ @configuration.expects(:file_path).with("my/local/file", :node => nil).returns("/some/file")
@instance = mock 'instance'
end
it "should create the instance with the key used to find the instance" do
- @model.expects(:new).with { |key, *options| key == @uri }
+ @model.expects(:new).with { |key, *options| key == "my/local/file" }
@file_server.find(@request)
end
@@ -149,35 +149,35 @@ describe Puppet::Indirector::FileServer do
describe Puppet::Indirector::FileServer, " when searching for 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)
+ @configuration.expects(:file_path).with("my/local/file", :node => nil)
@file_server.search(@request)
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)
+ @configuration.expects(:file_path).with("my/local/file", :node => nil)
@file_server.search(@request)
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")
+ @configuration.expects(:file_path).with("my/local/file", :node => "testing")
@request.node = "testing"
@file_server.search(@request)
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)
+ @configuration.expects(:file_path).with("my/local/file", :node => nil).returns(nil)
@file_server.search(@request).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")
+ @configuration.expects(:file_path).with("my/local/file", :node => nil).returns("my/file")
@file_server.expects(:path2instances)
@file_server.search(@request)
end
it "should pass the request on to :path2instances" do
- @configuration.expects(:file_path).with("/my/local/file", :node => nil).returns("/my/file")
- @file_server.expects(:path2instances).with(@request, "/my/file")
+ @configuration.expects(:file_path).with("my/local/file", :node => nil).returns("my/file")
+ @file_server.expects(:path2instances).with(@request, "my/file")
@file_server.search(@request)
end
end