pact-foundation / pact-cplusplus

C++ DSL for Pact Library
https://pact.io
MIT License
9 stars 4 forks source link

fix: Fixed errors in consumer.cpp #2

Closed Talank closed 2 years ago

Talank commented 2 years ago

Description

We can not compile the consumer.cpp mainly because of two errors:

  1. too few arguments to function ‘int32_t pact_mock_server_ffi::write_pact_file(int32_t, const char*, bool)’
  2. invalid conversion from ‘char’ to ‘const uint8_t’ while calling pact_mock_server_ffi::with_binary_file()

The first error can be resolved by including the third argument in the pact_mock_server_ffi::write_pact_file function call. And the second error can be resolved by casting the buffer.data() to const uint8_t* while calling the pact_mock_server_ffi::with_binary_file function from consumer.cpp

Resolving error 1

The error is as follows:

error: too few arguments to function ‘int32_t pact_mock_server_ffi::write_pact_file(int32_t, const char*, bool)’
   48 | _pact_file(mockServer.get_port(), this->pact_directory.data());

Here the last boolean argument determines if the file should be overrite or not. The declaration in the pact_mock_server_ffi.h for this function is as follows: int32_t write_pact_file(int32_t mock_server_port, const char *directory, bool overwrite);

In this PR, I have set the overwrite to false.

Resolving error 2

The error is as follows:

error: invalid conversion from ‘char*’ to ‘const uint8_t*’ {aka ‘const unsigned char*’} [-fpermissive]
  153 |         buffer.data(), size);
      |         ~~~~~~~~~~~^~
      |                    |
      |                    char*

This error arrise because the declaration of the with_binary_file() method in the pact_mock_server_ffi_h is as follows:

bool with_binary_file(InteractionHandle interaction,
                      InteractionPart part,
                      const char *content_type,
                      const uint8_t *body,
                      size_t size);

And while passing the argument body, a char* data is passed. And the solution is parsing the argument to const uint8_t* while calling from consumer.cpp

individual-it commented 2 years ago

@Talank you have to change the commit message and the PR header to something like: fix: .... to pass the semantic PR check