Sha256: 6d731995ce57db730d4a29caf7920ec503d057d1ce715a0cb6840d87a5f9c7eb

Contents?: true

Size: 1.83 KB

Versions: 12

Compression:

Stored size: 1.83 KB

Contents

#!/usr/bin/env rspec

require 'spec_helper'

def ifconfig_fixture(filename)
  File.read(fixtures('ifconfig', filename))
end

def netsh_fixture(filename)
  File.read(fixtures('netsh', filename))
end

describe "macaddress fact" do
  before do
    Facter::Util::Config.stubs(:is_windows?).returns(false)
  end

  describe "when run on Linux" do
    before :each do
      Facter.fact(:kernel).stubs(:value).returns("Linux")
      Facter.fact(:operatingsystem).stubs(:value).returns("Linux")
    end

    it "should return the macaddress of the first interface" do
      Facter::Util::Resolution.stubs(:exec).with('/sbin/ifconfig -a').
        returns(ifconfig_fixture('linux_ifconfig_all_with_multiple_interfaces'))

      Facter.value(:macaddress).should == "00:12:3f:be:22:01"
    end

    it "should return nil when no macaddress can be found" do
      Facter::Util::Resolution.stubs(:exec).with('/sbin/ifconfig -a').
        returns(ifconfig_fixture('linux_ifconfig_no_mac'))

      proc { Facter.value(:macaddress) }.should_not raise_error
      Facter.value(:macaddress).should be_nil
    end

    # some interfaces dont have a real mac addresses (like venet inside a container)
    it "should return nil when no interface has a real macaddress" do
      Facter::Util::Resolution.stubs(:exec).with('/sbin/ifconfig -a').
        returns(ifconfig_fixture('linux_ifconfig_venet'))

      proc { Facter.value(:macaddress) }.should_not raise_error
      Facter.value(:macaddress).should be_nil
    end
  end

  describe "when run on BSD" do
    it "should return macaddress information" do
      Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
      Facter::Util::Resolution.stubs(:exec).with('/sbin/ifconfig').
        returns(ifconfig_fixture('bsd_ifconfig_all_with_multiple_interfaces'))

      Facter.value(:macaddress).should == "00:0b:db:93:09:67"
    end
  end

end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
facter-1.6.12 spec/unit/macaddress_spec.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/facter-1.6.11/spec/unit/macaddress_spec.rb
facter-1.6.12.rc2 spec/unit/macaddress_spec.rb
facter-1.6.12.rc1 spec/unit/macaddress_spec.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/facter-1.6.11/spec/unit/macaddress_spec.rb
facter-1.6.11 spec/unit/macaddress_spec.rb
facter-1.6.10 spec/unit/macaddress_spec.rb
facter-1.6.9 spec/unit/macaddress_spec.rb
facter-1.6.8 spec/unit/macaddress_spec.rb
facter-1.6.7 spec/unit/macaddress_spec.rb
facter-1.6.6 spec/unit/macaddress_spec.rb
facter-1.6.5 spec/unit/macaddress_spec.rb