puppet 3.2.0.rc1 → 3.2.0.rc2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

@@ -39,6 +39,8 @@ describe Puppet::Daemon, :unless => Puppet.features.microsoft_windows? do
39
39
  @daemon.reopen_logs
40
40
  end
41
41
 
42
+ let(:server) { stub("Server", :start => nil, :wait_for_shutdown => nil) }
43
+
42
44
  describe "when setting signal traps" do
43
45
  signals = {:INT => :stop, :TERM => :stop }
44
46
  signals.update({:HUP => :restart, :USR1 => :reload, :USR2 => :reopen_logs}) unless Puppet.features.microsoft_windows?
@@ -74,12 +76,21 @@ describe Puppet::Daemon, :unless => Puppet.features.microsoft_windows? do
74
76
  end
75
77
 
76
78
  it "should start its server if one is configured" do
77
- server = mock 'server'
79
+ @daemon.server = server
80
+
78
81
  server.expects(:start)
79
82
  @daemon.stubs(:server).returns server
80
83
 
81
84
  @daemon.start
82
85
  end
86
+
87
+ it "waits for the server to shutdown when there is one" do
88
+ @daemon.server = server
89
+
90
+ server.expects(:wait_for_shutdown)
91
+
92
+ @daemon.start
93
+ end
83
94
  end
84
95
 
85
96
  describe "when stopping" do
@@ -97,7 +108,6 @@ describe Puppet::Daemon, :unless => Puppet.features.microsoft_windows? do
97
108
  end
98
109
 
99
110
  it "should stop its server if one is configured" do
100
- server = mock 'server'
101
111
  server.expects(:stop)
102
112
  @daemon.stubs(:server).returns server
103
113
  expect { @daemon.stop }.to exit_with 0
@@ -3,376 +3,326 @@ require 'spec_helper'
3
3
 
4
4
  require 'puppet/file_serving/fileset'
5
5
 
6
- describe Puppet::FileServing::Fileset, " when initializing" do
6
+ describe Puppet::FileServing::Fileset do
7
7
  include PuppetSpec::Files
8
+ let(:somefile) { make_absolute("/some/file") }
8
9
 
9
- let(:request) { Puppet::Indirector::Request.new(:file_serving, :find, "foo", nil) }
10
-
11
- before :each do
12
- @somefile = make_absolute("/some/file")
13
- end
14
-
15
- it "should require a path" do
16
- proc { Puppet::FileServing::Fileset.new }.should raise_error(ArgumentError)
17
- end
18
-
19
- it "should fail if its path is not fully qualified" do
20
- proc { Puppet::FileServing::Fileset.new("some/file") }.should raise_error(ArgumentError)
21
- end
22
-
23
- it "should not fail if the path is fully qualified, with a trailing separator" do
24
- path_with_separator = "#{@somefile}#{File::SEPARATOR}"
25
- File.stubs(:lstat).with(@somefile).returns stub('stat')
26
- fileset = Puppet::FileServing::Fileset.new(path_with_separator)
27
- fileset.path.should == @somefile
28
- end
29
-
30
- it "should not fail if the path is just the file separator" do
31
- path = File.expand_path(File::SEPARATOR)
32
- File.stubs(:lstat).with(path).returns stub('stat')
33
- fileset = Puppet::FileServing::Fileset.new(path)
34
- fileset.path.should == path
35
- end
36
-
37
- it "should fail if its path does not exist" do
38
- File.expects(:lstat).with(@somefile).returns nil
39
- proc { Puppet::FileServing::Fileset.new(@somefile) }.should raise_error(ArgumentError)
40
- end
41
-
42
- it "should accept a 'recurse' option" do
43
- File.expects(:lstat).with(@somefile).returns stub("stat")
44
- set = Puppet::FileServing::Fileset.new(@somefile, :recurse => true)
45
- set.recurse.should be_true
46
- end
47
-
48
- it "should accept a 'recurselimit' option" do
49
- File.expects(:lstat).with(@somefile).returns stub("stat")
50
- set = Puppet::FileServing::Fileset.new(@somefile, :recurselimit => 3)
51
- set.recurselimit.should == 3
52
- end
53
-
54
- it "should accept an 'ignore' option" do
55
- File.expects(:lstat).with(@somefile).returns stub("stat")
56
- set = Puppet::FileServing::Fileset.new(@somefile, :ignore => ".svn")
57
- set.ignore.should == [".svn"]
58
- end
59
-
60
- it "should accept a 'links' option" do
61
- File.expects(:lstat).with(@somefile).returns stub("stat")
62
- set = Puppet::FileServing::Fileset.new(@somefile, :links => :manage)
63
- set.links.should == :manage
64
- end
10
+ context "when initializing" do
11
+ it "requires a path" do
12
+ expect { Puppet::FileServing::Fileset.new }.to raise_error(ArgumentError)
13
+ end
65
14
 
