~ubuntu-branches/ubuntu/trusty/puppet/trusty

« back to all changes in this revision

Viewing changes to spec/unit/file_serving/fileset_spec.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2011-10-22 14:08:22 UTC
  • mfrom: (1.1.25) (3.1.32 sid)
  • Revision ID: package-import@ubuntu.com-20111022140822-odxde5lohc45yhuz
Tags: 2.7.6-1
* New upstream release (CVE-2011-3872)
* Remove cherry-picked "groupadd_aix_warning" patch
* Install all new manpages

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
require 'puppet/file_serving/fileset'
5
5
 
6
6
describe Puppet::FileServing::Fileset, " when initializing" do
 
7
  include PuppetSpec::Files
 
8
 
 
9
  before :each do
 
10
    @somefile = make_absolute("/some/file")
 
11
  end
 
12
 
7
13
  it "should require a path" do
8
14
    proc { Puppet::FileServing::Fileset.new }.should raise_error(ArgumentError)
9
15
  end
13
19
  end
14
20
 
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
21
26
  end
22
27
 
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
28
33
  end
29
34
 
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)
33
38
  end
34
39
 
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
39
44
  end
40
45
 
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
45
50
  end
46
51
 
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"]
51
56
  end
52
57
 
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
57
62
  end
58
63
 
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
63
68
  end
64
69
 
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)
67
72
  end
68
73
 
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
72
77
  end
73
78
 
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
77
82
  end
78
83
 
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 == []
82
87
  end
83
88
 
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
87
92
  end
88
93
 
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
93
98
  end
94
99
 
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")
100
106
    end
101
107
 
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]
106
112
      end
107
113
 
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]
111
117
      end
112
118
    end
113
119
 
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
117
123
    end
118
124
 
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
122
128
    end
123
129
 
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
127
133
    end
128
134
  end
129
135
end
130
136
 
131
137
describe Puppet::FileServing::Fileset, " when determining whether to recurse" do
 
138
  include PuppetSpec::Files
 
139
 
132
140
  before do
133
 
    @path = "/my/path"
 
141
    @path = make_absolute("/my/path")
134
142
    File.expects(:lstat).with(@path).returns stub("stat")
135
143
    @fileset = Puppet::FileServing::Fileset.new(@path)
136
144
  end
166
174
end
167
175
 
168
176
describe Puppet::FileServing::Fileset, " when recursing" do
 
177
  include PuppetSpec::Files
 
178
 
169
179
  before do
170
 
    @path = "/my/path"
 
180
    @path = make_absolute("/my/path")
171
181
    File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
172
182
    @fileset = Puppet::FileServing::Fileset.new(@path)
173
183
 
257
267
  end
258
268
 
259
269
  it "should succeed when paths have regexp significant characters" do
260
 
    @path = "/my/path/rV1x2DafFr0R6tGG+1bbk++++TM"
 
270
    @path = make_absolute("/my/path/rV1x2DafFr0R6tGG+1bbk++++TM")
261
271
    File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
262
272
    @fileset = Puppet::FileServing::Fileset.new(@path)
263
273
    mock_dir_structure(@path)
267
277
end
268
278
 
269
279
describe Puppet::FileServing::Fileset, " when following links that point to missing files" do
 
280
  include PuppetSpec::Files
 
281
 
270
282
  before do
271
 
    @path = "/my/path"
 
283
    @path = make_absolute("/my/path")
272
284
    File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
273
285
    @fileset = Puppet::FileServing::Fileset.new(@path)
274
286
    @fileset.links = :follow
291
303
end
292
304
 
293
305
describe Puppet::FileServing::Fileset, " when ignoring" do
 
306
  include PuppetSpec::Files
 
307
 
294
308
  before do
295
 
    @path = "/my/path"
 
309
    @path = make_absolute("/my/path")
296
310
    File.expects(:lstat).with(@path).returns stub("stat", :directory? => true)
297
311
    @fileset = Puppet::FileServing::Fileset.new(@path)
298
312
  end
318
332
end
319
333
 
320
334
describe Puppet::FileServing::Fileset, "when merging other filesets" do
 
335
  include PuppetSpec::Files
 
336
 
321
337
  before do
322
 
    @paths = %w{/first/path /second/path /third/path}
 
338
    @paths = [make_absolute("/first/path"), make_absolute("/second/path"), make_absolute("/third/path")]
323
339
    File.stubs(:lstat).returns stub("stat", :directory? => false)
324
340
 
325
341
    @filesets = @paths.collect do |path|
331
347
  end
332
348
 
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})
337
353
 
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"),
346
362
    }
347
363
  end
348
364
 
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})
352
368
 
353
 
    Puppet::FileServing::Fileset.merge(*@filesets)["."].should == "/first/path"
 
369
    Puppet::FileServing::Fileset.merge(*@filesets)["."].should == make_absolute("/first/path")
354
370
  end
355
371
 
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})
359
375
 
360
 
    Puppet::FileServing::Fileset.merge(*@filesets)["one"].should == "/first/path"
 
376
    Puppet::FileServing::Fileset.merge(*@filesets)["one"].should == make_absolute("/first/path")
361
377
  end
362
378
end