3 | 3 |
|
4 | 4 |
describe "Domain name facts" do
|
5 | 5 |
|
6 | |
{ :linux => {:kernel => "Linux", :hostname_command => "hostname -f"},
|
7 | |
:solaris => {:kernel => "SunOS", :hostname_command => "hostname"},
|
8 | |
:darwin => {:kernel => "Darwin", :hostname_command => "hostname -f"},
|
9 | |
:freebsd => {:kernel => "FreeBSD", :hostname_command => "hostname -f"},
|
10 | |
:hpux => {:kernel => "HP-UX", :hostname_command => "hostname"},
|
|
6 |
{ :linux => {:kernel => "Linux", :hostname_command => "hostname -f 2> /dev/null"},
|
|
7 |
:solaris => {:kernel => "SunOS", :hostname_command => "hostname 2> /dev/null"},
|
|
8 |
:darwin => {:kernel => "Darwin", :hostname_command => "hostname -f 2> /dev/null"},
|
|
9 |
:freebsd => {:kernel => "FreeBSD", :hostname_command => "hostname -f 2> /dev/null"},
|
|
10 |
:hpux => {:kernel => "HP-UX", :hostname_command => "hostname 2> /dev/null"},
|
11 | 11 |
}.each do |key, nested_hash|
|
12 | 12 |
|
13 | 13 |
describe "on #{key}" do
|
|
27 | 27 |
|
28 | 28 |
it "should fall back to the dnsdomainname binary" do
|
29 | 29 |
Facter::Util::Resolution.expects(:exec).with(hostname_command).returns("myhost")
|
30 | |
Facter::Util::Resolution.expects(:exec).with("dnsdomainname").returns("example.com")
|
|
30 |
Facter::Util::Resolution.expects(:exec).with("dnsdomainname 2> /dev/null").returns("example.com")
|
31 | 31 |
Facter.fact(:domain).value.should == "example.com"
|
32 | 32 |
end
|
33 | 33 |
|
34 | 34 |
|
35 | 35 |
it "should fall back to /etc/resolv.conf" do
|
36 | 36 |
Facter::Util::Resolution.expects(:exec).with(hostname_command).at_least_once.returns("myhost")
|
37 | |
Facter::Util::Resolution.expects(:exec).with("dnsdomainname").at_least_once.returns("")
|
|
37 |
Facter::Util::Resolution.expects(:exec).with("dnsdomainname 2> /dev/null").at_least_once.returns("")
|
38 | 38 |
File.expects(:open).with('/etc/resolv.conf').at_least_once
|
39 | 39 |
Facter.fact(:domain).value
|
40 | 40 |
end
|
|
42 | 42 |
it "should attempt to resolve facts in a specific order" do
|
43 | 43 |
seq = sequence('domain')
|
44 | 44 |
Facter::Util::Resolution.stubs(:exec).with(hostname_command).in_sequence(seq).at_least_once
|
45 | |
Facter::Util::Resolution.stubs(:exec).with("dnsdomainname").in_sequence(seq).at_least_once
|
|
45 |
Facter::Util::Resolution.stubs(:exec).with("dnsdomainname 2> /dev/null").in_sequence(seq).at_least_once
|
46 | 46 |
File.expects(:open).with('/etc/resolv.conf').in_sequence(seq).at_least_once
|
47 | 47 |
Facter.fact(:domain).value
|
48 | 48 |
end
|
|
50 | 50 |
describe "Top level domain" do
|
51 | 51 |
it "should find the domain name" do
|
52 | 52 |
Facter::Util::Resolution.expects(:exec).with(hostname_command).returns "ns01.tld"
|
53 | |
Facter::Util::Resolution.expects(:exec).with("dnsdomainname").never
|
|
53 |
Facter::Util::Resolution.expects(:exec).with("dnsdomainname 2> /dev/null").never
|
54 | 54 |
File.expects(:exists?).with('/etc/resolv.conf').never
|
55 | 55 |
Facter.fact(:domain).value.should == "tld"
|
56 | 56 |
end
|
|
59 | 59 |
describe "when using /etc/resolv.conf" do
|
60 | 60 |
before do
|
61 | 61 |
Facter::Util::Resolution.stubs(:exec).with(hostname_command)
|
62 | |
Facter::Util::Resolution.stubs(:exec).with("dnsdomainname")
|
|
62 |
Facter::Util::Resolution.stubs(:exec).with("dnsdomainname 2> /dev/null")
|
63 | 63 |
@mock_file = mock()
|
64 | 64 |
File.stubs(:open).with("/etc/resolv.conf").yields(@mock_file)
|
65 | 65 |
end
|
|
218 | 218 |
|
219 | 219 |
describe "scenarios" do
|
220 | 220 |
before(:each) do
|
221 | |
Facter::Util::Resolution.stubs(:exec).with("hostname -f").returns(scenario[:hostname])
|
222 | |
Facter::Util::Resolution.stubs(:exec).with("dnsdomainname").returns(scenario[:dnsdomainname])
|
|
221 |
Facter::Util::Resolution.stubs(:exec).with("hostname -f 2> /dev/null").returns(scenario[:hostname])
|
|
222 |
Facter::Util::Resolution.stubs(:exec).with("dnsdomainname 2> /dev/null").returns(scenario[:dnsdomainname])
|
223 | 223 |
@mock_file = mock()
|
224 | 224 |
File.stubs(:open).with("/etc/resolv.conf").yields(@mock_file)
|
225 | 225 |
lines = [
|