66
- it "should accept a 'checksum_type' option" do
67
- File.expects(:lstat).with(@somefile).returns stub("stat")
68
- set = Puppet::FileServing::Fileset.new(@somefile, :checksum_type => :test)
69
- set.checksum_type.should == :test
70
- end
15
+ it "fails if its path is not fully qualified" do
16
+ expect { Puppet::FileServing::Fileset.new("some/file") }.to raise_error(ArgumentError, "Fileset paths must be fully qualified: some/file")
17
+ end
71
18
 
72
- it "should fail if 'links' is set to anything other than :manage or :follow" do
73
- proc { Puppet::FileServing::Fileset.new(@somefile, :links => :whatever) }.should raise_error(ArgumentError)
74
- end
19
+ it "removes a trailing file path separator" do
20
+ path_with_separator = "#{somefile}#{File::SEPARATOR}"
21
+ File.stubs(:lstat).with(somefile).returns stub('stat')
22
+ fileset = Puppet::FileServing::Fileset.new(path_with_separator)
23
+ fileset.path.should == somefile
24
+ end
75
25
 
76
- it "should default to 'false' for recurse" do
77
- File.expects(:lstat).with(@somefile).returns stub("stat")
78
- Puppet::FileServing::Fileset.new(@somefile).recurse.should == false
79
- end
26
+ it "can be created from the root directory" do
27
+ path = File.expand_path(File::SEPARATOR)
28
+ File.stubs(:lstat).with(path).returns stub('stat')
29
+ fileset = Puppet::FileServing::Fileset.new(path)
30
+ fileset.path.should == path
31
+ end
80
32
 
81
- it "should default to :infinite for recurselimit" do
82
- File.expects(:lstat).with(@somefile).returns stub("stat")
83
- Puppet::FileServing::Fileset.new(@somefile).recurselimit.should == :infinite
84
- end
33
+ it "fails if its path does not exist" do
34
+ File.expects(:lstat).with(somefile).raises(Errno::ENOENT)
35
+ expect { Puppet::FileServing::Fileset.new(somefile) }.to raise_error(ArgumentError, "Fileset paths must exist")
36
+ end
85
37
 
86
- it "should default to an empty ignore list" do
87
- File.expects(:lstat).with(@somefile).returns stub("stat")
88
- Puppet::FileServing::Fileset.new(@somefile).ignore.should == []
89
- end
38
+ it "accepts a 'recurse' option" do
39
+ File.expects(:lstat).with(somefile).returns stub("stat")
40
+ set = Puppet::FileServing::Fileset.new(somefile, :recurse => true)
41
+ set.recurse.should be_true
42
+ end
90
43
 
91
- it "should default to :manage for links" do
92
- File.expects(:lstat).with(@somefile).returns stub("stat")
93
- Puppet::FileServing::Fileset.new(@somefile).links.should == :manage
94
- end
44
+ it "accepts a 'recurselimit' option" do
45
+ File.expects(:lstat).with(somefile).returns stub("stat")
46
+ set = Puppet::FileServing::Fileset.new(somefile, :recurselimit => 3)
47
+ set.recurselimit.should == 3
48
+ end
95
49
 
