3
require File.dirname(__FILE__) + '/../../spec_helper'
5
require 'puppet/file_serving/file_base'
7
describe Puppet::FileServing::FileBase do
8
it "should accept a key in the form of a URI" do
9
Puppet::FileServing::FileBase.new("puppet://host/module/dir/file").key.should == "puppet://host/module/dir/file"
12
it "should allow specification of whether links should be managed" do
13
Puppet::FileServing::FileBase.new("puppet://host/module/dir/file", :links => :manage).links.should == :manage
16
it "should consider :ignore links equivalent to :manage links" do
17
Puppet::FileServing::FileBase.new("puppet://host/module/dir/file", :links => :ignore).links.should == :manage
20
it "should fail if :links is set to anything other than :manage, :follow, or :ignore" do
21
proc { Puppet::FileServing::FileBase.new("puppet://host/module/dir/file", :links => :else) }.should raise_error(ArgumentError)
24
it "should default to :manage for :links" do
25
Puppet::FileServing::FileBase.new("puppet://host/module/dir/file").links.should == :manage
28
it "should allow specification of a path" do
29
FileTest.stubs(:exists?).returns(true)
30
Puppet::FileServing::FileBase.new("puppet://host/module/dir/file", :path => "/my/file").path.should == "/my/file"
33
it "should allow specification of a relative path" do
34
FileTest.stubs(:exists?).returns(true)
35
Puppet::FileServing::FileBase.new("puppet://host/module/dir/file", :relative_path => "my/file").relative_path.should == "my/file"
38
it "should have a means of determining if the file exists" do
39
Puppet::FileServing::FileBase.new("blah").should respond_to(:exist?)
42
it "should correctly indicate if the file is present" do
43
File.expects(:lstat).with("/my/file").returns(mock("stat"))
44
Puppet::FileServing::FileBase.new("blah", :path => "/my/file").exist?.should be_true
47
it "should correctly indicate if the file is asbsent" do
48
File.expects(:lstat).with("/my/file").raises RuntimeError
49
Puppet::FileServing::FileBase.new("blah", :path => "/my/file").exist?.should be_false
52
describe "when setting the base path" do
54
@file = Puppet::FileServing::FileBase.new("puppet://host/module/dir/file")
57
it "should require that the base path be fully qualified" do
58
FileTest.stubs(:exists?).returns(true)
59
proc { @file.path = "unqualified/file" }.should raise_error(ArgumentError)
63
describe "when setting the relative path" do
64
it "should require that the relative path be unqualified" do
65
@file = Puppet::FileServing::FileBase.new("puppet://host/module/dir/file")
66
FileTest.stubs(:exists?).returns(true)
67
proc { @file.relative_path = "/qualified/file" }.should raise_error(ArgumentError)
71
describe "when determining the full file path" do
73
@file = Puppet::FileServing::FileBase.new("mykey", :path => "/this/file")
76
it "should return the path if there is no relative path" do
77
@file.full_path.should == "/this/file"
80
it "should return the path if the relative_path is set to ''" do
81
@file.relative_path = ""
82
@file.full_path.should == "/this/file"
85
it "should return the path joined with the relative path if there is a relative path and it is not set to '/' or ''" do
86
@file.relative_path = "not/qualified"
87
@file.full_path.should == "/this/file/not/qualified"
90
it "should should fail if there is no path set" do
91
@file = Puppet::FileServing::FileBase.new("not/qualified")
92
proc { @file.full_path }.should raise_error(ArgumentError)
96
describe "when stat'ing files" do
98
@file = Puppet::FileServing::FileBase.new("mykey", :path => "/this/file")
101
it "should stat the file's full path" do
102
@file.stubs(:full_path).returns("/this/file")
103
File.expects(:lstat).with("/this/file").returns stub("stat", :ftype => "file")
107
it "should fail if the file does not exist" do
108
@file.stubs(:full_path).returns("/this/file")
109
File.expects(:lstat).with("/this/file").raises(Errno::ENOENT)
110
proc { @file.stat }.should raise_error(Errno::ENOENT)
113
it "should use :lstat if :links is set to :manage" do
114
File.expects(:lstat).with("/this/file").returns stub("stat", :ftype => "file")
118
it "should use :stat if :links is set to :follow" do
119
File.expects(:stat).with("/this/file").returns stub("stat", :ftype => "file")
120
@file.links = :follow