I think I need help with `verifying service method...
# libpact_ffi-users
t
I think I need help with
verifying service method interaction with a gRPC server
https://github.com/pactflow/pact-protobuf-plugin#service-method-provider I choose to write unit test to verify instead of using
pact_verifier_cli
. This part of the unit test:
Copy code
public function testPactVerifyConsumer()
    {
        $config = new VerifierConfig();
        $config->getProviderInfo()
            ->setName('protobufProvider')
            ->setHost('127.0.0.1')
            ->setScheme('tcp')
            ->setPort(9001);
        $providerTransport = new ProviderTransport();
        $providerTransport
            ->setProtocol('grpc')
            ->setScheme('tcp')
            ->setPort(9001)
            ->setPath('/')
        ;
        $config->addProviderTransport($providerTransport);
        if ($logLevel = \getenv('PACT_LOGLEVEL')) {
            $config->setLogLevel($logLevel);
        }

        $verifier = new Verifier($config);
        $verifier->addDirectory(__DIR__.'/../../../broker/pacts');

        $this->assertTrue($verifier->verify());
    }
This is the output:
Copy code
Verifying a pact between protobufConsumer and protobufProvider

  request for calculate shape area (0s loading, 2ms verification)
      Request Failed - builder error for url (<tcp://127.0.0.1:9001>): URL scheme is not allowed


Failures:

1) Verifying a pact between protobufConsumer and protobufProvider - request for calculate shape area - builder error for url (<tcp://127.0.0.1:9001>): URL scheme is not allowed
This is part of the log I think it's useful:
Copy code
2023-03-23T10:56:35.997068Z  INFO ThreadId(01) verify_interaction{interaction="request for calculate shape area"}: pact_verifier: Running provider verification for 'request for calculate shape area'
2023-03-23T10:56:35.997099Z DEBUG ThreadId(01) verify_interaction{interaction="request for calculate shape area"}: pact_verifier: Verifying a synchronous message (request/response)
2023-03-23T10:56:35.997212Z  INFO ThreadId(01) verify_interaction{interaction="request for calculate shape area"}: pact_verifier::provider_client: Sending request to provider at <tcp://127.0.0.1:9001/>
2023-03-23T10:56:35.997230Z DEBUG ThreadId(01) verify_interaction{interaction="request for calculate shape area"}: pact_verifier::provider_client: Provider details = ProviderInfo { name: "protobufProvider", protocol: "tcp", host: "127.0.0.1", port: Some(9001), path: "/", transports: [ProviderTransport { transport: "tcp", port: Some(9001), path: Some("/"), scheme: None }, ProviderTransport { transport: "grpc", port: Some(9001), path: Some("/"), scheme: Some("tcp") }] }
2023-03-23T10:56:35.997244Z  INFO ThreadId(01) verify_interaction{interaction="request for calculate shape area"}: pact_verifier::provider_client: Sending request HTTP Request ( method: POST, path: /, query: None, headers: Some({"Content-Type": ["application/json"]}), body: Present(447 bytes, application/json) )
2023-03-23T10:56:35.997257Z DEBUG ThreadId(01) verify_interaction{interaction="request for calculate shape area"}: pact_verifier::provider_client: body:
{"description":"request for calculate shape area","request":{"contents":{"content":"EgoNAABAQBUAAIBA","contentType":"application/protobuf;message=ShapeMessage","contentTypeHint":"BINARY","encoded":"base64"},"matchingRules":{"body":{"$.rectangle.length":{"combine":"AND","matchers":[{"match":"number"}]},"$.rectangle.width":{"combine":"AND","matchers":[{"match":"number"}]}}},"metadata":{"contentType":"application/protobuf;message=ShapeMessage"}}}
2023-03-23T10:56:35.997298Z DEBUG ThreadId(01) verify_interaction{interaction="request for calculate shape area"}: pact_verifier::provider_client: Native request builder: RequestBuilder { method: POST, url: Url { scheme: "tcp", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("127.0.0.1")), port: Some(9001), path: "", query: None, fragment: None }, headers: {"content-type": "application/json"}
Do you know how to solve that error
URL scheme is not allowed
?
👋 1
After adding some more debug message and compiling
pact_ffi
, I see the real issue:
transport
is missing from pact file:
Copy code
{
  "consumer": {
    "name": "protobufConsumer"
  },
  "interactions": [
    {
      .................
      "transport": "grpc"
    }
  ],
  "provider": {
    "name": "protobufProvider"
  }
}
How can I add this value to pact file?
y
The transport should be in the pact file https://github.com/pact-foundation/pact-reference/blob/9b1b7965f0b97a8c7d11f2d8bb6[…]9e482/php/pacts/grpc-consumer-php-area-calculator-provider.json I also noted some odd behaviour with
pactffi_verifier_set_provider_info
&
pactffi_verifier_add_provider_transport
I jotted some comments and experiments when trying to verify both a plugin pact (grpc) and http pact and trying to set the correct transports for both
Copy code
// 💡
// This would be my preferrred option
// Set the provider name (which should be used by anything using the verifier_handle, and filter sourced pacts that don't contain name)
// add multiple transports.
// note pactffi_verifier_set_provider_name does not exist
// update_provider_info might work
// <https://github.com/pact-foundation/pact-reference/blob/cfb2c03f87b3f67464291dd936d0aac555c42c91/rust/pact_ffi/src/verifier/handle.rs#L89>
// but is marked as deprecated.
 //
// also worthy of note, if pactffi_verifier_set_provider_info didn't mix with the information used in pactffi_verifier_add_provider_transport
 // this probably wouldn't be neccessary.
 $ffi->pactffi_verifier_set_provider_name($handle, 'http-provider'); // note this function doesn't exist (wishlist)
 $ffi->pactffi_verifier_add_provider_transport($handle, 'http',8000,'/','http');
$ffi->pactffi_verifier_add_provider_transport($handle, 'protobuf',37757,'/','tcp');
Looks related to your comments here https://pact-foundation.slack.com/archives/C02BXLDJ7JR/p1679503099374349 will take some time to go through them properly today
t
How can I forgot these valued comments. Let me check through them. Thanks
I found solution (based on your example): replace
pactffi_pact_handle_write_file
by
pactffi_write_pact_file
. I think because mock server know what transport it's using (by calling
pactffi_create_mock_server_for_transport
), asking it to write pact file will have additional
transport
information. I think this useful information should be mentioned somewhere , at least in the
pact.h
file?
y
Ahhh fabulous, glad they were helpful to you, it was your PHP examples that helped me in the first place 😄 I think capturing some of these thoughts maybe in https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_ffi/ARCHITECTURE.md or some kind of documentation for consumers of the FFI (being Authors/maintainers of pact client libraries) I love the idea of the reference implementations which really strip away from the client libraries DSLs and show the raw FFI calls for particular scenarioes, which then are easier to translate across to other languages as there is a clear view on what methods/args/ordering is required for said feature
or in the header file, tbh that is where I read most of the comments, however its harder to get too, as you have to get it from the releases pages. It would also be cool if the pact.h was annotated with the ffi version that it is for, I don't think there is a version in it, so you rely on it being supplied with the shared lib (which the pact client libs take care off but more awk when your testing against diff ffi versions directly)
u
Also, tcp is not a valid scheme
setScheme('tcp')
, it should be grpc.
t
tcp is not a valid scheme
setScheme('tcp')
, it should be grpc
I assume this note is for providerInfo part only. I removed it once I found solution above.
Add a comment about
pactffi_write_pact_file
into the file consumer-plugin.php, then create a PR to merge branch
php_plugins
into
master
is another option, but it's less obvious, and only for people who interest in reading PHP code only