Hi guys, I have errors when I perform tests on the...
# pact-go
g
Hi guys, I have errors when I perform tests on the content type. And I don’t understand why! I have this message:
Copy code
2.1) includes header 'Content-Type' with value 'application/json; charset=utf-8'
           Expected header 'Content-Type' to have value 'application/json; charset=utf-8' but was 'application/json; charset=utf-8'
But for me the 2 strings are equal. How can I fix this?
m
strange. Given the error looks obviously confusing, we’re going to need more detail in order to look into this. 1. Logs (ideally at debug or trace level, which will contain the HTTP response from the provider we can inspect) 2. Code - consumer pact
g
hello, I made this request :
Copy code
curl --location --request GET '<http://localhost:8080/api/v1/product/21>' -vvv
Note: Unnecessary use of -X or --request, GET is already inferred.
*   Trying ::1:8080...
* Connected to localhost (::1) port 8080 (#0)
> GET /api/v1/product/21 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.77.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Date: Tue, 12 Jul 2022 12:51:27 GMT
< Content-Length: 88
<
* Connection #0 to host localhost left intact
{"id":21,"name":"foo 2","brand":"bar 2","price_incl_vat":23.125,"price_excl_tax":20.125}%
@Matt (pactflow.io / pact-js / pact-go) And here with TRACE,
Copy code
Verifying a pact between ms.pact-consumer-example-for-go.b2c and ms.pact-provider-example-for-go
  Given The product with ID 21 exists
2022/07/12 14:50:46 [INFO] executing state handler middleware
2022/07/12 14:50:46 [TRACE] state handler received raw input {"action":"setup","params":{},"state":"The product with ID 21 exists"}
2022/07/12 14:50:46 [TRACE] state handler parsed input (without params) {setup The product with ID 21 exists map[]}
2022/07/12 14:50:46 [TRACE] state handler completed parsing input (with params) {setup The product with ID 21 exists map[params:map[]]}
2022/07/12 14:50:46 [TRACE] skipping state handler for request /api/v1/product/21
2022/07/12 14:50:46 [DEBUG] http reverse proxy received connection from [::1]:54332 on path /api/v1/product/21
2022/07/12 14:50:46 [DEBUG] setting proxy to target
2022/07/12 14:50:46 [DEBUG] incoming request /api/v1/product/21
2022/07/12 14:50:46 [DEBUG] outgoing request to target <http://localhost:8080/api/v1/product/21>
2022/07/12 14:50:46 [TRACE] proxy outgoing request
 GET /api/v1/product/21 HTTP/1.1
Host: localhost:8080
User-Agent: Pact Go
Accept: */*
Accept-Encoding: gzip, deflate
X-Forwarded-For: ::1


2022/07/12 14:50:46 [TRACE] proxied server response
 HTTP/1.1 200 OK
Content-Length: 88
Content-Type: application/json; charset=utf-8
Date: Tue, 12 Jul 2022 12:50:46 GMT

{"id":21,"name":"foo 2","brand":"bar 2","price_incl_vat":23.125,"price_excl_tax":20.125}
2022/07/12 14:50:46 [INFO] executing state handler middleware
2022/07/12 14:50:46 [TRACE] state handler received raw input {"action":"teardown","params":{},"state":"The product with ID 21 exists"}
2022/07/12 14:50:46 [TRACE] state handler parsed input (without params) {teardown The product with ID 21 exists map[]}
2022/07/12 14:50:46 [TRACE] state handler completed parsing input (with params) {teardown The product with ID 21 exists map[params:map[]]}
  Given The product with ID 66 doesn't exists
2022/07/12 14:50:46 [INFO] executing state handler middleware
2022/07/12 14:50:46 [TRACE] state handler received raw input {"action":"setup","params":{},"state":"The product with ID 66 doesn't exists"}
2022/07/12 14:50:46 [TRACE] state handler parsed input (without params) {setup The product with ID 66 doesn't exists map[]}
2022/07/12 14:50:46 [TRACE] state handler completed parsing input (with params) {setup The product with ID 66 doesn't exists map[params:map[]]}
2022/07/12 14:50:46 [WARN] no state handler found for state: The product with ID 66 doesn't exists
2022/07/12 14:50:46 [TRACE] skipping state handler for request /api/v1/product/66
2022/07/12 14:50:46 [DEBUG] http reverse proxy received connection from [::1]:54336 on path /api/v1/product/66
2022/07/12 14:50:46 [DEBUG] setting proxy to target
2022/07/12 14:50:46 [DEBUG] incoming request /api/v1/product/66
2022/07/12 14:50:46 [DEBUG] outgoing request to target <http://localhost:8080/api/v1/product/66>
2022/07/12 14:50:46 [TRACE] proxy outgoing request
 GET /api/v1/product/66 HTTP/1.1
Host: localhost:8080
User-Agent: Pact Go
Accept: */*
Accept-Encoding: gzip, deflate
X-Forwarded-For: ::1


2022/07/12 14:50:46 [TRACE] proxied server response
 HTTP/1.1 404 Not Found
Content-Length: 2
Content-Type: application/json; charset=utf-8
Date: Tue, 12 Jul 2022 12:50:46 GMT

{}
2022/07/12 14:50:46 [INFO] executing state handler middleware
2022/07/12 14:50:46 [TRACE] state handler received raw input {"action":"teardown","params":{},"state":"The product with ID 66 doesn't exists"}
2022/07/12 14:50:46 [TRACE] state handler parsed input (without params) {teardown The product with ID 66 doesn't exists map[]}
2022/07/12 14:50:46 [TRACE] state handler completed parsing input (with params) {teardown The product with ID 66 doesn't exists map[params:map[]]}
2022/07/12 14:50:46 [WARN] no state handler found for state: The product with ID 66 doesn't exists

  a request Product 21
    returns a response which
      has status code 200 (OK)
      includes headers
        "Content-Type" with value "application/json; charset=utf-8" (FAILED)
      has a matching body (OK)

  a request Product 66
    returns a response which
      has status code 404 (OK)
      includes headers
        "Content-Type" with value "application/json; charset=utf-8" (FAILED)
      has a matching body (OK)