Ruth
Ruth

Reputation: 1110

Pact V4 migration with headers does not work

I am currently trying to move to V4 pacts.

Currently I have this pact, which works

@Pact(consumer = CONSUMER, provider = PROVIDER)
RequestResponsePact provider(PactDslWithProvider builder) {
  return builder
      .uponReceiving("get")
      .method("GET")
      .headers("accept", "application/json, application/*+json")
      .path("/test")
      .willRespondWith()
      .status(200)
      .toPact()
}

I migrated it to look like this:

@Pact(consumer = CONSUMER, provider = PROVIDER)
V4Pact provider(PactBuilder builder) {
  return builder
      .expectsToReceiveHttpInteraction("get") { httpBuilder ->
        httpBuilder
            .withRequest { httpRequestBuilder ->
              httpRequestBuilder
                  .path("/test")
                  .method("GET")
                  .headers("accept", "application/json, application/*+json")
            }
            .willRespondWith { httpResponseBuilder ->
              httpResponseBuilder.status(200)
            }
      }
      .toPact()
}

but now I get this error message from Pact:

2025-01-16 11:41:50,475 [HTTP-Dispatcher] ERROR  a.c.d.p.c.BaseMockServer$Companion - PartialRequestMatch: get:
    Expected header 'accept' to have value 'application/json' but was 'application/json, application/*+json'
    Expected header 'accept' to have value 'application/*+json' but was ''

I am very confused as the signature of the method headers I am using shows it as a value:String. I also tried the .header method, but I still get the same error. Any idea what I can do?

Upvotes: 0

Views: 20

Answers (0)

Related Questions