Class: Pact::Provider::BaseVerifier

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/provider/base_verifier.rb

Direct Known Subclasses

AsyncMessageVerifier, GrpcVerifier, HttpVerifier

Defined Under Namespace

Classes: VerificationError, VerifierError

Constant Summary collapse

PROVIDER_TRANSPORT_TYPE =
nil
DEFAULT_CONSUMER_SELECTORS =
{}
VERIFICATION_ERRORS =
{
  1 => { reason: :verification_failed, status: 1,
         description: 'The verification process failed, see output for errors' },
  2 => { reason: :null_pointer, status: 2, description: 'A null pointer was received' },
  3 => { reason: :internal_error, status: 3, description: 'The method panicked' },
  4 => { reason: :invalid_arguments, status: 4,
         description: 'Invalid arguments were provided to the verification process' }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pact_config, mixed_config = nil) ⇒ BaseVerifier

env below are set up by pipeline-builder see paas/cicd/images/pact/pipeline-builder/-/blob/master/internal/commands/consumers-pipeline/ruby.go



31
32
33
34
35
36
37
38
39
40
# File 'lib/pact/provider/base_verifier.rb', line 31

def initialize(pact_config, mixed_config = nil)
  unless pact_config.is_a?(::Pact::Provider::PactConfig::Base)
    raise ArgumentError,
          'pact_config must be a subclass of Pact::Provider::PactConfig::Base'
  end

  @pact_config = pact_config
  @mixed_config = mixed_config
  @logger = @pact_config.logger || Logger.new($stdout)
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



11
12
13
# File 'lib/pact/provider/base_verifier.rb', line 11

def logger
  @logger
end

Instance Method Details

#verify!Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pact/provider/base_verifier.rb', line 42

def verify!
  raise VerifierError.new('interaction is designed to be used one-time only') if defined?(@used)

  # if consumer_selectors.blank?
  #   logger.info("[verifier] does not need to verify consumer #{@pact_config.consumer_name}")
  #   return
  # end

  exception = nil
  pact_handle = init_pact

  start_servers!

  logger.info('[verifier] starting provider verification')

  result = Pact::Native::BlockingVerifier.execute(pact_handle)
  if VERIFICATION_ERRORS[result].present?
    error = VERIFICATION_ERRORS[result]
    exception = VerificationError.new(
      "There was an error while trying to verify provider \"#{@pact_config.provider_name}\"", error[:reason], error[:status] # rubocop:disable Layout/LineLength
    )
  end
ensure
  @used = true
  PactFfi::Verifier.shutdown(pact_handle) if pact_handle
  stop_servers
  @grpc_server.stop if @grpc_server
  raise exception if exception
end