File: filebucket_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 (104 lines) | stat: -rw-r--r-- 3,585 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require 'spec_helper'

describe Puppet::Type.type(:filebucket) do
  include PuppetSpec::Files

  describe "when validating attributes" do
    %w{name server port path}.each do |attr|
      it "should have a '#{attr}' parameter" do
        expect(Puppet::Type.type(:filebucket).attrtype(attr.intern)).to eq(:param)
      end
    end

    it "should have its 'name' attribute set as its namevar" do
      expect(Puppet::Type.type(:filebucket).key_attributes).to eq([:name])
    end
  end

  it "should use the clientbucketdir as the path by default path" do
    Puppet.settings[:clientbucketdir] = "/my/bucket"
    expect(Puppet::Type.type(:filebucket).new(:name => "main")[:path]).to eq(Puppet[:clientbucketdir])
  end

  it "should not have a default port" do
    Puppet.settings[:masterport] = 50
    expect(Puppet::Type.type(:filebucket).new(:name => "main")[:port]).to eq(nil)
  end

  it "should not have a default server" do
    Puppet.settings[:server] = "myserver"
    expect(Puppet::Type.type(:filebucket).new(:name => "main")[:server]).to eq(nil)
  end

  it "be local by default" do
    bucket = Puppet::Type.type(:filebucket).new :name => "main"

    expect(bucket.bucket).to be_local
  end

  describe "path" do
    def bucket(hash)
      Puppet::Type.type(:filebucket).new({:name => 'main'}.merge(hash))
    end

    it "should accept false as a value" do
      expect { bucket(:path => false) }.not_to raise_error
    end

    it "should accept true as a value" do
      expect { bucket(:path => true) }.not_to raise_error
    end

    it "should fail when given an array of values" do
      expect { bucket(:path => ['one', 'two']) }.
        to raise_error Puppet::Error, /only have one filebucket path/
    end

    %w{one ../one one/two}.each do |path|
      it "should fail if given a relative path of #{path.inspect}" do
        expect { bucket(:path => path) }.
          to raise_error Puppet::Error, /Filebucket paths must be absolute/
      end
    end

    it "should succeed if given an absolute path" do
      expect { bucket(:path => make_absolute('/tmp/bucket')) }.not_to raise_error
    end

    it "not be local if path is false" do
      expect(bucket(:path => false).bucket).not_to be_local
    end

    it "be local if both a path and a server are specified" do
      expect(bucket(:server => "puppet", :path => make_absolute("/my/path")).bucket).to be_local
    end
  end

  describe "when creating the filebucket" do
    before do
      @bucket = double('bucket', :name= => nil)
    end

    it "should use any provided path" do
      path = make_absolute("/foo/bar")
      bucket = Puppet::Type.type(:filebucket).new :name => "main", :path => path
      expect(Puppet::FileBucket::Dipper).to receive(:new).with(:Path => path).and_return(@bucket)
      bucket.bucket
    end

    it "should use any provided server and port" do
      bucket = Puppet::Type.type(:filebucket).new :name => "main", :server => "myserv", :port => "myport", :path => false
      expect(Puppet::FileBucket::Dipper).to receive(:new).with(:Server => "myserv", :Port => "myport").and_return(@bucket)
      bucket.bucket
    end

    it "should not try to guess server or port if the path is unset and no server is provided" do
      Puppet.settings[:server] = "myserv"
      Puppet.settings[:server_list] = ['server_list_0', 'server_list_1']
      expect(Puppet::FileBucket::Dipper).to receive(:new).with(:Server => nil, :Port => nil).and_return(@bucket)

      bucket = Puppet::Type.type(:filebucket).new :name => "main", :path => false
      bucket.bucket
    end
  end
end