summaryrefslogtreecommitdiffstats
path: root/spec/unit/file_serving/mount/modules.rb
blob: 6861e94a5a1e49a417ad53c9d3bcba391daf49f2 (plain)
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
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/file_serving/mount/modules'

describe Puppet::FileServing::Mount::Modules, "when finding files" do
    before do
        @mount = Puppet::FileServing::Mount::Modules.new("modules")

        @environment = stub 'environment', :module => nil
        @mount.stubs(:environment).returns @environment
    end

    it "should use the node's environment to find the module" do
        env = mock 'env'
        @mount.expects(:environment).with("mynode").returns env
        env.expects(:module)

        @mount.find("foo", :node => "mynode")
    end

    it "should treat the first field of the relative path as the module name" do
        @environment.expects(:module).with("foo")
        @mount.find("foo/bar/baz")
    end

    it "should return nil if the specified module does not exist" do
        @environment.expects(:module).with("foo").returns nil
        @mount.find("foo/bar/baz")
    end

    it "should return the file path from the module" do
        mod = mock 'module'
        mod.expects(:file).with("bar/baz").returns "eh"
        @environment.expects(:module).with("foo").returns mod
        @mount.find("foo/bar/baz").should == "eh"
    end
end

describe Puppet::FileServing::Mount::Modules, "when searching for files" do
    before do
        @mount = Puppet::FileServing::Mount::Modules.new("modules")

        @environment = stub 'environment', :module => nil
        @mount.stubs(:environment).returns @environment
    end

    it "should use the node's environment to search the module" do
        env = mock 'env'
        @mount.expects(:environment).with("mynode").returns env
        env.expects(:module)

        @mount.search("foo", :node => "mynode")
    end

    it "should treat the first field of the relative path as the module name" do
        @environment.expects(:module).with("foo")
        @mount.search("foo/bar/baz")
    end

    it "should return nil if the specified module does not exist" do
        @environment.expects(:module).with("foo").returns nil
        @mount.search("foo/bar/baz")
    end

    it "should return the file path as an array from the module" do
        mod = mock 'module'
        mod.expects(:file).with("bar/baz").returns "eh"
        @environment.expects(:module).with("foo").returns mod
        @mount.search("foo/bar/baz").should == ["eh"]
    end
end