96
- it "should support using an Indirector Request for its options" do
97
- File.expects(:lstat).with(@somefile).returns stub("stat")
98
- lambda { Puppet::FileServing::Fileset.new(@somefile, request) }.should_not raise_error
99
- end
50
+ it "accepts an 'ignore' option" do
51
+ File.expects(:lstat).with(somefile).returns stub("stat")
52
+ set = Puppet::FileServing::Fileset.new(somefile, :ignore => ".svn")
53
+ set.ignore.should == [".svn"]
54
+ end
100
55
 
101
- describe "using an indirector request" do
102
- before do
103
- File.stubs(:lstat).returns stub("stat")
104
- @values = {:links => :manage, :ignore => %w{a b}, :recurse => true, :recurselimit => 1234}
105
- @myfile = make_absolute("/my/file")
56
+ it "accepts a 'links' option" do
57
+ File.expects(:lstat).with(somefile).returns stub("stat")
58
+ set = Puppet::FileServing::Fileset.new(somefile, :links => :manage)
59
+ set.links.should == :manage
106
60
  end
107
61
 
108
- [:recurse, :recurselimit, :ignore, :links].each do |option|
109
- it "should pass :recurse, :recurselimit, :ignore, and :links settings on to the fileset if present" do
110
- request.stubs(:options).returns(option => @values[option])
111
- Puppet::FileServing::Fileset.new(@myfile, request).send(option).should == @values[option]
112
- end
62
+ it "accepts a 'checksum_type' option" do
63
+ File.expects(:lstat).with(somefile).returns stub("stat")
64
+ set = Puppet::FileServing::Fileset.new(somefile, :checksum_type => :test)
65
+ set.checksum_type.should == :test
66
+ end
113
67
 
114
- it "should pass :recurse, :recurselimit, :ignore, and :links settings on to the fileset if present with the keys stored as strings" do
115
- request.stubs(:options).returns(option.to_s => @values[option])
116
- Puppet::FileServing::Fileset.new(@myfile, request).send(option).should == @values[option]
117
- end
68
+ it "fails if 'links' is set to anything other than :manage or :follow" do
69
+ expect { Puppet::FileServing::Fileset.new(somefile, :links => :whatever) }.to raise_error(ArgumentError, "Invalid :links value 'whatever'")
118
70
  end
119
71
 
120
- it "should convert the integer as a string to their integer counterpart when setting options" do
121
- request.stubs(:options).returns(:recurselimit => "1234")
122
- Puppet::FileServing::Fileset.new(@myfile, request).recurselimit.should == 1234
72
+ it "defaults to 'false' for recurse" do
73
+ File.expects(:lstat).with(somefile).returns stub("stat")
74
+ Puppet::FileServing::Fileset.new(somefile).recurse.should == false
123
75
  end
124
76
 
125
- it "should convert the string 'true' to the boolean true when setting options" do
126
- request.stubs(:options).returns(:recurse => "true")
127
- Puppet::FileServing::Fileset.new(@myfile, request).recurse.should == true
77
+ it "defaults to :infinite for recurselimit" do
78
+ File.expects(:lstat).with(somefile).returns stub("stat")
79
+ Puppet::FileServing::Fileset.new(somefile).recurselimit.should == :infinite
128
80
  end
129
81
 
130
- it "should convert the string 'false' to the boolean false when setting options" do
131
- request.stubs(:options).returns(:recurse => "false")
132
- Puppet::FileServing::Fileset.new(@myfile, request).recurse.should == false
82
+ it "defaults to an empty ignore list" do
83
+ File.expects(:lstat).with(somefile).returns stub("stat")
84
+ Puppet::FileServing::Fileset.new(somefile).ignore.should == []
133
85
  end
134
- end
135
- end
136
86
 
