File: current_machine_spec.rb

package info (click to toggle)
ruby-fog-core 2.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 676 kB
  • sloc: ruby: 4,719; makefile: 5
file content (36 lines) | stat: -rw-r--r-- 857 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require "spec_helper"

describe Fog::CurrentMachine do
  before do
    @was_mocking = Fog.mock?
    Fog.mock!

    @old_excon_defaults_mock = Excon.defaults[:mock]
    Excon.defaults[:mock] = true
  end

  after do
    Fog.unmock! unless @was_mocking

    Fog::CurrentMachine.ip_address = nil
    Excon.stubs.clear
    Excon.defaults[:mock] = @old_excon_defaults_mock
  end

  describe "ip_address" do
    it "should be thread safe" do

      (1..10).map do
        Thread.new do
          Excon.stub({ :method => :get, :path => "/" }, { :body => "" })
          Fog::CurrentMachine.ip_address
        end
      end.each(&:join)
    end

    it "should remove trailing endline characters" do
      Excon.stub({ :method => :get, :path => "/" }, { :body => "192.168.0.1\n" })
      assert_equal "192.168.0.1", Fog::CurrentMachine.ip_address
    end
  end
end