summaryrefslogtreecommitdiffstats
path: root/spec/unit/indirector/facts
diff options
context:
space:
mode:
authorPieter van de Bruggen <pieter@puppetlabs.com>2011-04-18 13:40:31 -0700
committerPieter van de Bruggen <pieter@puppetlabs.com>2011-04-18 14:08:32 -0700
commit07b677c5f6af8def03c5c30393fd83bc3986239a (patch)
treeb28d3376b4ea835a2348ebfea898d674cb593e34 /spec/unit/indirector/facts
parentb142973a94ced6c0ff43da882189abe806c18c68 (diff)
downloadpuppet-07b677c5f6af8def03c5c30393fd83bc3986239a.tar.gz
puppet-07b677c5f6af8def03c5c30393fd83bc3986239a.tar.xz
puppet-07b677c5f6af8def03c5c30393fd83bc3986239a.zip
Merge remote-tracking branch 'community/feature/puppet-device' into 2.7.x
Reviewed-By: Mike Stahnke
Diffstat (limited to 'spec/unit/indirector/facts')
-rw-r--r--spec/unit/indirector/facts/network_device_spec.rb89
1 files changed, 89 insertions, 0 deletions
diff --git a/spec/unit/indirector/facts/network_device_spec.rb b/spec/unit/indirector/facts/network_device_spec.rb
new file mode 100644
index 000000000..302a810e8
--- /dev/null
+++ b/spec/unit/indirector/facts/network_device_spec.rb
@@ -0,0 +1,89 @@
+#!/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/network_device'
+
+describe Puppet::Node::Facts::NetworkDevice do
+ it "should be a subclass of the Code terminus" do
+ Puppet::Node::Facts::NetworkDevice.superclass.should equal(Puppet::Indirector::Code)
+ end
+
+ it "should have documentation" do
+ Puppet::Node::Facts::NetworkDevice.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::NetworkDevice.indirection.should equal(indirection)
+ end
+
+ it "should have its name set to :facter" do
+ Puppet::Node::Facts::NetworkDevice.name.should == :network_device
+ end
+end
+
+describe Puppet::Node::Facts::NetworkDevice do
+ before :each do
+ @remote_device = stub 'remote_device', :facts => {}
+ Puppet::Util::NetworkDevice.stubs(:current).returns(@remote_device)
+ @device = Puppet::Node::Facts::NetworkDevice.new
+ @name = "me"
+ @request = stub 'request', :key => @name
+ end
+
+ describe Puppet::Node::Facts::NetworkDevice, " when finding facts" do
+ it "should return a Facts instance" do
+ @device.find(@request).should be_instance_of(Puppet::Node::Facts)
+ end
+
+ it "should return a Facts instance with the provided key as the name" do
+ @device.find(@request).name.should == @name
+ end
+
+ it "should return the device facts as the values in the Facts instance" do
+ @remote_device.expects(:facts).returns("one" => "two")
+ facts = @device.find(@request)
+ facts.values["one"].should == "two"
+ end
+
+ it "should add local facts" do
+ facts = Puppet::Node::Facts.new("foo")
+ Puppet::Node::Facts.expects(:new).returns facts
+ facts.expects(:add_local_facts)
+
+ @device.find(@request)
+ end
+
+ it "should convert all facts into strings" do
+ facts = Puppet::Node::Facts.new("foo")
+ Puppet::Node::Facts.expects(:new).returns facts
+ facts.expects(:stringify)
+
+ @device.find(@request)
+ end
+
+ it "should call the downcase hook" do
+ facts = Puppet::Node::Facts.new("foo")
+ Puppet::Node::Facts.expects(:new).returns facts
+ facts.expects(:downcase_if_necessary)
+
+ @device.find(@request)
+ end
+ end
+
+ describe Puppet::Node::Facts::NetworkDevice, " when saving facts" do
+ it "should fail" do
+ proc { @device.save(@facts) }.should raise_error(Puppet::DevError)
+ end
+ end
+
+ describe Puppet::Node::Facts::NetworkDevice, " when destroying facts" do
+ it "should fail" do
+ proc { @device.destroy(@facts) }.should raise_error(Puppet::DevError)
+ end
+ end
+end