137
- describe Puppet::FileServing::Fileset, " when determining whether to recurse" do
138
- include PuppetSpec::Files
87
+ it "defaults to :manage for links" do
88
+ File.expects(:lstat).with(somefile).returns stub("stat")
89
+ Puppet::FileServing::Fileset.new(somefile).links.should == :manage
90
+ end
139
91
 
140
- before do
141
- @path = make_absolute("/my/path")
142
- File.expects(:lstat).with(@path).returns stub("stat")
143
- @fileset = Puppet::FileServing::Fileset.new(@path)
144
- end
92
+ describe "using an indirector request" do
93
+ let(:values) { { :links => :manage, :ignore => %w{a b}, :recurse => true, :recurselimit => 1234 } }
145
94
 
146
- it "should always recurse if :recurse is set to 'true' and with infinite recursion" do
147
- @fileset.recurse = true
148
- @fileset.recurselimit = :infinite
149
- @fileset.recurse?(0).should be_true
150
- end
95
+ before :each do
96
+ File.stubs(:lstat).returns stub("stat")
97
+ end
151
98
 
152
- it "should never recurse if :recurse is set to 'false'" do
153
- @fileset.recurse = false
154
- @fileset.recurse?(-1).should be_false
155
- end
99
+ [:recurse, :recurselimit, :ignore, :links].each do |option|
100
+ it "passes the #{option} option on to the fileset if present" do
101
+ request = Puppet::Indirector::Request.new(:file_serving, :find, "foo", nil, {option => values[option]})
156
102
 
157
- it "should recurse if :recurse is set to true, :recurselimit is set to an integer and the current depth is less than that integer" do
158
- @fileset.recurse = true
159
- @fileset.recurselimit = 1
160
- @fileset.recurse?(0).should be_true
161
- end
103
+ Puppet::FileServing::Fileset.new(somefile, request).send(option).should == values[option]
104
+ end
105
+ end
162
106
 
163
- it "should recurse if :recurse is set to true, :recurselimit is set to an integer and the current depth is equal to that integer" do
164
- @fileset.recurse = true
165
- @fileset.recurselimit = 1
166
- @fileset.recurse?(1).should be_true
167
- end
107
+ it "converts the integer as a string to their integer counterpart when setting options" do
108
+ request = Puppet::Indirector::Request.new(:file_serving, :find, "foo", nil,
109
+ {:recurselimit => "1234"})
168
110
 
169
- it "should not recurse if :recurse is set to true, :recurselimit is set to an integer and the current depth is greater than that integer" do
170
- @fileset.recurse = true
171
- @fileset.recurselimit = 1
172
- @fileset.recurse?(2).should be_false
173
- end
174
- end
111
+ Puppet::FileServing::Fileset.new(somefile, request).recurselimit.should == 1234
112
+ end
175
113
 
176
- describe Puppet::FileServing::Fileset, " when recursing" do
177
- include PuppetSpec::Files
114
+ it "converts the string 'true' to the boolean true when setting options" do
115
+ request = Puppet::Indirector::Request.new(:file_serving, :find, "foo", nil,
116
+ {:recurse => "true"})
178
117
 
179
- before do
180
- @path = make_absolute("/my/path")
181
- File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
182
- @fileset = Puppet::FileServing::Fileset.new(@path)
118
+ Puppet::FileServing::Fileset.new(somefile, request).recurse.should == true
119
+ end
183
120
 
184
- @dirstat = stub 'dirstat', :directory? => true
185
- @filestat = stub 'filestat', :directory? => false
186
- end
121
+ it "converts the string 'false' to the boolean false when setting options" do
122
+ request = Puppet::Indirector::Request.new(:file_serving, :find, "foo", nil,
123
+ {:recurse => "false"})
187
124
 
