Sha256: 173a33ab61c60f6cdacaf4aa018b4e28439a2b97d3dcbd7ea64ffc4f707b41f5

Contents?: true

Size: 1.22 KB

Versions: 26

Compression:

Stored size: 1.22 KB

Contents

#! /usr/bin/env ruby

require 'spec_helper'

describe "Hostname facts" do

  describe "on linux" do
    before do
      Facter.fact(:kernel).stubs(:value).returns("Linux")
      Facter.fact(:kernelrelease).stubs(:value).returns("2.6")
    end

    it "should use the hostname command" do
      Facter::Util::Resolution.expects(:exec).with('hostname').at_least_once
      Facter.fact(:hostname).value.should be_nil
    end

    it "should use hostname as the fact if unqualified" do
      Facter::Util::Resolution.stubs(:exec).with('hostname').returns('host1')
      Facter.fact(:hostname).value.should == "host1"
    end

    it "should truncate the domain name if qualified" do
      Facter::Util::Resolution.stubs(:exec).with('hostname').returns('host1.example.com')
      Facter.fact(:hostname).value.should == "host1"
    end
  end

  describe "on darwin release R7" do
    before do
      Facter.fact(:kernel).stubs(:value).returns("Darwin")
      Facter.fact(:kernelrelease).stubs(:value).returns("R7")
    end

    it "should use scutil to get the hostname" do
      Facter::Util::Resolution.expects(:exec).with('/usr/sbin/scutil --get LocalHostName').returns("host1")
      Facter.fact(:hostname).value.should == "host1"
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
facter-1.7.6 spec/unit/hostname_spec.rb
facter-1.7.5 spec/unit/hostname_spec.rb
facter-1.7.5.rc2 spec/unit/hostname_spec.rb
facter-1.7.5.rc1 spec/unit/hostname_spec.rb
facter-1.7.4 spec/unit/hostname_spec.rb
facter-1.7.4.rc1 spec/unit/hostname_spec.rb
facter-1.7.3 spec/unit/hostname_spec.rb
facter-1.7.3.rc1 spec/unit/hostname_spec.rb
facter-1.7.2 spec/unit/hostname_spec.rb
facter-1.7.2.rc1 spec/unit/hostname_spec.rb
facter-1.7.1 spec/unit/hostname_spec.rb
facter-1.7.1.rc1 spec/unit/hostname_spec.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/facter-1.6.17/spec/unit/hostname_spec.rb
facter-1.7.0 spec/unit/hostname_spec.rb
facter-1.7.0.rc2 spec/unit/hostname_spec.rb
facter-1.7.0.rc1 spec/unit/hostname_spec.rb
facter-1.6.18 spec/unit/hostname_spec.rb
facter-1.6.18.rc1 spec/unit/hostname_spec.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/facter-1.6.17/spec/unit/hostname_spec.rb
facter-1.6.17 spec/unit/hostname_spec.rb