summaryrefslogtreecommitdiffstats
path: root/spec/integration/node_spec.rb
blob: 4ea6142e27daf571887ec1c93accc9f75421297d (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env rspec
#
#  Created by Luke Kanies on 2007-9-23.
#  Copyright (c) 2007. All rights reserved.

require 'spec_helper'

require 'puppet/node'

describe Puppet::Node do
  describe "when delegating indirection calls" do
    before do
      @name = "me"
      @node = Puppet::Node.new(@name)
    end

    it "should be able to use the exec terminus" do
      Puppet::Node.indirection.stubs(:terminus_class).returns :exec

      # Load now so we can stub
      terminus = Puppet::Node.indirection.terminus(:exec)

      terminus.expects(:query).with(@name).returns "myresults"
      terminus.expects(:translate).with(@name, "myresults").returns "translated_results"
      terminus.expects(:create_node).with(@name, "translated_results").returns @node

      Puppet::Node.indirection.find(@name).should equal(@node)
    end

    it "should be able to use the yaml terminus" do
      Puppet::Node.indirection.stubs(:terminus_class).returns :yaml

      # Load now, before we stub the exists? method.
      terminus = Puppet::Node.indirection.terminus(:yaml)

      terminus.expects(:path).with(@name).returns "/my/yaml/file"

      FileTest.expects(:exist?).with("/my/yaml/file").returns false
      Puppet::Node.indirection.find(@name).should be_nil
    end

    it "should have an ldap terminus" do
      Puppet::Node.indirection.terminus(:ldap).should_not be_nil
    end

    it "should be able to use the plain terminus", :'fails_on_ruby_1.9.2' => true do
      Puppet::Node.indirection.stubs(:terminus_class).returns :plain

      # Load now, before we stub the exists? method.
      Puppet::Node.indirection.terminus(:plain)

      Puppet::Node.expects(:new).with(@name).returns @node

      Puppet::Node.indirection.find(@name).should equal(@node)
    end

    describe "and using the memory terminus" do
      before do
        @name = "me"
        @old_terminus = Puppet::Node.indirection.terminus_class
        @terminus = Puppet::Node.indirection.terminus(:memory)
        Puppet::Node.indirection.stubs(:terminus).returns @terminus
        @node = Puppet::Node.new(@name)
      end

      it "should find no nodes by default" do
        Puppet::Node.indirection.find(@name).should be_nil
      end

      it "should be able to find nodes that were previously saved" do
        Puppet::Node.indirection.save(@node)
        Puppet::Node.indirection.find(@name).should equal(@node)
      end

      it "should replace existing saved nodes when a new node with the same name is saved" do
        Puppet::Node.indirection.save(@node)
        two = Puppet::Node.new(@name)
        Puppet::Node.indirection.save(two)
        Puppet::Node.indirection.find(@name).should equal(two)
      end

      it "should be able to remove previously saved nodes" do
        Puppet::Node.indirection.save(@node)
        Puppet::Node.indirection.destroy(@node.name)
        Puppet::Node.indirection.find(@name).should be_nil
      end

      it "should fail when asked to destroy a node that does not exist" do
        proc { Puppet::Node.indirection.destroy(@node) }.should raise_error(ArgumentError)
      end
    end
  end
end