188
- def mock_dir_structure(path, stat_method = :lstat)
189
- File.stubs(stat_method).with(path).returns(@dirstat)
190
- Dir.stubs(:entries).with(path).returns(%w{one two .svn CVS})
191
-
192
- # Keep track of the files we're stubbing.
193
- @files = %w{.}
194
-
195
- %w{one two .svn CVS}.each do |subdir|
196
- @files << subdir # relative path
197
- subpath = File.join(path, subdir)
198
- File.stubs(stat_method).with(subpath).returns(@dirstat)
199
- Dir.stubs(:entries).with(subpath).returns(%w{.svn CVS file1 file2})
200
- %w{file1 file2 .svn CVS}.each do |file|
201
- @files << File.join(subdir, file) # relative path
202
- File.stubs(stat_method).with(File.join(subpath, file)).returns(@filestat)
125
+ Puppet::FileServing::Fileset.new(somefile, request).recurse.should == false
203
126
  end
204
127
  end
205
128
  end
206
129
 
207
- it "should recurse through the whole file tree if :recurse is set to 'true'" do
208
- mock_dir_structure(@path)
209
- @fileset.stubs(:recurse?).returns(true)
210
- @fileset.files.sort.should == @files.sort
211
- end
130
+ context "when recursing" do
131
+ before do
132
+ @path = make_absolute("/my/path")
133
+ File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
134
+ @fileset = Puppet::FileServing::Fileset.new(@path)
212
135
 
213
- it "should not recurse if :recurse is set to 'false'" do
214
- mock_dir_structure(@path)
215
- @fileset.stubs(:recurse?).returns(false)
216
- @fileset.files.should == %w{.}
217
- end
136
+ @dirstat = stub 'dirstat', :directory? => true
137
+ @filestat = stub 'filestat', :directory? => false
138
+ end
218
139
 
219
- # It seems like I should stub :recurse? here, or that I shouldn't stub the
220
- # examples above, but...
221
- it "should recurse to the level set if :recurselimit is set to an integer" do
222
- mock_dir_structure(@path)
223
- @fileset.recurse = true
224
- @fileset.recurselimit = 1
225
- @fileset.files.should == %w{. one two .svn CVS}
226
- end
140
+ def mock_dir_structure(path, stat_method = :lstat)
141
+ File.stubs(stat_method).with(path).returns(@dirstat)
142
+ Dir.stubs(:entries).with(path).returns(%w{one two .svn CVS})
143
+
144
+ # Keep track of the files we're stubbing.
145
+ @files = %w{.}
146
+
147
+ %w{one two .svn CVS}.each do |subdir|
148
+ @files << subdir # relative path
149
+ subpath = File.join(path, subdir)
150
+ File.stubs(stat_method).with(subpath).returns(@dirstat)
151
+ Dir.stubs(:entries).with(subpath).returns(%w{.svn CVS file1 file2})
152
+ %w{file1 file2 .svn CVS}.each do |file|
153
+ @files << File.join(subdir, file) # relative path
154
+ File.stubs(stat_method).with(File.join(subpath, file)).returns(@filestat)
155
+ end
156
+ end
157
+ end
227
158
 
228
- it "should ignore the '.' and '..' directories in subdirectories" do
229
- mock_dir_structure(@path)
230
- @fileset.recurse = true
231
- @fileset.files.sort.should == @files.sort
232
- end
159
+ MockStat = Struct.new(:path, :directory) do
160
+ # struct doesn't support thing ending in ?
161
+ def directory?
162
+ directory
163
+ end
164
+ end
233
165
 
234
- it "should function if the :ignore value provided is nil" do
235
- mock_dir_structure(@path)
236
- @fileset.recurse = true
237
- @fileset.ignore = nil
238
- lambda { @fileset.files }.should_not raise_error
239
- end
166
+ MockDirectory = Struct.new(:name, :entries) do
167
+ def mock(base_path)
168
+ path = File.join(base_path, name)
169
+ File.stubs(:lstat).with(path).returns(MockStat.new(path, true))
170
+ Dir.stubs(:entries).with(path).returns(['.', '..'] + entries.map(&:name))
171
+ entries.each do |entry|
172
+ entry.mock(path)
173
+ end
174
+ end
175
+ end
240
176
 
