summaryrefslogtreecommitdiffstats
path: root/spec/unit/indirector/facts/facter.rb
blob: e8ea721d31dff3560b17fc39b210b4d3a5eefbd6 (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
#!/usr/bin/env ruby
#
#  Created by Luke Kanies on 2007-9-23.
#  Copyright (c) 2007. All rights reserved.

require File.dirname(__FILE__) + '/../../../spec_helper'

require 'puppet/indirector/facts/facter'

describe Puppet::Node::Facts::Facter do
    it "should be a subclass of the Code terminus" do
        Puppet::Node::Facts::Facter.superclass.should equal(Puppet::Indirector::Code)
    end

    it "should have documentation" do
        Puppet::Node::Facts::Facter.doc.should_not be_nil
    end

    it "should be registered with the configuration store indirection" do
        indirection = Puppet::Indirector::Indirection.instance(:facts)
        Puppet::Node::Facts::Facter.indirection.should equal(indirection)
    end

    it "should have its name set to :facter" do
        Puppet::Node::Facts::Facter.name.should == :facter
    end
end

module TestingCodeFacts
    def setup
        @facter = Puppet::Node::Facts::Facter.new
        Facter.stubs(:to_hash).returns({})
        @name = "me"
        @facts = @facter.find(@name)
    end
end

describe Puppet::Node::Facts::Facter, " when finding facts" do
    include TestingCodeFacts

    it "should return a Facts instance" do
        @facts.should be_instance_of(Puppet::Node::Facts)
    end

    it "should return a Facts instance with the provided key as the name" do
        @facts.name.should == @name
    end

    it "should return the Facter facts as the values in the Facts instance" do
        Facter.expects(:to_hash).returns("one" => "two")
        facts = @facter.find(@name)
        facts.values["one"].should == "two"
    end
end

describe Puppet::Node::Facts::Facter, " when saving facts" do
    include TestingCodeFacts

    it "should fail" do
        proc { @facter.save(@facts) }.should raise_error(Puppet::DevError)
    end
end

describe Puppet::Node::Facts::Facter, " when destroying facts" do
    include TestingCodeFacts

    it "should fail" do
        proc { @facter.destroy(@facts) }.should raise_error(Puppet::DevError)
    end
end