Open jvmlet opened 1 year ago
Agree, useful feature. It is hard to make Providers run contract test in new environment when no consumers exist yet
Support was added in pact-js in 2022: https://github.com/pact-foundation/pact-js/issues/941
possible workaround
/// <summary>
/// Send a request to the Pact Broker to check if pacts exist for the given filters.
/// </summary>
/// <returns>true if at least one pact is returned for the given filters</returns>
private async Task<bool> PactsForVerificationExist(Uri pactBrokerUri, string providerName,
List<ConsumerVersionSelector> pactsSelectors)
{
var jsonSettings = new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }
};
var payload = new Dictionary<dynamic, dynamic>
{
{ "consumerVersionSelectors", pactsSelectors },
{ "includePendingStatus", true },
{ "includeWipPactsSince", "2023-06-01" }
};
var payloadAsJson = JsonConvert.SerializeObject(payload, jsonSettings);
var data = new StringContent(payloadAsJson, Encoding.UTF8, "application/json");
var forVerificationUri = new Uri(pactBrokerUri + $"/providers/{providerName}/for-verification");
var response = await _httpClient.PostAsync(pactBrokerUri, data);
var result = await response.Content.ReadAsStringAsync();
// return true if at least one pact is returned
return result.Contains(providerName);
}
I imagine it's a pretty straightforward addition - would you be open to creating a PR?
Please support
--fail-if-no-pacts-found
in verifier configuration