241
- it "should ignore files that match a single pattern in the ignore list" do
242
- mock_dir_structure(@path)
243
- @fileset.recurse = true
244
- @fileset.ignore = ".svn"
245
- @fileset.files.find { |file| file.include?(".svn") }.should be_nil
246
- end
177
+ MockFile = Struct.new(:name) do
178
+ def mock(base_path)
179
+ path = File.join(base_path, name)
180
+ File.stubs(:lstat).with(path).returns(MockStat.new(path, false))
181
+ end
182
+ end
247
183
 
248
- it "should ignore files that match any of multiple patterns in the ignore list" do
249
- mock_dir_structure(@path)
250
- @fileset.recurse = true
251
- @fileset.ignore = %w{.svn CVS}
252
- @fileset.files.find { |file| file.include?(".svn") or file.include?("CVS") }.should be_nil
253
- end
184
+ it "doesn't ignore pending directories when the last entry at the top level is a file" do
185
+ structure = MockDirectory.new('path',
186
+ [MockDirectory.new('dir1',
187
+ [MockDirectory.new('a', [MockFile.new('f')])]),
188
+ MockFile.new('file')])
189
+ structure.mock(make_absolute('/your'))
190
+ fileset = Puppet::FileServing::Fileset.new(make_absolute('/your/path'))
191
+ fileset.recurse = true
192
+ fileset.links = :manage
193
+ fileset.files.should == [".", "dir1", "file", "dir1/a", "dir1/a/f"]
194
+ end
254
195
 
255
- it "should use File.stat if :links is set to :follow" do
256
- mock_dir_structure(@path, :stat)
257
- @fileset.recurse = true
258
- @fileset.links = :follow
259
- @fileset.files.sort.should == @files.sort
260
- end
196
+ it "recurses through the whole file tree if :recurse is set to 'true'" do
197
+ mock_dir_structure(@path)
198
+ @fileset.recurse = true
199
+ @fileset.files.sort.should == @files.sort
200
+ end
261
201
 
262
- it "should use File.lstat if :links is set to :manage" do
263
- mock_dir_structure(@path, :lstat)
264
- @fileset.recurse = true
265
- @fileset.links = :manage
266
- @fileset.files.sort.should == @files.sort
267
- end
202
+ it "does not recurse if :recurse is set to 'false'" do
203
+ mock_dir_structure(@path)
204
+ @fileset.recurse = false
205
+ @fileset.files.should == %w{.}
206
+ end
268
207
 
269
- it "should succeed when paths have regexp significant characters" do
270
- @path = make_absolute("/my/path/rV1x2DafFr0R6tGG+1bbk++++TM")
271
- File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
272
- @fileset = Puppet::FileServing::Fileset.new(@path)
273
- mock_dir_structure(@path)
274
- @fileset.recurse = true
275
- @fileset.files.sort.should == @files.sort
276
- end
277
- end
208
+ it "recurses to the level set by :recurselimit" do
209
+ mock_dir_structure(@path)
210
+ @fileset.recurse = true
211
+ @fileset.recurselimit = 1
212
+ @fileset.files.should == %w{. one two .svn CVS}
213
+ end
278
214
 
279
- describe Puppet::FileServing::Fileset, " when following links that point to missing files" do
280
- include PuppetSpec::Files
215
+ it "ignores the '.' and '..' directories in subdirectories" do
216
+ mock_dir_structure(@path)
217
+ @fileset.recurse = true
218
+ @fileset.files.sort.should == @files.sort
219
+ end
281
220
 
282
- before do
283
- @path = make_absolute("/my/path")
284
- File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
285
- @fileset = Puppet::FileServing::Fileset.new(@path)
286
- @fileset.links = :follow
287
- @fileset.recurse = true
221
+ it "does not fail if the :ignore value provided is nil" do
222
+ mock_dir_structure(@path)
223
+ @fileset.recurse = true
224
+ @fileset.ignore = nil
225
+ expect { @fileset.files }.to_not raise_error
226
+ end
288
227
 
