2011-08-17 17:31:33 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'fog/core/current_machine'
|
|
|
|
|
|
|
|
describe Fog::CurrentMachine do
|
|
|
|
context '#ip_address' do
|
2012-06-22 11:26:42 -04:00
|
|
|
around(:each) do |example|
|
|
|
|
old_mock = Excon.defaults[:mock]
|
|
|
|
described_class.ip_address = nil
|
|
|
|
begin
|
|
|
|
Excon.defaults[:mock] = true
|
|
|
|
example.run
|
|
|
|
ensure
|
|
|
|
Excon.defaults[:mock] = false
|
|
|
|
Excon.stubs.clear
|
|
|
|
end
|
|
|
|
end
|
2011-08-17 17:31:33 -04:00
|
|
|
it 'should be threadsafe' do
|
2012-06-22 11:26:42 -04:00
|
|
|
Excon.stub({:method => :get, :path => '/'}, {:body => ''})
|
2011-08-17 17:31:33 -04:00
|
|
|
|
|
|
|
(1..10).map {
|
|
|
|
Thread.new { described_class.ip_address }
|
|
|
|
}.each{ |t| t.join }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should remove trailing endline characters' do
|
2012-06-22 11:26:42 -04:00
|
|
|
Excon.stub({:method => :get, :path => '/'}, {:body => "192.168.0.1\n"})
|
2011-08-17 17:31:33 -04:00
|
|
|
|
|
|
|
described_class.ip_address.should == '192.168.0.1'
|
|
|
|
end
|
2012-06-22 11:26:42 -04:00
|
|
|
|
2011-08-17 17:31:33 -04:00
|
|
|
end
|
|
|
|
end
|