1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#! /usr/bin/env ruby
require 'spec_helper'
require 'puppet/file_serving/mount/plugins'
describe Puppet::FileServing::Mount::Plugins do
before do
@mount = Puppet::FileServing::Mount::Plugins.new("plugins")
@environment = stub 'environment', :module => nil
@options = { :recurse => true }
@request = stub 'request', :environment => @environment, :options => @options
end
describe "when finding files" do
it "should use the provided environment to find the modules" do
@environment.expects(:modules).returns []
@mount.find("foo", @request)
end
it "should return nil if no module can be found with a matching plugin" do
mod = mock 'module'
mod.stubs(:plugin).with("foo/bar").returns nil
@environment.stubs(:modules).returns [mod]
@mount.find("foo/bar", @request).should be_nil
end
it "should return the file path from the module" do
mod = mock 'module'
mod.stubs(:plugin).with("foo/bar").returns "eh"
@environment.stubs(:modules).returns [mod]
@mount.find("foo/bar", @request).should == "eh"
end
end
describe "when searching for files" do
it "should use the node's environment to find the modules" do
@environment.expects(:modules).at_least_once.returns []
@environment.stubs(:modulepath).returns ["/tmp/modules"]
@mount.search("foo", @request)
end
it "should return modulepath if no modules can be found that have plugins" do
mod = mock 'module'
mod.stubs(:plugins?).returns false
@environment.stubs(:modules).returns []
@environment.stubs(:modulepath).returns ["/"]
@options.expects(:[]=).with(:recurse, false)
@mount.search("foo/bar", @request).should == ["/"]
end
it "should return nil if no modules can be found that have plugins and modulepath is invalid" do
mod = mock 'module'
mod.stubs(:plugins?).returns false
@environment.stubs(:modules).returns []
@environment.stubs(:modulepath).returns []
@mount.search("foo/bar", @request).should be_nil
end
it "should return the plugin paths for each module that has plugins" do
one = stub 'module', :plugins? => true, :plugin_directory => "/one"
two = stub 'module', :plugins? => true, :plugin_directory => "/two"
@environment.stubs(:modules).returns [one, two]
@mount.search("foo/bar", @request).should == %w{/one /two}
end
end
end
|