Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jvmlet opened this issue May 24, 2023 · 3 comments
Open

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

jvmlet opened this issue May 24, 2023 · 3 comments
Labels
feature request Indicates new feature requests good first issue Indicates a good issue for first-time contributors help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@jvmlet
Copy link

jvmlet commented May 24, 2023

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

@mkokho
Copy link

mkokho commented Jul 9, 2023

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: pact-foundation/pact-js#941

@mkokho
Copy link

mkokho commented Jul 9, 2023

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 mefellows added feature request Indicates new feature requests help wanted Indicates that a maintainer wants help on an issue or pull request good first issue Indicates a good issue for first-time contributors labels Aug 18, 2023
@mefellows
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Indicates new feature requests good first issue Indicates a good issue for first-time contributors help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
Status: New Issue
Development

No branches or pull requests

3 participants