summaryrefslogtreecommitdiffstats
path: root/spec/unit/type/filebucket_spec.rb
blob: 3c5311184530498932331f5c84991c2a44ffa7f8 (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
73
#!/usr/bin/env rspec
require 'spec_helper'

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

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

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

  it "should use the masterport as the path by default port" do
    Puppet.settings[:masterport] = 50
    Puppet::Type.type(:filebucket).new(:name => "main")[:port].should == Puppet[:masterport]
  end

  it "should use the server as the path by default server" do
    Puppet.settings[:server] = "myserver"
    Puppet::Type.type(:filebucket).new(:name => "main")[:server].should == Puppet[:server]
  end

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

    bucket.bucket.should be_local
  end

  it "not be local if path is false" do
    bucket = Puppet::Type.type(:filebucket).new :name => "main", :path => false

    bucket.bucket.should_not be_local
  end

  it "be local if both a path and a server are specified" do
    bucket = Puppet::Type.type(:filebucket).new :name => "main", :server => "puppet", :path => "/my/path"

    bucket.bucket.should be_local
  end

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

    it "should use any provided path" do
      bucket = Puppet::Type.type(:filebucket).new :name => "main", :path => "/foo/bar"
      Puppet::FileBucket::Dipper.expects(:new).with(:Path => "/foo/bar").returns @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
      Puppet::FileBucket::Dipper.expects(:new).with(:Server => "myserv", :Port => "myport").returns @bucket
      bucket.bucket
    end

    it "should use the default server if the path is unset and no server is provided" do
      Puppet.settings[:server] = "myserv"
      bucket = Puppet::Type.type(:filebucket).new :name => "main", :path => false
      Puppet::FileBucket::Dipper.expects(:new).with { |args| args[:Server] == "myserv" }.returns @bucket
      bucket.bucket
    end
  end
end