12
12
@object = Object.new
13
13
@object.extend(Puppet::FileServing::IndirectionHooks)
15
@request = stub 'request', :key => "http://myhost/blah", :options => {:node => "whatever"}
15
@request = stub 'request', :key => "mymod/myfile", :options => {:node => "whatever"}, :server => nil, :protocol => nil
18
18
describe "when being used to select termini" do
19
it "should escape the key before parsing" do
20
uri = stub 'uri', :scheme => "puppet", :host => "blah", :path => "/something"
21
URI.expects(:escape).with("http://myhost/blah").returns("escaped_blah")
22
URI.expects(:parse).with("escaped_blah").returns(uri)
23
@object.select_terminus(@request)
26
it "should use the URI class to parse the key" do
27
uri = stub 'uri', :scheme => "puppet", :host => "blah", :path => "/something"
28
URI.expects(:parse).with("http://myhost/blah").returns(uri)
29
@object.select_terminus @request
32
it "should choose :rest when the protocol is 'puppet'" do
33
@request.stubs(:key).returns "puppet://host/module/file"
34
@object.select_terminus(@request).should == :rest
37
it "should choose :file_server when the protocol is 'puppetmounts' and the mount name is not 'modules'" do
38
modules = mock 'modules'
39
@object.stubs(:terminus).with(:modules).returns(modules)
40
modules.stubs(:find_module).returns(nil)
42
@request.stubs(:key).returns "puppetmounts://host/notmodules/file"
44
@object.select_terminus(@request).should == :file_server
47
it "should choose :file_server when no server name is provided, the process name is 'puppet', and the mount name is not 'modules'" do
48
modules = mock 'modules'
49
@object.stubs(:terminus).with(:modules).returns(modules)
50
modules.stubs(:find_module).returns(nil)
52
Puppet.settings.expects(:value).with(:name).returns("puppet")
53
@request.stubs(:key).returns "puppet:///notmodules/file"
54
@object.select_terminus(@request).should == :file_server
57
it "should choose :modules if it would normally choose :file_server but the mount name is 'modules'" do
58
@request.stubs(:key).returns "puppetmounts://host/modules/mymod/file"
59
@object.select_terminus(@request).should == :modules
62
it "should choose :modules if it would normally choose :file_server but a module exists with the mount name" do
63
modules = mock 'modules'
65
@object.expects(:terminus).with(:modules).returns(modules)
66
modules.expects(:find_module).with("mymod", @request.options[:node]).returns(:thing)
68
@request.stubs(:key).returns "puppetmounts://host/mymod/file"
69
@object.select_terminus(@request).should == :modules
72
it "should choose :rest when no server name is provided and the process name is not 'puppet'" do
73
Puppet.settings.expects(:value).with(:name).returns("puppetd")
74
@request.stubs(:key).returns "puppet:///module/file"
75
@object.select_terminus(@request).should == :rest
78
it "should choose :file when the protocol is 'file'" do
79
@request.stubs(:key).returns "file://host/module/file"
80
@object.select_terminus(@request).should == :file
83
it "should choose :file when the URI is a normal path name" do
84
@request.stubs(:key).returns "/module/file"
85
@object.select_terminus(@request).should == :file
88
# This is so that we only choose modules over mounts, not file
89
it "should choose :file when the protocol is 'file' and the fully qualified path starts with '/modules'" do
90
@request.stubs(:key).returns "/module/file"
91
@object.select_terminus(@request).should == :file
94
it "should fail when a protocol other than :puppet, :file, or :puppetmounts is used" do
95
@request.stubs(:key).returns "http:///module/file"
19
it "should return :file if the request key is fully qualified" do
20
@request.expects(:key).returns "#{File::SEPARATOR}foo"
21
@object.select_terminus(@request).should == :file
24
it "should return :file if the URI protocol is set to 'file'" do
25
@request.expects(:protocol).returns "file"
26
@object.select_terminus(@request).should == :file
29
it "should fail when a protocol other than :puppet or :file is used" do
30
@request.stubs(:protocol).returns "http"
96
31
proc { @object.select_terminus(@request) }.should raise_error(ArgumentError)
100
describe "when looking for a module whose name matches the mount name" do
102
@modules = mock 'modules'
103
@object.stubs(:terminus).with(:modules).returns(@modules)
105
@request.stubs(:key).returns "puppetmounts://host/mymod/file"
108
it "should use the modules terminus to look up the module" do
109
@modules.expects(:find_module).with("mymod", @request.options[:node])
110
@object.select_terminus @request
113
it "should pass the node name to the modules terminus" do
114
@modules.expects(:find_module).with("mymod", @request.options[:node])
115
@object.select_terminus @request
118
it "should log a deprecation warning if a module is found" do
119
@modules.expects(:find_module).with("mymod", @request.options[:node]).returns(:something)
120
Puppet.expects(:warning)
121
@object.select_terminus @request
34
describe "and the protocol is 'puppet'" do
36
@request.stubs(:protocol).returns "puppet"
39
it "should choose :rest when a server is specified" do
40
@request.stubs(:protocol).returns "puppet"
41
@request.expects(:server).returns "foo"
42
@object.select_terminus(@request).should == :rest
45
# This is so a given file location works when bootstrapping with no server.
46
it "should choose :rest when the Settings name isn't 'puppet'" do
47
@request.stubs(:protocol).returns "puppet"
48
@request.stubs(:server).returns "foo"
49
Puppet.settings.stubs(:value).with(:name).returns "foo"
50
@object.select_terminus(@request).should == :rest
53
it "should choose :file_server when the settings name is 'puppet' and no server is specified" do
54
modules = mock 'modules'
56
@request.expects(:protocol).returns "puppet"
57
@request.expects(:server).returns nil
58
Puppet.settings.expects(:value).with(:name).returns "puppet"
59
@object.select_terminus(@request).should == :file_server