diff --git a/Rakefile b/Rakefile index 4ec566b2b..3a129b061 100644 --- a/Rakefile +++ b/Rakefile @@ -60,8 +60,6 @@ task :test do end def tests(mocked) - Formatador.display_line - sh("export FOG_MOCK=#{mocked} && bundle exec spec spec") Formatador.display_line start = Time.now.to_i threads = [] diff --git a/lib/fog/core.rb b/lib/fog/core.rb index c075b421b..41ff05ef8 100644 --- a/lib/fog/core.rb +++ b/lib/fog/core.rb @@ -19,6 +19,7 @@ require 'fog/core/attributes' require 'fog/core/collection' require 'fog/core/connection' require 'fog/core/credentials' +require 'fog/core/current_machine' require 'fog/core/deprecation' require 'fog/core/errors' require 'fog/core/hmac' diff --git a/lib/fog/core/current_machine.rb b/lib/fog/core/current_machine.rb index 32e6c39d1..9848ffc4a 100644 --- a/lib/fog/core/current_machine.rb +++ b/lib/fog/core/current_machine.rb @@ -1,4 +1,3 @@ - module Fog class CurrentMachine @@lock = Mutex.new @@ -24,7 +23,7 @@ module Fog # puts "Service timeout" # end # - # @raise [Net::HTTPExceptions] if the net/http request fails. + # @raise [Excon::Errors::Error] if the net/http request fails. def self.ip_address @@lock.synchronize do @@ip_address ||= Excon.get(AMAZON_AWS_CHECK_IP).body.chomp diff --git a/spec/core/current_machine_spec.rb b/spec/core/current_machine_spec.rb deleted file mode 100644 index a22dfc268..000000000 --- a/spec/core/current_machine_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'spec_helper' -require 'fog/core/current_machine' - -describe Fog::CurrentMachine do - context '#ip_address' do - 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 - it 'should be threadsafe' do - Excon.stub({:method => :get, :path => '/'}, {:body => ''}) - - (1..10).map { - Thread.new { described_class.ip_address } - }.each{ |t| t.join } - end - - it 'should remove trailing endline characters' do - Excon.stub({:method => :get, :path => '/'}, {:body => "192.168.0.1\n"}) - - described_class.ip_address.should == '192.168.0.1' - end - - end -end diff --git a/spec/lib/fog/aws/parsers/sqs/receive_message_spec.rb b/spec/lib/fog/aws/parsers/sqs/receive_message_spec.rb deleted file mode 100644 index fd7e9894e..000000000 --- a/spec/lib/fog/aws/parsers/sqs/receive_message_spec.rb +++ /dev/null @@ -1,58 +0,0 @@ -require 'fog/core/parser' -require 'fog/aws/parsers/sqs/receive_message' - -describe Fog::Parsers::AWS::SQS::ReceiveMessage do - let(:parser) { Fog::Parsers::AWS::SQS::ReceiveMessage.new } - - let(:sent_timestamp) { 1322475007845 } - let(:approximate_first_receive_timestamp) { 1322494017370 } - - let(:xml) do - <<-XML - - - - - e4fbeece-7260-4106-807d-18255e43e687 - gH2qdC6bjNtuE/U+iA5J/5HQK/lgvsTY0Vj+gFEXyRlsRL+EDf9tgjLxAW9cdutwjqgV22jyQyTgFsYV+G0oQc2posQntKVMZKqOLlrJqbKSOUnsBtkoWoD2MxyacbuDTG0q0a9yS3RpPSN4lV8RN0BrJjfoeQDRQOn/RIxtAH9H4C4NasSLODB1xJWcO/KsZYRch0IWL89a4YgP060XCxAyKYqY8O+GvNhX5d59JRAI6tO2sx9wLwytIHNlG97DDnUGb/6PNuYPmoZcvYOdfhMQgP28rdrUW3B7Pai+dqE= - b425c09d8559b59dd989cf8c47caaf54 - testmessage - SenderId000000000000 - SentTimestamp#{sent_timestamp} - ApproximateReceiveCount2 - ApproximateFirstReceiveTimestamp#{approximate_first_receive_timestamp} - - - 72c77661-d4b5-45b9-8a82-a685c980e9dd - - XML - end - - def timestamp(attribute) - body = Nokogiri::XML::SAX::PushParser.new(parser) - body << xml - body.finish - response_body = parser.response - response_body['Message'].first['Attributes'][attribute].utc - end - - it "converts SentTimestamp to the same time as a Time-like object" do - stamp = timestamp 'SentTimestamp' - stamp.year.should == 2011 - stamp.month.should == 11 - stamp.day.should == 28 - stamp.hour.should == 10 - stamp.min.should == 10 - stamp.sec.should == 7 - end - - it "converts ApproximateFirstReceiveTimestamp to the same time as a Time-like object" do - stamp = timestamp 'ApproximateFirstReceiveTimestamp' - stamp.year.should == 2011 - stamp.month.should == 11 - stamp.day.should == 28 - stamp.hour.should == 15 - stamp.min.should == 26 - stamp.sec.should == 57 - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb deleted file mode 100644 index 2c0bb5920..000000000 --- a/spec/spec_helper.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'rspec' -require 'open-uri' -require 'fog' -require 'fog/bin' - -if ENV["FOG_MOCK"] == "true" - Fog.mock! -end diff --git a/tests/core/current_machine_tests.rb b/tests/core/current_machine_tests.rb new file mode 100644 index 000000000..8fddf5f9a --- /dev/null +++ b/tests/core/current_machine_tests.rb @@ -0,0 +1,32 @@ +Shindo.tests('Fog CurrentMachine', 'core') do + + pending unless Fog.mock? + + old_excon_defaults_mock = Excon.defaults[:mock] + Excon.defaults[:mock] = true + + tests('ip_address') do + + tests('should be thread safe') do + Excon.stub({:method => :get, :path => '/'}, {:body => ''}) + + (1..10).map { + Thread.new { Fog::CurrentMachine.ip_address } + }.each{ |t| t.join } + end + + Fog::CurrentMachine.ip_address = nil + Excon.stubs.clear + + tests('should remove trailing endline characters') do + Excon.stub({:method => :get, :path => '/'}, {:body => "192.168.0.1\n"}) + Fog::CurrentMachine.ip_address == '192.168.0.1' + end + + end + + Fog::CurrentMachine.ip_address = nil + Excon.stubs.clear + Excon.defaults[:mock] = old_excon_defaults_mock + +end