diff options
Diffstat (limited to 'spec/unit/plugins/rackspace_spec.rb')
-rw-r--r-- | spec/unit/plugins/rackspace_spec.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/spec/unit/plugins/rackspace_spec.rb b/spec/unit/plugins/rackspace_spec.rb index 72dc6e28..4e60d111 100644 --- a/spec/unit/plugins/rackspace_spec.rb +++ b/spec/unit/plugins/rackspace_spec.rb @@ -19,6 +19,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin rackspace" do before(:each) do + Resolv.stub(:getname).and_return("1.2.3.4") @plugin = get_plugin("rackspace") @plugin[:hostname] = "katie" @plugin[:network] = {:interfaces => {:eth0 => {"addresses"=> { @@ -95,6 +96,20 @@ describe Ohai::System, "plugin rackspace" do @plugin[:rackspace][:public_hostname].should_not be_nil end + it "should resolve hostname if reverse dns is set" do + Resolv.stub(:getname).and_return("1234.resolved.com") + @plugin.run + @plugin[:rackspace][:public_hostname].should == "1234.resolved.com" + end + + [Resolv::ResolvError, Resolv::ResolvTimeout].each do |exception| + it "should return ip address when reverse dns returns exception: #{exception}" do + Resolv.stub(:getname).and_raise(exception) + @plugin.run + @plugin[:rackspace][:public_hostname].should == "1.2.3.4" + end + end + it "should have correct values for all attributes" do @plugin.run @plugin[:rackspace][:public_ip].should == "1.2.3.4" @@ -103,7 +118,7 @@ describe Ohai::System, "plugin rackspace" do @plugin[:rackspace][:local_ipv4].should == "5.6.7.8" @plugin[:rackspace][:public_ipv6].should == "2a00:1a48:7805:111:e875:efaf:ff08:75" @plugin[:rackspace][:local_hostname].should == 'katie' - @plugin[:rackspace][:public_hostname].should == "1-2-3-4.static.cloud-ips.com" + @plugin[:rackspace][:public_hostname].should == "1.2.3.4" end it "should capture region information" do @@ -124,10 +139,13 @@ OUT it_should_behave_like "rackspace" before(:each) do + Resolv.stub(:getname).and_raise(Resolv::ResolvError) File.stub(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true) File.stub(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('') File.stub(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true) File.stub(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('') + File.stub(:exist?).with('/etc/resolv.conf').and_return(true) + File.stub(:read).with('/etc/resolv.conf').and_return('') end describe 'with no public interfaces (empty eth0)' do |