Codebase list facter / 5a8547d
(14466) Warn when no facts found Add `warnonce` message to Facter to alert user when no facts were loaded. Hailee Kenney 11 years ago
3 changed file(s) with 22 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
7777 # Try HARDER
7878 loader.load_all unless @facts[name]
7979
80 # Warn if no facts were loaded
81 Facter.warnonce("No facts loaded from #{loader.search_path.join(File::PATH_SEPARATOR)}") if @facts.length == 0
82
8083 @facts[name]
8184 end
8285
148148 end
149149
150150 describe "when api connect test fails" do
151 before :each do
152 Facter.stubs(:warnonce)
153 end
154
151155 it "should not populate ec2_userdata" do
152156 # Emulate ec2 for now as it matters little to this test
153157 Facter::Util::EC2.stubs(:has_euca_mac?).returns(true)
257257 facts.should_not be_include("two")
258258 end
259259 end
260
261 describe "when no facts are loaded" do
262 before :each do
263 @coll = Facter::Util::Collection.new
264 @load = Facter::Util::Loader.new
265 @load.stubs(:load).returns nil
266 @load.stubs(:load_all).returns nil
267 @coll.stubs(:loader).returns @load
268 end
269
270 it "should warn when no facts were loaded" do
271 Facter.expects(:warnonce).with("No facts loaded from #{@load.search_path.join(File::PATH_SEPARATOR)}").once
272 @coll.fact("one")
273 end
274 end
260275 end