Class: Pact::V2::Provider::BaseVerifier

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/v2/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

Raises:

  • (ArgumentError)


30
31
32
33
34
35
# File 'lib/pact/v2/provider/base_verifier.rb', line 30

def initialize(pact_config, mixed_config = nil)
  raise ArgumentError, "pact_config must be a subclass of Pact::V2::Provider::PactConfig::Base" unless pact_config.is_a?(::Pact::V2::Provider::PactConfig::Base)
  @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.



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

def logger
  @logger
end

Instance Method Details

#verify!Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pact/v2/provider/base_verifier.rb', line 37

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::V2::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])
  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