File: tasks_spec.rb

package info (click to toggle)
puppet 5.5.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,316 kB
  • sloc: ruby: 254,925; sh: 1,608; xml: 219; makefile: 153; sql: 103
file content (71 lines) | stat: -rw-r--r-- 2,544 bytes parent folder | download | duplicates (3)
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
require 'spec_helper'
require 'puppet/file_serving/mount/tasks'

describe Puppet::FileServing::Mount::Tasks do
  before do
    @mount = Puppet::FileServing::Mount::Tasks.new("tasks")

    @environment = double('environment', :module => nil)
    @request = double('request', :environment => @environment)
  end

  describe "when finding task files" do
    it "should fail if no task is specified" do
      expect { @mount.find("", @request) }.to raise_error(/No task specified/)
    end

    it "should use the request's environment to find the module" do
      mod_name = 'foo'
      expect(@environment).to receive(:module).with(mod_name)

      @mount.find(mod_name, @request)
    end

    it "should use the first segment of the request's path as the module name" do
      expect(@environment).to receive(:module).with("foo")
      @mount.find("foo/bartask", @request)
    end

    it "should return nil if the module in the path doesn't exist" do
      expect(@environment).to receive(:module).with("foo").and_return(nil)
      expect(@mount.find("foo/bartask", @request)).to be_nil
    end

    it "should return the file path from the module" do
      mod = double('module')
      expect(mod).to receive(:task_file).with("bartask").and_return("mocked")
      expect(@environment).to receive(:module).with("foo").and_return(mod)
      expect(@mount.find("foo/bartask", @request)).to eq("mocked")
    end
  end

  describe "when searching for task files" do
    it "should fail if no module is specified" do
      expect { @mount.search("", @request) }.to raise_error(/No task specified/)
    end

    it "should use the request's environment to find the module" do
      mod_name = 'foo'
      expect(@environment).to receive(:module).with(mod_name)

      @mount.search(mod_name, @request)
    end

    it "should use the first segment of the request's path as the module name" do
      expect(@environment).to receive(:module).with("foo")
      @mount.search("foo/bartask", @request)
    end

    it "should return nil if the module in the path doesn't exist" do
      expect(@environment).to receive(:module).with("foo").and_return(nil)
      expect(@mount.search("foo/bartask", @request)).to be_nil
    end

    it "should return the file path from the module" do
      mod = double('module')
      expect(mod).to receive(:task_file).with("bartask").and_return("mocked")
      expect(@environment).to receive(:module).with("foo").and_return(mod)
      expect(@mount.search("foo/bartask", @request)).to eq(["mocked"])
    end
  end
end