pact-foundation / pact-net

.NET version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://pact.io
MIT License
847 stars 234 forks source link

Please support --fail-if-no-pacts-found in verifier configuration #462

Open jvmlet opened 1 year ago

jvmlet commented 1 year ago

Please support --fail-if-no-pacts-found in verifier configuration

mkokho commented 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

mkokho commented 1 year ago

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);
        }
mefellows commented 1 year ago

I imagine it's a pretty straightforward addition - would you be open to creating a PR?

ekarnialiuk commented 1 month ago

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!

YOU54F commented 1 month ago

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.