Sha256: 8b5f87a96770ca0dd26e222c179f24e90412bc0e4f7bb33d1f0cb0faeb061572

Contents?: true

Size: 986 Bytes

Versions: 9

Compression:

Stored size: 986 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, consumer_name, provider_name)
          @mock_services.add(delegator)
          response = delegator.call(env)
          response
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pact-mock_service-0.5.4 lib/pact/mock_service/control_server/mock_service_creator.rb
pact-mock_service-0.5.3 lib/pact/mock_service/control_server/mock_service_creator.rb
pact-mock_service-0.5.2 lib/pact/mock_service/control_server/mock_service_creator.rb
pact-mock_service-0.5.1 lib/pact/mock_service/control_server/mock_service_creator.rb
pact-mock_service-0.5.0 lib/pact/mock_service/control_server/mock_service_creator.rb
pact-mock_service-0.4.2 lib/pact/mock_service/control_server/mock_service_creator.rb
pact-mock_service-0.4.1 lib/pact/mock_service/control_server/mock_service_creator.rb
pact-mock_service-0.4.0 lib/pact/mock_service/control_server/mock_service_creator.rb
pact-mock_service-0.3.0 lib/pact/mock_service/control_server/mock_service_creator.rb