File: terminus_selector_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 (65 lines) | stat: -rw-r--r-- 2,536 bytes parent folder | download
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
require 'spec_helper'

require 'puppet/file_serving/terminus_selector'

describe Puppet::FileServing::TerminusSelector do
  before do
    @object = Object.new
    @object.extend(Puppet::FileServing::TerminusSelector)

    @request = double('request', :key => "mymod/myfile", :options => {:node => "whatever"}, :server => nil, :protocol => nil)
  end

  describe "when being used to select termini" do
    it "should return :file if the request key is fully qualified" do
      expect(@request).to receive(:key).and_return(File.expand_path('/foo'))
      expect(@object.select(@request)).to eq(:file)
    end

    it "should return :file if the URI protocol is set to 'file'" do
      expect(@request).to receive(:protocol).and_return("file")
      expect(@object.select(@request)).to eq(:file)
    end

    it "should return :http if the URI protocol is set to 'http'" do
      expect(@request).to receive(:protocol).and_return("http")
      expect(@object.select(@request)).to eq :http
    end

    it "should return :http if the URI protocol is set to 'https'" do
      expect(@request).to receive(:protocol).and_return("https")
      expect(@object.select(@request)).to eq :http
    end

    it "should fail when a protocol other than :puppet, :http(s) or :file is used" do
      allow(@request).to receive(:protocol).and_return("ftp")
      expect { @object.select(@request) }.to raise_error(ArgumentError)
    end

    describe "and the protocol is 'puppet'" do
      before do
        allow(@request).to receive(:protocol).and_return("puppet")
      end

      it "should choose :rest when a server is specified" do
        allow(@request).to receive(:protocol).and_return("puppet")
        expect(@request).to receive(:server).and_return("foo")
        expect(@object.select(@request)).to eq(:rest)
      end

      # This is so a given file location works when bootstrapping with no server.
      it "should choose :rest when default_file_terminus is rest" do
        allow(@request).to receive(:protocol).and_return("puppet")
        Puppet[:server] = 'localhost'
        expect(@object.select(@request)).to eq(:rest)
      end

      it "should choose :file_server when default_file_terminus is file_server and no server is specified on the request" do
        expect(@request).to receive(:protocol).and_return("puppet")
        expect(@request).to receive(:server).and_return(nil)
        Puppet[:default_file_terminus] = 'file_server'
        expect(@object.select(@request)).to eq(:file_server)
      end
    end
  end
end