~ubuntu-branches/ubuntu/lucid/puppet/lucid-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env ruby
2
 
 
3
 
require File.dirname(__FILE__) + '/../../spec_helper'
4
 
 
5
 
require 'puppet/file_serving/file_base'
6
 
 
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"
10
 
    end
11
 
 
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
14
 
    end
15
 
 
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
18
 
    end
19
 
 
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)
22
 
    end
23
 
 
24
 
    it "should default to :manage for :links" do
25
 
        Puppet::FileServing::FileBase.new("puppet://host/module/dir/file").links.should == :manage
26
 
    end
27
 
 
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"
31
 
    end
32
 
 
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"
36
 
    end
37
 
 
38
 
    it "should have a means of determining if the file exists" do
39
 
        Puppet::FileServing::FileBase.new("blah").should respond_to(:exist?)
40
 
    end
41
 
 
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
45
 
    end
46
 
 
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
50
 
    end
51
 
 
52
 
    describe "when setting the base path" do
53
 
        before do
54
 
            @file = Puppet::FileServing::FileBase.new("puppet://host/module/dir/file")
55
 
        end
56
 
 
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)
60
 
        end
61
 
    end
62
 
 
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)
68
 
        end
69
 
    end
70
 
 
71
 
    describe "when determining the full file path" do
72
 
        before do
73
 
            @file = Puppet::FileServing::FileBase.new("mykey", :path => "/this/file")
74
 
        end
75
 
 
76
 
        it "should return the path if there is no relative path" do
77
 
            @file.full_path.should == "/this/file"
78
 
        end
79
 
 
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"
83
 
        end
84
 
 
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"
88
 
        end
89
 
 
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)
93
 
        end
94
 
    end
95
 
 
96
 
    describe "when stat'ing files" do
97
 
        before do
98
 
            @file = Puppet::FileServing::FileBase.new("mykey", :path => "/this/file")
99
 
        end
100
 
 
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")
104
 
            @file.stat
105
 
        end
106
 
 
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)
111
 
        end
112
 
 
113
 
        it "should use :lstat if :links is set to :manage" do
114
 
            File.expects(:lstat).with("/this/file").returns stub("stat", :ftype => "file")
115
 
            @file.stat
116
 
        end
117
 
 
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
121
 
            @file.stat
122
 
        end
123
 
    end
124
 
end