289
- @stat = stub 'stat', :directory? => true
228
+ it "ignores files that match a single pattern in the ignore list" do
229
+ mock_dir_structure(@path)
230
+ @fileset.recurse = true
231
+ @fileset.ignore = ".svn"
232
+ @fileset.files.find { |file| file.include?(".svn") }.should be_nil
233
+ end
290
234
 
291
- File.expects(:stat).with(@path).returns(@stat)
292
- File.expects(:stat).with(File.join(@path, "mylink")).raises(Errno::ENOENT)
293
- Dir.stubs(:entries).with(@path).returns(["mylink"])
294
- end
235
+ it "ignores files that match any of multiple patterns in the ignore list" do
236
+ mock_dir_structure(@path)
237
+ @fileset.recurse = true
238
+ @fileset.ignore = %w{.svn CVS}
239
+ @fileset.files.find { |file| file.include?(".svn") or file.include?("CVS") }.should be_nil
240
+ end
295
241
 
296
- it "should not fail" do
297
- proc { @fileset.files }.should_not raise_error
298
- end
242
+ it "uses File.stat if :links is set to :follow" do
243
+ mock_dir_structure(@path, :stat)
244
+ @fileset.recurse = true
245
+ @fileset.links = :follow
246
+ @fileset.files.sort.should == @files.sort
247
+ end
248
+
249
+ it "uses File.lstat if :links is set to :manage" do
250
+ mock_dir_structure(@path, :lstat)
251
+ @fileset.recurse = true
252
+ @fileset.links = :manage
253
+ @fileset.files.sort.should == @files.sort
254
+ end
299
255
 
300
- it "should still manage the link" do
301
- @fileset.files.sort.should == %w{. mylink}.sort
256
+ it "works when paths have regexp significant characters" do
257
+ @path = make_absolute("/my/path/rV1x2DafFr0R6tGG+1bbk++++TM")
258
+ File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
259
+ @fileset = Puppet::FileServing::Fileset.new(@path)
260
+ mock_dir_structure(@path)
261
+ @fileset.recurse = true
262
+ @fileset.files.sort.should == @files.sort
263
+ end
302
264
  end
303
- end
304
265
 
305
- describe Puppet::FileServing::Fileset, " when ignoring" do
306
- include PuppetSpec::Files
266
+ it "manages the links to missing files" do
267
+ path = make_absolute("/my/path")
268
+ stat = stub 'stat', :directory? => true
307
269
 
308
- before do
309
- @path = make_absolute("/my/path")
310
- File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
311
- @fileset = Puppet::FileServing::Fileset.new(@path)
312
- end
270
+ File.expects(:lstat).with(path).returns(stat)
271
+ File.expects(:stat).with(path).returns(stat)
272
+ File.expects(:stat).with(File.join(path, "mylink")).raises(Errno::ENOENT)
313
273
 
314
- it "should use ruby's globbing to determine what files should be ignored" do
315
- @fileset.ignore = ".svn"
316
- File.expects(:fnmatch?).with(".svn", "my_file")
317
- @fileset.ignore?("my_file")
318
- end
274
+ Dir.stubs(:entries).with(path).returns(["mylink"])
319
275
 
320
- it "should ignore files whose paths match a single provided ignore value" do
321
- @fileset.ignore = ".svn"
322
- File.stubs(:fnmatch?).with(".svn", "my_file").returns true
323
- @fileset.ignore?("my_file").should be_true
324
- end
276
+ fileset = Puppet::FileServing::Fileset.new(path)
277
+
278
+ fileset.links = :follow
279
+ fileset.recurse = true
325
280
 
326
- it "should ignore files whose paths match any of multiple provided ignore values" do
327
- @fileset.ignore = [".svn", "CVS"]
328
- File.stubs(:fnmatch?).with(".svn", "my_file").returns false
329
- File.stubs(:fnmatch?).with("CVS", "my_file").returns true
330
- @fileset.ignore?("my_file").should be_true
281
+ fileset.files.sort.should == %w{. mylink}.sort
331
282
  end
