Sha256: 6f2c8822a7781eca6e60e46006ddb6a52420a984e1f868ede738a7b1d015a4c7

Contents?: true

Size: 1014 Bytes

Versions: 1

Compression:

Stored size: 1014 Bytes

Contents

require 'pact/mock_service/spawn'
require 'pact/mock_service/control_server/delegator'
require 'find_a_port'
require 'pact/mock_service/server/wait_for_server_up'

# Create a new MockService on a random port and delegate the incoming request to it

module Pact
  module MockService
    module ControlServer

      class MockServiceCreator

        attr_reader :options

        def initialize mock_services, options
          @mock_services = mock_services
          @options = options
        end

        def call env
          consumer_name = env['HTTP_X_PACT_CONSUMER']
          provider_name = env['HTTP_X_PACT_PROVIDER']
          port = FindAPort.available_port
          mock_service = Pact::MockService::Spawn.(consumer_name, provider_name, port, options)
          delegator = Delegator.new(mock_service, "http://localhost:#{port}", consumer_name, provider_name)
          @mock_services.add(delegator)
          response = delegator.call(env)
          response
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pact-mock_service-0.2.4 lib/pact/mock_service/control_server/mock_service_creator.rb