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?
Hey, just a friendly reminder. Could you please implement this feature? It's quite inconvenient to verify interactions when there are numerous services, and the contracts are not ready. This is especially unpleasant to realize when other languages have such a setting to disable.
Looking forward to your response about this issue, thanks!
Why not fork the project, implement the feature and propose a pull request?
It was introduced by an external contributor in the linked pull request against pact-js.
Please support
--fail-if-no-pacts-found
in verifier configuration