1
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
describe "Domain name facts" do
7
Facter.fact(:kernel).stubs(:value).returns("Linux")
8
FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(true)
11
it "should use the hostname binary" do
12
Facter::Util::Resolution.expects(:exec).with("hostname").returns "test.example.com"
13
Facter.fact(:domain).value.should == "example.com"
16
it "should fall back to the dnsdomainname binary" do
17
Facter::Util::Resolution.expects(:exec).with("hostname").returns("myhost")
18
Facter::Util::Resolution.expects(:exec).with("dnsdomainname").returns("example.com")
19
Facter.fact(:domain).value.should == "example.com"
23
it "should fall back to /etc/resolv.conf" do
24
Facter::Util::Resolution.expects(:exec).with("hostname").at_least_once.returns("myhost")
25
Facter::Util::Resolution.expects(:exec).with("dnsdomainname").at_least_once.returns("")
26
File.expects(:open).with('/etc/resolv.conf').at_least_once
27
Facter.fact(:domain).value
30
it "should attempt to resolve facts in a specific order" do
31
seq = sequence('domain')
32
Facter::Util::Resolution.stubs(:exec).with("hostname").in_sequence(seq).at_least_once
33
Facter::Util::Resolution.stubs(:exec).with("dnsdomainname").in_sequence(seq).at_least_once
34
File.expects(:open).with('/etc/resolv.conf').in_sequence(seq).at_least_once
35
Facter.fact(:domain).value
38
describe "when using /etc/resolv.conf" do
40
Facter::Util::Resolution.stubs(:exec).with("hostname")
41
Facter::Util::Resolution.stubs(:exec).with("dnsdomainname")
43
File.stubs(:open).with("/etc/resolv.conf").yields(@mock_file)
46
it "should use the domain field over the search field" do
52
@mock_file.expects(:each).multiple_yields(*lines)
53
Facter.fact(:domain).value.should == 'example.com'
56
it "should fall back to the search field" do
61
@mock_file.expects(:each).multiple_yields(*lines)
62
Facter.fact(:domain).value.should == 'example.org'
65
it "should use the first domain in the search field" do
67
"search example.org example.net",
69
@mock_file.expects(:each).multiple_yields(*lines)
70
Facter.fact(:domain).value.should == 'example.org'
75
describe "on Windows" do
76
it "should use the DNSDomain for the first nic where ip is enabled" do
77
Facter.fact(:kernel).stubs(:value).returns("windows")
80
nic.stubs(:DNSDomain).returns("foo.com")
83
nic2.stubs(:DNSDomain).returns("bar.com")
85
require 'facter/util/wmi'
86
Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns([nic, nic2])
88
Facter.fact(:domain).value.should == 'foo.com'