3
# Created by Luke Kanies on 2007-9-23.
4
# Copyright (c) 2007. All rights reserved.
6
require File.dirname(__FILE__) + '/../../../spec_helper'
8
require 'puppet/indirector/facts/network_device'
10
describe Puppet::Node::Facts::NetworkDevice do
11
it "should be a subclass of the Code terminus" do
12
Puppet::Node::Facts::NetworkDevice.superclass.should equal(Puppet::Indirector::Code)
15
it "should have documentation" do
16
Puppet::Node::Facts::NetworkDevice.doc.should_not be_nil
19
it "should be registered with the configuration store indirection" do
20
indirection = Puppet::Indirector::Indirection.instance(:facts)
21
Puppet::Node::Facts::NetworkDevice.indirection.should equal(indirection)
24
it "should have its name set to :facter" do
25
Puppet::Node::Facts::NetworkDevice.name.should == :network_device
29
describe Puppet::Node::Facts::NetworkDevice do
31
@remote_device = stub 'remote_device', :facts => {}
32
Puppet::Util::NetworkDevice.stubs(:current).returns(@remote_device)
33
@device = Puppet::Node::Facts::NetworkDevice.new
35
@request = stub 'request', :key => @name
38
describe Puppet::Node::Facts::NetworkDevice, " when finding facts" do
39
it "should return a Facts instance" do
40
@device.find(@request).should be_instance_of(Puppet::Node::Facts)
43
it "should return a Facts instance with the provided key as the name" do
44
@device.find(@request).name.should == @name
47
it "should return the device facts as the values in the Facts instance" do
48
@remote_device.expects(:facts).returns("one" => "two")
49
facts = @device.find(@request)
50
facts.values["one"].should == "two"
53
it "should add local facts" do
54
facts = Puppet::Node::Facts.new("foo")
55
Puppet::Node::Facts.expects(:new).returns facts
56
facts.expects(:add_local_facts)
58
@device.find(@request)
61
it "should convert all facts into strings" do
62
facts = Puppet::Node::Facts.new("foo")
63
Puppet::Node::Facts.expects(:new).returns facts
64
facts.expects(:stringify)
66
@device.find(@request)
69
it "should call the downcase hook" do
70
facts = Puppet::Node::Facts.new("foo")
71
Puppet::Node::Facts.expects(:new).returns facts
72
facts.expects(:downcase_if_necessary)
74
@device.find(@request)
78
describe Puppet::Node::Facts::NetworkDevice, " when saving facts" do
80
proc { @device.save(@facts) }.should raise_error(Puppet::DevError)
84
describe Puppet::Node::Facts::NetworkDevice, " when destroying facts" do
86
proc { @device.destroy(@facts) }.should raise_error(Puppet::DevError)