15
21
it "should not fail if the path is fully qualified, with a trailing separator" do
16
path = "/some/path/with/trailing/separator"
17
path_with_separator = "#{path}#{File::SEPARATOR}"
18
File.stubs(:lstat).with(path).returns stub('stat')
22
path_with_separator = "#{@somefile}#{File::SEPARATOR}"
23
File.stubs(:lstat).with(@somefile).returns stub('stat')
19
24
fileset = Puppet::FileServing::Fileset.new(path_with_separator)
20
fileset.path.should == path
25
fileset.path.should == @somefile
23
28
it "should not fail if the path is just the file separator" do
24
path = File::SEPARATOR
29
path = File.expand_path(File::SEPARATOR)
25
30
File.stubs(:lstat).with(path).returns stub('stat')
26
31
fileset = Puppet::FileServing::Fileset.new(path)
27
32
fileset.path.should == path
30
35
it "should fail if its path does not exist" do
31
File.expects(:lstat).with("/some/file").returns nil
32
proc { Puppet::FileServing::Fileset.new("/some/file") }.should raise_error(ArgumentError)
36
File.expects(:lstat).with(@somefile).returns nil
37
proc { Puppet::FileServing::Fileset.new(@somefile) }.should raise_error(ArgumentError)
35
40
it "should accept a 'recurse' option" do
36
File.expects(:lstat).with("/some/file").returns stub("stat")
37
set = Puppet::FileServing::Fileset.new("/some/file", :recurse => true)
41
File.expects(:lstat).with(@somefile).returns stub("stat")
42
set = Puppet::FileServing::Fileset.new(@somefile, :recurse => true)
38
43
set.recurse.should be_true
41
46
it "should accept a 'recurselimit' option" do
42
File.expects(:lstat).with("/some/file").returns stub("stat")
43
set = Puppet::FileServing::Fileset.new("/some/file", :recurselimit => 3)
47
File.expects(:lstat).with(@somefile).returns stub("stat")
48
set = Puppet::FileServing::Fileset.new(@somefile, :recurselimit => 3)
44
49
set.recurselimit.should == 3
47
52
it "should accept an 'ignore' option" do
48
File.expects(:lstat).with("/some/file").returns stub("stat")
49
set = Puppet::FileServing::Fileset.new("/some/file", :ignore => ".svn")
53
File.expects(:lstat).with(@somefile).returns stub("stat")
54
set = Puppet::FileServing::Fileset.new(@somefile, :ignore => ".svn")
50
55
set.ignore.should == [".svn"]
53
58
it "should accept a 'links' option" do
54
File.expects(:lstat).with("/some/file").returns stub("stat")
55
set = Puppet::FileServing::Fileset.new("/some/file", :links => :manage)
59
File.expects(:lstat).with(@somefile).returns stub("stat")
60
set = Puppet::FileServing::Fileset.new(@somefile, :links => :manage)
56
61
set.links.should == :manage
59
64
it "should accept a 'checksum_type' option" do
60
File.expects(:lstat).with("/some/file").returns stub("stat")
61
set = Puppet::FileServing::Fileset.new("/some/file", :checksum_type => :test)
65
File.expects(:lstat).with(@somefile).returns stub("stat")
66
set = Puppet::FileServing::Fileset.new(@somefile, :checksum_type => :test)
62
67
set.checksum_type.should == :test
65
70
it "should fail if 'links' is set to anything other than :manage or :follow" do
66
proc { Puppet::FileServing::Fileset.new("/some/file", :links => :whatever) }.should raise_error(ArgumentError)
71
proc { Puppet::FileServing::Fileset.new(@somefile, :links => :whatever) }.should raise_error(ArgumentError)
69
74
it "should default to 'false' for recurse" do
70
File.expects(:lstat).with("/some/file").returns stub("stat")
71
Puppet::FileServing::Fileset.new("/some/file").recurse.should == false
75
File.expects(:lstat).with(@somefile).returns stub("stat")
76
Puppet::FileServing::Fileset.new(@somefile).recurse.should == false
74
79
it "should default to :infinite for recurselimit" do
75
File.expects(:lstat).with("/some/file").returns stub("stat")
76
Puppet::FileServing::Fileset.new("/some/file").recurselimit.should == :infinite
80
File.expects(:lstat).with(@somefile).returns stub("stat")
81
Puppet::FileServing::Fileset.new(@somefile).recurselimit.should == :infinite
79
84
it "should default to an empty ignore list" do
80
File.expects(:lstat).with("/some/file").returns stub("stat")
81
Puppet::FileServing::Fileset.new("/some/file").ignore.should == []
85
File.expects(:lstat).with(@somefile).returns stub("stat")
86
Puppet::FileServing::Fileset.new(@somefile).ignore.should == []
84
89
it "should default to :manage for links" do
85
File.expects(:lstat).with("/some/file").returns stub("stat")
86
Puppet::FileServing::Fileset.new("/some/file").links.should == :manage
90
File.expects(:lstat).with(@somefile).returns stub("stat")
91
Puppet::FileServing::Fileset.new(@somefile).links.should == :manage
89
94
it "should support using an Indirector Request for its options" do
90
File.expects(:lstat).with("/some/file").returns stub("stat")
95
File.expects(:lstat).with(@somefile).returns stub("stat")
91
96
request = Puppet::Indirector::Request.new(:file_serving, :find, "foo")
92
lambda { Puppet::FileServing::Fileset.new("/some/file", request) }.should_not raise_error
97
lambda { Puppet::FileServing::Fileset.new(@somefile, request) }.should_not raise_error
95
100
describe "using an indirector request" do
97
102
File.stubs(:lstat).returns stub("stat")
98
103
@values = {:links => :manage, :ignore => %w{a b}, :recurse => true, :recurselimit => 1234}
99
104
@request = Puppet::Indirector::Request.new(:file_serving, :find, "foo")
105
@myfile = make_absolute("/my/file")
102
108
[:recurse, :recurselimit, :ignore, :links].each do |option|
103
109
it "should pass :recurse, :recurselimit, :ignore, and :links settings on to the fileset if present" do
104
110
@request.stubs(:options).returns(option => @values[option])
105
Puppet::FileServing::Fileset.new("/my/file", @request).send(option).should == @values[option]
111
Puppet::FileServing::Fileset.new(@myfile, @request).send(option).should == @values[option]
108
114
it "should pass :recurse, :recurselimit, :ignore, and :links settings on to the fileset if present with the keys stored as strings" do
109
115
@request.stubs(:options).returns(option.to_s => @values[option])
110
Puppet::FileServing::Fileset.new("/my/file", @request).send(option).should == @values[option]
116
Puppet::FileServing::Fileset.new(@myfile, @request).send(option).should == @values[option]
114
120
it "should convert the integer as a string to their integer counterpart when setting options" do
115
121
@request.stubs(:options).returns(:recurselimit => "1234")
116
Puppet::FileServing::Fileset.new("/my/file", @request).recurselimit.should == 1234
122
Puppet::FileServing::Fileset.new(@myfile, @request).recurselimit.should == 1234
119
125
it "should convert the string 'true' to the boolean true when setting options" do
120
126
@request.stubs(:options).returns(:recurse => "true")
121
Puppet::FileServing::Fileset.new("/my/file", @request).recurse.should == true
127
Puppet::FileServing::Fileset.new(@myfile, @request).recurse.should == true
124
130
it "should convert the string 'false' to the boolean false when setting options" do
125
131
@request.stubs(:options).returns(:recurse => "false")
126
Puppet::FileServing::Fileset.new("/my/file", @request).recurse.should == false
132
Puppet::FileServing::Fileset.new(@myfile, @request).recurse.should == false
131
137
describe Puppet::FileServing::Fileset, " when determining whether to recurse" do
138
include PuppetSpec::Files
141
@path = make_absolute("/my/path")
134
142
File.expects(:lstat).with(@path).returns stub("stat")
135
143
@fileset = Puppet::FileServing::Fileset.new(@path)
333
349
it "should return a hash of all files in each fileset with the value being the base path" do
334
Dir.expects(:entries).with("/first/path").returns(%w{one uno})
335
Dir.expects(:entries).with("/second/path").returns(%w{two dos})
336
Dir.expects(:entries).with("/third/path").returns(%w{three tres})
350
Dir.expects(:entries).with(make_absolute("/first/path")).returns(%w{one uno})
351
Dir.expects(:entries).with(make_absolute("/second/path")).returns(%w{two dos})
352
Dir.expects(:entries).with(make_absolute("/third/path")).returns(%w{three tres})
338
354
Puppet::FileServing::Fileset.merge(*@filesets).should == {
339
"." => "/first/path",
340
"one" => "/first/path",
341
"uno" => "/first/path",
342
"two" => "/second/path",
343
"dos" => "/second/path",
344
"three" => "/third/path",
345
"tres" => "/third/path",
355
"." => make_absolute("/first/path"),
356
"one" => make_absolute("/first/path"),
357
"uno" => make_absolute("/first/path"),
358
"two" => make_absolute("/second/path"),
359
"dos" => make_absolute("/second/path"),
360
"three" => make_absolute("/third/path"),
361
"tres" => make_absolute("/third/path"),
349
365
it "should include the base directory from the first fileset" do
350
Dir.expects(:entries).with("/first/path").returns(%w{one})
351
Dir.expects(:entries).with("/second/path").returns(%w{two})
366
Dir.expects(:entries).with(make_absolute("/first/path")).returns(%w{one})
367
Dir.expects(:entries).with(make_absolute("/second/path")).returns(%w{two})
353
Puppet::FileServing::Fileset.merge(*@filesets)["."].should == "/first/path"
369
Puppet::FileServing::Fileset.merge(*@filesets)["."].should == make_absolute("/first/path")
356
372
it "should use the base path of the first found file when relative file paths conflict" do
357
Dir.expects(:entries).with("/first/path").returns(%w{one})
358
Dir.expects(:entries).with("/second/path").returns(%w{one})
373
Dir.expects(:entries).with(make_absolute("/first/path")).returns(%w{one})
374
Dir.expects(:entries).with(make_absolute("/second/path")).returns(%w{one})
360
Puppet::FileServing::Fileset.merge(*@filesets)["one"].should == "/first/path"
376
Puppet::FileServing::Fileset.merge(*@filesets)["one"].should == make_absolute("/first/path")