3
3
require File.dirname(__FILE__) + '/../../spec_helper'
4
4
require 'puppet/file_serving/mount'
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(/^[^.]+\./, ''))
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]"
26
17
it "should allow dashes in its name" do
27
18
Puppet::FileServing::Mount.new("non-alpha").name.should == "non-alpha"
30
it "should allow an optional path" do
31
Puppet::FileServing::Mount.new("name", "/").path.should == "/"
35
describe Puppet::FileServing::Mount, " when setting the path" do
37
@mount = Puppet::FileServing::Mount.new("test")
38
@dir = "/this/path/does/not/exist"
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)
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)
53
22
describe Puppet::FileServing::Mount, " when finding files" do
54
include FileServingMountTesting
57
FileTest.stubs(:directory?).returns(true)
58
FileTest.stubs(:readable?).returns(true)
59
@mount = Puppet::FileServing::Mount.new("test")
60
@host = "host.domain.com"
63
it "should fail if the mount path has not been set" do
64
proc { @mount.file_path("/blah") }.should raise_error(ArgumentError)
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"
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"
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"
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"
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"
92
it "should not perform replacements on the per-file path" do
94
@mount.file_path("/%h/stuff", @host).should == "/blah/%h/stuff"
97
it "should look for files relative to its base directory" do
99
@mount.file_path("/my/stuff", @host).should == "/blah/my/stuff"
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"
109
Puppet::FileServing::Mount.clear_cache
24
lambda { Puppet::FileServing::Mount.new("test").find("foo", :one => "two") }.should raise_error(NotImplementedError)
113
describe Puppet::FileServing::Mount, " when providing file paths" do
114
include FileServingMountTesting
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"
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
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"
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"
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
30
lambda { Puppet::FileServing::Mount.new("test").search("foo", :one => "two") }.should raise_error(NotImplementedError)