332
- end
333
283
 
334
- describe Puppet::FileServing::Fileset, "when merging other filesets" do
335
- include PuppetSpec::Files
284
+ context "when merging other filesets" do
285
+ before do
286
+ @paths = [make_absolute("/first/path"), make_absolute("/second/path"), make_absolute("/third/path")]
287
+ File.stubs(:lstat).returns stub("stat", :directory? => false)
336
288
 
337
- before do
338
- @paths = [make_absolute("/first/path"), make_absolute("/second/path"), make_absolute("/third/path")]
339
- File.stubs(:lstat).returns stub("stat", :directory? => false)
289
+ @filesets = @paths.collect do |path|
290
+ File.stubs(:lstat).with(path).returns stub("stat", :directory? => true)
291
+ Puppet::FileServing::Fileset.new(path, :recurse => true)
292
+ end
340
293
 
341
- @filesets = @paths.collect do |path|
342
- File.stubs(:lstat).with(path).returns stub("stat", :directory? => true)
343
- Puppet::FileServing::Fileset.new(path, :recurse => true)
294
+ Dir.stubs(:entries).returns []
344
295
  end
345
296
 
346
- Dir.stubs(:entries).returns []
347
- end
348
-
349
- it "should return a hash of all files in each fileset with the value being the base path" do
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})
353
-
354
- Puppet::FileServing::Fileset.merge(*@filesets).should == {
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"),
362
- }
363
- end
297
+ it "returns a hash of all files in each fileset with the value being the base path" do
298
+ Dir.expects(:entries).with(make_absolute("/first/path")).returns(%w{one uno})
299
+ Dir.expects(:entries).with(make_absolute("/second/path")).returns(%w{two dos})
300
+ Dir.expects(:entries).with(make_absolute("/third/path")).returns(%w{three tres})
301
+
302
+ Puppet::FileServing::Fileset.merge(*@filesets).should == {
303
+ "." => make_absolute("/first/path"),
304
+ "one" => make_absolute("/first/path"),
305
+ "uno" => make_absolute("/first/path"),
306
+ "two" => make_absolute("/second/path"),
307
+ "dos" => make_absolute("/second/path"),
308
+ "three" => make_absolute("/third/path"),
309
+ "tres" => make_absolute("/third/path"),
310
+ }
311
+ end
364
312
 
365
- it "should include the base directory from the first fileset" do
366
- Dir.expects(:entries).with(make_absolute("/first/path")).returns(%w{one})
367
- Dir.expects(:entries).with(make_absolute("/second/path")).returns(%w{two})
313
+ it "includes the base directory from the first fileset" do
314
+ Dir.expects(:entries).with(make_absolute("/first/path")).returns(%w{one})
315
+ Dir.expects(:entries).with(make_absolute("/second/path")).returns(%w{two})
368
316
 
369
- Puppet::FileServing::Fileset.merge(*@filesets)["."].should == make_absolute("/first/path")
370
- end
317
+ Puppet::FileServing::Fileset.merge(*@filesets)["."].should == make_absolute("/first/path")
318
+ end
371
319
 
372
- it "should use the base path of the first found file when relative file paths conflict" do
373
- Dir.expects(:entries).with(make_absolute("/first/path")).returns(%w{one})
374
- Dir.expects(:entries).with(make_absolute("/second/path")).returns(%w{one})
320
+ it "uses the base path of the first found file when relative file paths conflict" do
321
+ Dir.expects(:entries).with(make_absolute("/first/path")).returns(%w{one})
322
+ Dir.expects(:entries).with(make_absolute("/second/path")).returns(%w{one})
375
323
 
376
- Puppet::FileServing::Fileset.merge(*@filesets)["one"].should == make_absolute("/first/path")
324
+ Puppet::FileServing::Fileset.merge(*@filesets)["one"].should == make_absolute("/first/path")
325
+ end
377
326
  end
378
327
  end
328
+