summaryrefslogtreecommitdiffstats
path: root/spec/unit/indirector/memory.rb
blob: ac6f055ced781db201b92fd91993f16f1016b167 (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
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/indirector/memory'

describe "A Memory Terminus", :shared => true do
    it "should find no instances by default" do
        @searcher.find(@name).should be_nil
    end

    it "should be able to find instances that were previously saved" do
        @searcher.save(@instance)
        @searcher.find(@name).should equal(@instance)
    end

    it "should replace existing saved instances when a new instance with the same name is saved" do
        @searcher.save(@instance)
        two = stub 'second', :name => @name
        @searcher.save(two)
        @searcher.find(@name).should equal(two)
    end

    it "should be able to remove previously saved instances" do
        @searcher.save(@instance)
        @searcher.destroy(@instance)
        @searcher.find(@name).should be_nil
    end

    it "should fail when asked to destroy an instance that does not exist" do
        proc { @searcher.destroy(@instance) }.should raise_error(ArgumentError)
    end
end

describe Puppet::Indirector::Memory do
    it_should_behave_like "A Memory Terminus"

    before do
        Puppet::Indirector::Terminus.stubs(:register_terminus_class)
        @model = mock 'model'
        @indirection = stub 'indirection', :name => :mystuff, :register_terminus_type => nil, :model => @model
        Puppet::Indirector::Indirection.stubs(:instance).returns(@indirection)

        @memory_class = Class.new(Puppet::Indirector::Memory) do
            def self.to_s
                "Testing"
            end
        end

        @searcher = @memory_class.new
        @name = "me"
        @instance = stub 'instance', :name => @name
    end
end