spec/unit/ec2_spec.rb in facter-1.6.18 vs spec/unit/ec2_spec.rb in facter-1.7.0.rc1

- old
+ new

@@ -26,11 +26,12 @@ Object.any_instance.expects(:open). with("#{api_prefix}/2008-02-01/meta-data/foo"). at_least_once.returns(StringIO.new("bar")) - Facter.collection.loader.load(:ec2) + Facter.collection.internal_loader.load(:ec2) + Facter.fact(:ec2_foo).value.should == "bar" end it "should create flat meta-data facts with comma seperation" do Object.any_instance.expects(:open). @@ -39,11 +40,12 @@ Object.any_instance.expects(:open). with("#{api_prefix}/2008-02-01/meta-data/foo"). at_least_once.returns(StringIO.new("bar\nbaz")) - Facter.collection.loader.load(:ec2) + Facter.collection.internal_loader.load(:ec2) + Facter.fact(:ec2_foo).value.should == "bar,baz" end it "should create structured meta-data facts" do Object.any_instance.expects(:open). @@ -56,11 +58,12 @@ Object.any_instance.expects(:open). with("#{api_prefix}/2008-02-01/meta-data/foo/bar"). at_least_once.returns(StringIO.new("baz")) - Facter.collection.loader.load(:ec2) + Facter.collection.internal_loader.load(:ec2) + Facter.fact(:ec2_foo_bar).value.should == "baz" end it "should create ec2_user_data fact" do # No meta-data @@ -70,11 +73,11 @@ Facter::Util::EC2.stubs(:read_uri). with("#{api_prefix}/latest/user-data/"). returns("test") - Facter.collection.loader.load(:ec2) + Facter.collection.internal_loader.load(:ec2) Facter.fact(:ec2_userdata).value.should == ["test"] end end describe "when running on eucalyptus" do @@ -97,11 +100,11 @@ Facter::Util::EC2.stubs(:read_uri). with("#{api_prefix}/latest/user-data/"). returns("test") # Force a fact load - Facter.collection.loader.load(:ec2) + Facter.collection.internal_loader.load(:ec2) Facter.fact(:ec2_userdata).value.should == ["test"] end end @@ -125,11 +128,11 @@ Facter::Util::EC2.stubs(:read_uri). with("#{api_prefix}/latest/user-data/"). returns("test") # Force a fact load - Facter.collection.loader.load(:ec2) + Facter.collection.internal_loader.load(:ec2) Facter.fact(:ec2_userdata).value.should == ["test"] end it "should return nil if open fails" do @@ -143,18 +146,22 @@ Facter::Util::EC2.stubs(:read_uri). with("#{api_prefix}/latest/user-data/"). raises(RuntimeError, 'host unreachable') # Force a fact load - Facter.collection.loader.load(:ec2) + Facter.collection.internal_loader.load(:ec2) Facter.fact(:ec2_userdata).value.should be_nil end end describe "when api connect test fails" do + before :each do + Facter.stubs(:warnonce) + end + it "should not populate ec2_userdata" do # Emulate ec2 for now as it matters little to this test Facter::Util::EC2.stubs(:has_euca_mac?).returns(true) Facter::Util::EC2.stubs(:has_ec2_arp?).never Facter::Util::EC2.expects(:can_connect?).at_least_once.returns(false) @@ -164,10 +171,10 @@ with("#{api_prefix}/2008-02-01/meta-data/").never Object.any_instance.expects(:open). with("#{api_prefix}/2008-02-01/user-data/").never # Force a fact load - Facter.collection.loader.load(:ec2) + Facter.collection.internal_loader.load(:ec2) Facter.fact(:ec2_userdata).should == nil end it "should rescue the exception" do