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

« back to all changes in this revision

Viewing changes to spec/unit/file_serving/mount.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:
3
3
require File.dirname(__FILE__) + '/../../spec_helper'
4
4
require 'puppet/file_serving/mount'
5
5
 
6
 
module FileServingMountTesting
7
 
    def stub_facter(hostname)
8
 
        Facter.stubs(:value).with("hostname").returns(hostname.sub(/\..+/, ''))
9
 
        Facter.stubs(:value).with("domain").returns(hostname.sub(/^[^.]+\./, ''))
10
 
    end
11
 
end
12
 
 
13
6
describe Puppet::FileServing::Mount do
14
 
    it "should provide a method for clearing its cached host information" do
15
 
        Puppet::FileServing::Mount.new("whatever").send(:localmap)
16
 
        Puppet::FileServing::Mount.clear_cache
17
 
        Puppet::FileServing::Mount.send(:class_variable_get, "@@localmap").should be_nil
 
7
    it "should use 'mount[$name]' as its string form" do
 
8
        Puppet::FileServing::Mount.new("foo").to_s.should == "mount[foo]"
18
9
    end
19
10
end
20
11
 
26
17
    it "should allow dashes in its name" do
27
18
        Puppet::FileServing::Mount.new("non-alpha").name.should == "non-alpha"
28
19
    end
29
 
 
30
 
    it "should allow an optional path" do
31
 
        Puppet::FileServing::Mount.new("name", "/").path.should == "/"
32
 
    end
33
 
end
34
 
 
35
 
describe Puppet::FileServing::Mount, " when setting the path" do
36
 
    before do
37
 
        @mount = Puppet::FileServing::Mount.new("test")
38
 
        @dir = "/this/path/does/not/exist"
39
 
    end
40
 
 
41
 
    it "should fail if the path is not a directory" do
42
 
        FileTest.expects(:directory?).returns(false)
43
 
        proc { @mount.path = @dir }.should raise_error(ArgumentError)
44
 
    end
45
 
 
46
 
    it "should fail if the path is not readable" do
47
 
        FileTest.expects(:directory?).returns(true)
48
 
        FileTest.expects(:readable?).returns(false)
49
 
        proc { @mount.path = @dir }.should raise_error(ArgumentError)
50
 
    end
51
20
end
52
21
 
53
22
describe Puppet::FileServing::Mount, " when finding files" do
54
 
    include FileServingMountTesting
55
 
 
56
 
    before do
57
 
        FileTest.stubs(:directory?).returns(true)
58
 
        FileTest.stubs(:readable?).returns(true)
59
 
        @mount = Puppet::FileServing::Mount.new("test")
60
 
        @host = "host.domain.com"
61
 
    end
62
 
 
63
 
    it "should fail if the mount path has not been set" do
64
 
        proc { @mount.file_path("/blah") }.should raise_error(ArgumentError)
65
 
    end
66
 
 
67
 
    it "should replace incidences of %h in the path with the client's short name" do
68
 
        @mount.path = "/dir/%h/yay"
69
 
        @mount.path(@host).should == "/dir/host/yay"
70
 
    end
71
 
 
72
 
    it "should replace incidences of %H in the path with the client's fully qualified name" do
73
 
        @mount.path = "/dir/%H/yay"
74
 
        @mount.path(@host).should == "/dir/host.domain.com/yay"
75
 
    end
76
 
 
77
 
    it "should replace incidences of %d in the path with the client's domain name" do
78
 
        @mount.path = "/dir/%d/yay"
79
 
        @mount.path(@host).should == "/dir/domain.com/yay"
80
 
    end
81
 
 
82
 
    it "should perform all necessary replacements" do
83
 
        @mount.path = "/%h/%d/%H"
84
 
        @mount.path(@host).should == "/host/domain.com/host.domain.com"
85
 
    end
86
 
 
87
 
    it "should perform replacements on the base path" do
88
 
        @mount.path = "/blah/%h"
89
 
        @mount.file_path("/my/stuff", @host).should == "/blah/host/my/stuff"
90
 
    end
91
 
 
92
 
    it "should not perform replacements on the per-file path" do
93
 
        @mount.path = "/blah"
94
 
        @mount.file_path("/%h/stuff", @host).should == "/blah/%h/stuff"
95
 
    end
96
 
 
97
 
    it "should look for files relative to its base directory" do
98
 
        @mount.path = "/blah"
99
 
        @mount.file_path("/my/stuff", @host).should == "/blah/my/stuff"
100
 
    end
101
 
 
102
 
    it "should use local host information if no client data is provided" do
103
 
        stub_facter("myhost.mydomain.com")
104
 
        @mount.path = "/%h/%d/%H"
105
 
        @mount.path().should == "/myhost/mydomain.com/myhost.mydomain.com"
106
 
    end
107
 
 
108
 
    after do
109
 
        Puppet::FileServing::Mount.clear_cache
 
23
    it "should fail" do
 
24
        lambda { Puppet::FileServing::Mount.new("test").find("foo", :one => "two") }.should raise_error(NotImplementedError)
110
25
    end
111
26
end
112
27
 
113
 
describe Puppet::FileServing::Mount, " when providing file paths" do
114
 
    include FileServingMountTesting
115
 
 
116
 
    before do
117
 
        FileTest.stubs(:exists?).returns(true)
118
 
        FileTest.stubs(:directory?).returns(true)
119
 
        FileTest.stubs(:readable?).returns(true)
120
 
        @mount = Puppet::FileServing::Mount.new("test", "/mount/%h")
121
 
        stub_facter("myhost.mydomain.com")
122
 
        @host = "host.domain.com"
123
 
    end
124
 
 
125
 
    it "should return nil if the file is absent" do
126
 
        FileTest.stubs(:exists?).returns(false)
127
 
        @mount.file("/my/path").should be_nil
128
 
    end
129
 
 
130
 
    it "should return the file path if the file is absent" do
131
 
        FileTest.stubs(:exists?).with("/my/path").returns(true)
132
 
        @mount.file("/my/path").should == "/mount/myhost/my/path"
133
 
    end
134
 
 
135
 
    it "should treat a nil file name as the path to the mount itself" do
136
 
        FileTest.stubs(:exists?).returns(true)
137
 
        @mount.file(nil).should == "/mount/myhost"
138
 
    end
139
 
 
140
 
    it "should use the client host name if provided in the options" do
141
 
        @mount.file("/my/path", :node => @host).should == "/mount/host/my/path"
 
28
describe Puppet::FileServing::Mount, " when searching for files" do
 
29
    it "should fail" do
 
30
        lambda { Puppet::FileServing::Mount.new("test").search("foo", :one => "two") }.should raise_error(NotImplementedError)
142
31
    end
143
32
end