Sha256: 70c1279a76660703853badae7f497499311cc32b48ec434f1198b1e8e58afe2b

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

require "integration_helper"

class Circuitbox
  class FaradayMiddlewareTest < Minitest::Test
    @@only_once = false
    def setup
      @connection = Faraday.new do |c|
        c.use FaradayMiddleware
        c.adapter Faraday.default_adapter
      end
      @success_url = "http://localhost:4711"
      @failure_url = "http://localhost:4712"

      if !@@only_once
        FakeServer.create(4711, ['200', {'Content-Type' => 'text/plain'}, ["Success!"]])
        FakeServer.create(4712, ['500', {'Content-Type' => 'text/plain'}, ["Failure!"]])
      end
    end

    def teardown
      Circuitbox.reset
    end

    def test_open_circuit_response
      10.times { @connection.get(@failure_url) } # make the CircuitBreaker open
      open_circuit_response = @connection.get(@failure_url)
      assert open_circuit_response.status, 503
      assert_match open_circuit_response.original_response.body, "Failure!"
    end

    def test_closed_circuit_response
      result = @connection.get(@success_url)
      assert result.success?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
circuitbox-0.9.0 test/integration/faraday_middleware_test.rb
circuitbox-0.8.0 test/integration/faraday_middleware_test.rb