159 | 159 |
Facter::Util::Registry.stubs(:hklm_read).returns('')
|
160 | 160 |
end
|
161 | 161 |
|
162 | |
it "should use the DNSDomain for the first nic where ip is enabled" do
|
163 | |
nic = stubs 'nic'
|
164 | |
nic.stubs(:DNSDomain).returns("foo.com")
|
165 | |
|
166 | |
nic2 = stubs 'nic'
|
167 | |
nic2.stubs(:DNSDomain).returns("bar.com")
|
|
162 |
def expects_dnsdomains(domains)
|
|
163 |
nics = []
|
|
164 |
|
|
165 |
domains.each do |domain|
|
|
166 |
nic = stubs 'nic'
|
|
167 |
nic.stubs(:DNSDomain).returns(domain)
|
|
168 |
nics << nic
|
|
169 |
end
|
168 | 170 |
|
169 | 171 |
require 'facter/util/wmi'
|
170 | |
Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns([nic, nic2])
|
|
172 |
Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns(nics)
|
|
173 |
end
|
|
174 |
|
|
175 |
it "uses the first DNSDomain" do
|
|
176 |
expects_dnsdomains(['foo.com', 'bar.com'])
|
171 | 177 |
|
172 | 178 |
Facter.fact(:domain).value.should == 'foo.com'
|
|
179 |
end
|
|
180 |
|
|
181 |
it "uses the first non-nil DNSDomain" do
|
|
182 |
expects_dnsdomains([nil, 'bar.com'])
|
|
183 |
|
|
184 |
Facter.fact(:domain).value.should == 'bar.com'
|
|
185 |
end
|
|
186 |
|
|
187 |
it "uses the first non-empty DNSDomain" do
|
|
188 |
expects_dnsdomains(['', 'bar.com'])
|
|
189 |
|
|
190 |
Facter.fact(:domain).value.should == 'bar.com'
|
173 | 191 |
end
|
174 | 192 |
|
175 | 193 |
context "without any network adapters with a specified DNSDomain" do
|
176 | 194 |
let(:hostname_command) { 'hostname > NUL' }
|
177 | 195 |
|
178 | 196 |
it "should return nil" do
|
179 | |
nic = stubs 'nic'
|
180 | |
nic.stubs(:DNSDomain).returns(nil)
|
|
197 |
expects_dnsdomains([nil])
|
|
198 |
|
181 | 199 |
Facter::Util::Resolution.stubs(:exec).with(hostname_command).returns('sometest')
|
182 | 200 |
FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(false)
|
183 | |
|
184 | |
require 'facter/util/wmi'
|
185 | |
Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns([nic])
|
186 | 201 |
|
187 | 202 |
Facter.fact(:domain).value.should be_nil
|
188 | 203 |
end
|