15 | 15 |
Facter.fact(:kernel).stubs(:value).returns(nested_hash[:kernel])
|
16 | 16 |
FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(true)
|
17 | 17 |
end
|
18 | |
|
19 | |
let :hostname_command do
|
|
18 |
|
|
19 |
let :hostname_command do
|
20 | 20 |
nested_hash[:hostname_command]
|
21 | |
end
|
22 | |
|
|
21 |
end
|
|
22 |
|
23 | 23 |
it "should use the hostname binary" do
|
24 | 24 |
Facter::Util::Resolution.expects(:exec).with(hostname_command).returns "test.example.com"
|
25 | 25 |
Facter.fact(:domain).value.should == "example.com"
|
26 | 26 |
end
|
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 | 30 |
Facter::Util::Resolution.expects(:exec).with("dnsdomainname").returns("example.com")
|
31 | 31 |
Facter.fact(:domain).value.should == "example.com"
|
32 | 32 |
end
|
33 | |
|
34 | |
|
|
33 |
|
|
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 | 37 |
Facter::Util::Resolution.expects(:exec).with("dnsdomainname").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
|
41 | |
|
|
41 |
|
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
|
|
46 | 46 |
File.expects(:open).with('/etc/resolv.conf').in_sequence(seq).at_least_once
|
47 | 47 |
Facter.fact(:domain).value
|
48 | 48 |
end
|
49 | |
|
50 | |
describe "Top level domain" do
|
|
49 |
|
|
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 | 53 |
Facter::Util::Resolution.expects(:exec).with("dnsdomainname").never
|
54 | 54 |
File.expects(:exists?).with('/etc/resolv.conf').never
|
55 | |
Facter.fact(:domain).value.should == "tld"
|
56 | |
end
|
57 | |
end
|
58 | |
|
|
55 |
Facter.fact(:domain).value.should == "tld"
|
|
56 |
end
|
|
57 |
end
|
|
58 |
|
59 | 59 |
describe "when using /etc/resolv.conf" do
|
60 | 60 |
before do
|
61 | 61 |
Facter::Util::Resolution.stubs(:exec).with(hostname_command)
|
|
63 | 63 |
@mock_file = mock()
|
64 | 64 |
File.stubs(:open).with("/etc/resolv.conf").yields(@mock_file)
|
65 | 65 |
end
|
66 | |
|
|
66 |
|
67 | 67 |
it "should use the domain field over the search field" do
|
68 | 68 |
lines = [
|
69 | 69 |
"nameserver 4.2.2.1",
|
|
82 | 82 |
@mock_file.expects(:each).multiple_yields(*lines)
|
83 | 83 |
Facter.fact(:domain).value.should == 'example.org'
|
84 | 84 |
end
|
85 | |
|
|
85 |
|
86 | 86 |
it "should use the first domain in the search field" do
|
87 | 87 |
lines = [
|
88 | 88 |
"search example.org example.net",
|
|
90 | 90 |
@mock_file.expects(:each).multiple_yields(*lines)
|
91 | 91 |
Facter.fact(:domain).value.should == 'example.org'
|
92 | 92 |
end
|
93 | |
|
|
93 |
|
94 | 94 |
# Test permutations of domain and search, where 'domain' can be a value of
|
95 | 95 |
# the search keyword and the domain keyword
|
96 | 96 |
# and also where 'search' can be a value of the search keyword and the
|
|
128 | 128 |
end
|
129 | 129 |
end
|
130 | 130 |
end
|
131 | |
end
|
|
131 |
end
|
132 | 132 |
|
133 | 133 |
describe "on Windows" do
|
134 | 134 |
before(:each) do
|
|
172 | 172 |
end
|
173 | 173 |
end
|
174 | 174 |
|
175 | |
describe "with trailing dots" do
|
176 | |
describe "on Windows" do
|
|
175 |
describe "with trailing dots" do
|
|
176 |
describe "on Windows" do
|
177 | 177 |
before do
|
178 | 178 |
Facter.fact(:kernel).stubs(:value).returns("windows")
|
179 | 179 |
require 'facter/util/registry'
|
180 | 180 |
require 'facter/util/wmi'
|
181 | 181 |
end
|
182 | |
|
|
182 |
|
183 | 183 |
[{:registry => 'testdomain.', :wmi => '', :expect => 'testdomain'},
|
184 | 184 |
{:registry => '', :wmi => 'testdomain.', :expect => 'testdomain'},
|
185 | 185 |
].each do |scenario|
|
186 | 186 |
|
187 | |
describe "scenarios" do
|
|
187 |
describe "scenarios" do
|
188 | 188 |
before(:each) do
|
189 | 189 |
Facter::Util::Registry.stubs(:hklm_read).returns(scenario[:registry])
|
190 | 190 |
nic = stubs 'nic'
|
191 | 191 |
nic.stubs(:DNSDomain).returns(scenario[:wmi])
|
192 | 192 |
Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns([nic])
|
193 | 193 |
end
|
194 | |
|
|
194 |
|
195 | 195 |
it "should return #{scenario[:expect]}" do
|
196 | 196 |
Facter.fact(:domain).value.should == scenario[:expect]
|
197 | 197 |
end
|
198 | |
|
|
198 |
|
199 | 199 |
it "should remove trailing dots" do
|
200 | 200 |
Facter.fact(:domain).value.should_not =~ /\.$/
|
201 | 201 |
end
|
202 | |
end
|
203 | |
end
|
|
202 |
end
|
|
203 |
end
|
204 | 204 |
end
|
205 | 205 |
|
206 | 206 |
describe "on everything else" do
|
|
212 | 212 |
[{:hostname => 'host.testdomain.', :dnsdomainname => '', :resolve_domain => '', :resolve_search => '', :expect => 'testdomain'},
|
213 | 213 |
{:hostname => '', :dnsdomainname => 'testdomain.', :resolve_domain => '', :resolve_search => '', :expect => 'testdomain'},
|
214 | 214 |
{:hostname => '', :dnsdomainname => '', :resolve_domain => 'testdomain.', :resolve_search => '', :expect => 'testdomain'},
|
215 | |
{:hostname => '', :dnsdomainname => '', :resolve_domain => '', :resolve_search => 'testdomain.', :expect => 'testdomain'},
|
|
215 |
{:hostname => '', :dnsdomainname => '', :resolve_domain => '', :resolve_search => 'testdomain.', :expect => 'testdomain'},
|
216 | 216 |
{:hostname => '', :dnsdomainname => '', :resolve_domain => '', :resolve_search => '', :expect => nil}
|
217 | 217 |
].each do |scenario|
|
218 | 218 |
|
219 | 219 |
describe "scenarios" do
|
220 | |
before(:each) do
|
|
220 |
before(:each) do
|
221 | 221 |
Facter::Util::Resolution.stubs(:exec).with("hostname -f").returns(scenario[:hostname])
|
222 | 222 |
Facter::Util::Resolution.stubs(:exec).with("dnsdomainname").returns(scenario[:dnsdomainname])
|
223 | 223 |
@mock_file = mock()
|
|
237 | 237 |
Facter.fact(:domain).value.should == scenario[:expect]
|
238 | 238 |
end
|
239 | 239 |
end
|
240 | |
end
|
|
240 |
end
|
241 | 241 |
end
|
242 | 242 |
end
|
243 | 243 |
end
|