27
21
mount.path = "/foo"
28
22
lambda { mount.validate }.should_not raise_error(ArgumentError)
32
describe Puppet::FileServing::Mount::File, " when setting the path" do
34
@mount = Puppet::FileServing::Mount::File.new("test")
35
@dir = "/this/path/does/not/exist"
38
it "should fail if the path is not a directory" do
39
FileTest.expects(:directory?).returns(false)
40
proc { @mount.path = @dir }.should raise_error(ArgumentError)
43
it "should fail if the path is not readable" do
44
FileTest.expects(:directory?).returns(true)
45
FileTest.expects(:readable?).returns(false)
46
proc { @mount.path = @dir }.should raise_error(ArgumentError)
50
describe Puppet::FileServing::Mount::File, " when substituting hostnames and ip addresses into file paths" do
51
include FileServingMountTesting
54
FileTest.stubs(:directory?).returns(true)
55
FileTest.stubs(:readable?).returns(true)
56
@mount = Puppet::FileServing::Mount::File.new("test")
57
@host = "host.domain.com"
60
it "should replace incidences of %h in the path with the client's short name" do
61
@mount.path = "/dir/%h/yay"
62
@mount.path(@host).should == "/dir/host/yay"
65
it "should replace incidences of %H in the path with the client's fully qualified name" do
66
@mount.path = "/dir/%H/yay"
67
@mount.path(@host).should == "/dir/host.domain.com/yay"
70
it "should replace incidences of %d in the path with the client's domain name" do
71
@mount.path = "/dir/%d/yay"
72
@mount.path(@host).should == "/dir/domain.com/yay"
75
it "should perform all necessary replacements" do
76
@mount.path = "/%h/%d/%H"
77
@mount.path(@host).should == "/host/domain.com/host.domain.com"
80
it "should use local host information if no client data is provided" do
81
stub_facter("myhost.mydomain.com")
82
@mount.path = "/%h/%d/%H"
83
@mount.path.should == "/myhost/mydomain.com/myhost.mydomain.com"
87
Puppet::Util::Cacher.expire
91
describe Puppet::FileServing::Mount::File, "when determining the complete file path" do
92
include FileServingMountTesting
95
FileTest.stubs(:exist?).returns(true)
96
FileTest.stubs(:directory?).returns(true)
97
FileTest.stubs(:readable?).returns(true)
98
@mount = Puppet::FileServing::Mount::File.new("test")
99
@mount.path = "/mount"
100
stub_facter("myhost.mydomain.com")
101
@host = "host.domain.com"
104
it "should return nil if the file is absent" do
105
FileTest.stubs(:exist?).returns(false)
106
@mount.complete_path("/my/path", nil).should be_nil
109
it "should write a log message if the file is absent" do
110
FileTest.stubs(:exist?).returns(false)
112
Puppet.expects(:info).with("File does not exist or is not accessible: /mount/my/path")
114
@mount.complete_path("/my/path", nil)
117
it "should return the file path if the file is present" do
118
FileTest.stubs(:exist?).with("/my/path").returns(true)
119
@mount.complete_path("/my/path", nil).should == "/mount/my/path"
122
it "should treat a nil file name as the path to the mount itself" do
123
FileTest.stubs(:exist?).returns(true)
124
@mount.complete_path(nil, nil).should == "/mount"
127
it "should use the client host name if provided in the options" do
128
@mount.path = "/mount/%h"
129
@mount.complete_path("/my/path", @host).should == "/mount/host/my/path"
132
it "should perform replacements on the base path" do
133
@mount.path = "/blah/%h"
134
@mount.complete_path("/my/stuff", @host).should == "/blah/host/my/stuff"
137
it "should not perform replacements on the per-file path" do
138
@mount.path = "/blah"
139
@mount.complete_path("/%h/stuff", @host).should == "/blah/%h/stuff"
142
it "should look for files relative to its base directory" do
143
@mount.complete_path("/my/stuff", @host).should == "/mount/my/stuff"
147
describe Puppet::FileServing::Mount::File, "when finding files" do
148
include FileServingMountTesting
151
FileTest.stubs(:exist?).returns(true)
152
FileTest.stubs(:directory?).returns(true)
153
FileTest.stubs(:readable?).returns(true)
154
@mount = Puppet::FileServing::Mount::File.new("test")
155
@mount.path = "/mount"
156
stub_facter("myhost.mydomain.com")
157
@host = "host.domain.com"
159
@request = stub 'request', :node => "foo"
162
it "should return the results of the complete file path" do
163
FileTest.stubs(:exist?).returns(false)
164
@mount.expects(:complete_path).with("/my/path", "foo").returns "eh"
165
@mount.find("/my/path", @request).should == "eh"
169
describe Puppet::FileServing::Mount::File, "when searching for files" do
170
include FileServingMountTesting
173
FileTest.stubs(:exist?).returns(true)
174
FileTest.stubs(:directory?).returns(true)
175
FileTest.stubs(:readable?).returns(true)
176
@mount = Puppet::FileServing::Mount::File.new("test")
177
@mount.path = "/mount"
178
stub_facter("myhost.mydomain.com")
179
@host = "host.domain.com"
181
@request = stub 'request', :node => "foo"
184
it "should return the results of the complete file path as an array" do
185
FileTest.stubs(:exist?).returns(false)
186
@mount.expects(:complete_path).with("/my/path", "foo").returns "eh"
187
@mount.search("/my/path", @request).should == ["eh"]
190
it "should return nil if the complete path is nil" do
191
FileTest.stubs(:exist?).returns(false)
192
@mount.expects(:complete_path).with("/my/path", "foo").returns nil
193
@mount.search("/my/path", @request).should be_nil
25
describe "when setting the path" do
27
@mount = Puppet::FileServing::Mount::File.new("test")
28
@dir = "/this/path/does/not/exist"
31
it "should fail if the path is not a directory" do
32
FileTest.expects(:directory?).returns(false)
33
proc { @mount.path = @dir }.should raise_error(ArgumentError)
36
it "should fail if the path is not readable" do
37
FileTest.expects(:directory?).returns(true)
38
FileTest.expects(:readable?).returns(false)
39
proc { @mount.path = @dir }.should raise_error(ArgumentError)
43
describe "when substituting hostnames and ip addresses into file paths" do
44
include FileServingMountTesting
47
FileTest.stubs(:directory?).returns(true)
48
FileTest.stubs(:readable?).returns(true)
49
@mount = Puppet::FileServing::Mount::File.new("test")
50
@host = "host.domain.com"
54
Puppet::FileServing::Mount::File.instance_variable_set(:@localmap, nil)
57
it "should replace incidences of %h in the path with the client's short name" do
58
@mount.path = "/dir/%h/yay"
59
@mount.path(@host).should == "/dir/host/yay"
62
it "should replace incidences of %H in the path with the client's fully qualified name" do
63
@mount.path = "/dir/%H/yay"
64
@mount.path(@host).should == "/dir/host.domain.com/yay"
67
it "should replace incidences of %d in the path with the client's domain name" do
68
@mount.path = "/dir/%d/yay"
69
@mount.path(@host).should == "/dir/domain.com/yay"
72
it "should perform all necessary replacements" do
73
@mount.path = "/%h/%d/%H"
74
@mount.path(@host).should == "/host/domain.com/host.domain.com"
77
it "should use local host information if no client data is provided" do
78
stub_facter("myhost.mydomain.com")
79
@mount.path = "/%h/%d/%H"
80
@mount.path.should == "/myhost/mydomain.com/myhost.mydomain.com"
84
describe "when determining the complete file path" do
85
include FileServingMountTesting
88
FileTest.stubs(:exist?).returns(true)
89
FileTest.stubs(:directory?).returns(true)
90
FileTest.stubs(:readable?).returns(true)
91
@mount = Puppet::FileServing::Mount::File.new("test")
92
@mount.path = "/mount"
93
stub_facter("myhost.mydomain.com")
94
@host = "host.domain.com"
97
it "should return nil if the file is absent" do
98
FileTest.stubs(:exist?).returns(false)
99
@mount.complete_path("/my/path", nil).should be_nil
102
it "should write a log message if the file is absent" do
103
FileTest.stubs(:exist?).returns(false)
105
Puppet.expects(:info).with("File does not exist or is not accessible: /mount/my/path")
107
@mount.complete_path("/my/path", nil)
110
it "should return the file path if the file is present" do
111
FileTest.stubs(:exist?).with("/my/path").returns(true)
112
@mount.complete_path("/my/path", nil).should == "/mount/my/path"
115
it "should treat a nil file name as the path to the mount itself" do
116
FileTest.stubs(:exist?).returns(true)
117
@mount.complete_path(nil, nil).should == "/mount"
120
it "should use the client host name if provided in the options" do
121
@mount.path = "/mount/%h"
122
@mount.complete_path("/my/path", @host).should == "/mount/host/my/path"
125
it "should perform replacements on the base path" do
126
@mount.path = "/blah/%h"
127
@mount.complete_path("/my/stuff", @host).should == "/blah/host/my/stuff"
130
it "should not perform replacements on the per-file path" do
131
@mount.path = "/blah"
132
@mount.complete_path("/%h/stuff", @host).should == "/blah/%h/stuff"
135
it "should look for files relative to its base directory" do
136
@mount.complete_path("/my/stuff", @host).should == "/mount/my/stuff"
140
describe "when finding files" do
141
include FileServingMountTesting
144
FileTest.stubs(:exist?).returns(true)
145
FileTest.stubs(:directory?).returns(true)
146
FileTest.stubs(:readable?).returns(true)
147
@mount = Puppet::FileServing::Mount::File.new("test")
148
@mount.path = "/mount"
149
stub_facter("myhost.mydomain.com")
150
@host = "host.domain.com"
152
@request = stub 'request', :node => "foo"
155
it "should return the results of the complete file path" do
156
FileTest.stubs(:exist?).returns(false)
157
@mount.expects(:complete_path).with("/my/path", "foo").returns "eh"
158
@mount.find("/my/path", @request).should == "eh"
162
describe "when searching for files" do
163
include FileServingMountTesting
166
FileTest.stubs(:exist?).returns(true)
167
FileTest.stubs(:directory?).returns(true)
168
FileTest.stubs(:readable?).returns(true)
169
@mount = Puppet::FileServing::Mount::File.new("test")
170
@mount.path = "/mount"
171
stub_facter("myhost.mydomain.com")
172
@host = "host.domain.com"
174
@request = stub 'request', :node => "foo"
177
it "should return the results of the complete file path as an array" do
178
FileTest.stubs(:exist?).returns(false)
179
@mount.expects(:complete_path).with("/my/path", "foo").returns "eh"
180
@mount.search("/my/path", @request).should == ["eh"]
183
it "should return nil if the complete path is nil" do
184
FileTest.stubs(:exist?).returns(false)
185
@mount.expects(:complete_path).with("/my/path", "foo").returns nil
186
@mount.search("/my/path", @request).should be_nil