~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to spec/unit/indirector/facts/network_device_spec.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-07-25 01:00:37 UTC
  • mfrom: (1.1.24 upstream) (3.1.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110725010037-875vuxs10eboqgw3
Tags: 2.7.1-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/puppetmaster-passenger.postinst: Use cacrl instead of hostcrl to
    set the location of the CRL in apache2 configuration. Fix apache2
    configuration on upgrade as well (LP: #641001)
  - move all puppet dependencies to puppet-common since all the code
    actually located in puppet-common.
  - move libagueas from a recommend to a dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
#
 
3
#  Created by Luke Kanies on 2007-9-23.
 
4
#  Copyright (c) 2007. All rights reserved.
 
5
 
 
6
require File.dirname(__FILE__) + '/../../../spec_helper'
 
7
 
 
8
require 'puppet/indirector/facts/network_device'
 
9
 
 
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)
 
13
  end
 
14
 
 
15
  it "should have documentation" do
 
16
    Puppet::Node::Facts::NetworkDevice.doc.should_not be_nil
 
17
  end
 
18
 
 
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)
 
22
  end
 
23
 
 
24
  it "should have its name set to :facter" do
 
25
    Puppet::Node::Facts::NetworkDevice.name.should == :network_device
 
26
  end
 
27
end
 
28
 
 
29
describe Puppet::Node::Facts::NetworkDevice do
 
30
  before :each do
 
31
    @remote_device = stub 'remote_device', :facts => {}
 
32
    Puppet::Util::NetworkDevice.stubs(:current).returns(@remote_device)
 
33
    @device = Puppet::Node::Facts::NetworkDevice.new
 
34
    @name = "me"
 
35
    @request = stub 'request', :key => @name
 
36
  end
 
37
 
 
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)
 
41
    end
 
42
 
 
43
    it "should return a Facts instance with the provided key as the name" do
 
44
      @device.find(@request).name.should == @name
 
45
    end
 
46
 
 
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"
 
51
    end
 
52
 
 
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)
 
57
 
 
58
      @device.find(@request)
 
59
    end
 
60
 
 
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)
 
65
 
 
66
      @device.find(@request)
 
67
    end
 
68
 
 
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)
 
73
 
 
74
      @device.find(@request)
 
75
    end
 
76
  end
 
77
 
 
78
  describe Puppet::Node::Facts::NetworkDevice, " when saving facts" do
 
79
    it "should fail" do
 
80
      proc { @device.save(@facts) }.should raise_error(Puppet::DevError)
 
81
    end
 
82
  end
 
83
 
 
84
  describe Puppet::Node::Facts::NetworkDevice, " when destroying facts" do
 
85
    it "should fail" do
 
86
      proc { @device.destroy(@facts) }.should raise_error(Puppet::DevError)
 
87
    end
 
88
  end
 
89
end