From b3aad26d777d3bad996e75c951da3af1a2e9ef05 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Mon, 1 Jul 2024 15:56:48 +0100 Subject: [PATCH] chore: update consumer version code snippets --- .../consumer_version_selectors.md | 246 ++++++++---------- 1 file changed, 103 insertions(+), 143 deletions(-) diff --git a/website/docs/pact_broker/advanced_topics/consumer_version_selectors.md b/website/docs/pact_broker/advanced_topics/consumer_version_selectors.md index 84154407..9d4a1057 100644 --- a/website/docs/pact_broker/advanced_topics/consumer_version_selectors.md +++ b/website/docs/pact_broker/advanced_topics/consumer_version_selectors.md @@ -97,11 +97,6 @@ This is the most common use case. - We recommend using `deployedOrReleased` to return the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment, this allows the provider to not know that detail and let the Pact broker take care of it for you) - alternatively you can target just `deployed` or just `released` consumers across `all` environments , or consumers only in specified `environments`. - We recommend using `mainBranch` to return the pacts associated with any consumers configured `mainBranch` property (your consumer may have the branch `main`, `master` or `develop`, this allows the provider to not know that detail and let the Pact broker take care of it for you) -- The shown selectors, will target for the provider - - any pacts for the consumer associated with their configured `mainBranch` property - - any pacts for the consumers, deployed to `any` environment - - This if filtered by only pacts `deployed` or `released` to the `test` / `production` environments. - - If this consumer/provider pair, has an additional environment `staging`, it would not be picked up, due to the named `test` / `production` environments. Removing these conditions, will return any pacts, deployed or released to any environment, which is the recommended setup for the majority of cases. (coupled with enabling pending pacts.) { - options.ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true }, // (recommended) - Returns the pacts for consumers configured mainBranch property - new ConsumerVersionSelector { DeployedOrReleased = true } // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment. - new ConsumerVersionSelector { Deployed = true, Environment = "test" }, // Normally, this would not be needed, Any versions currently deployed to the specified environment. - new ConsumerVersionSelector { Deployed = true, Environment = "production" }, // Normally, this would not be needed, Any versions currently deployed to the specified environment. - new ConsumerVersionSelector { Released = true, Deployed = true, Environment = "test" }, // Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment. - new ConsumerVersionSelector { Released = true, Deployed = true, Environment = "production" }, // Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment. + options.ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true }, + new ConsumerVersionSelector { DeployedOrReleased = true } ) .PublishResults(version, results => { @@ -256,23 +225,11 @@ verifier = Verifier( pact.VerifyProvider(t, types.VerifyRequest{ ConsumerVersionSelectors: []types.ConsumerVersionSelector{ types.ConsumerVersionSelector{ - MainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property - }, - types.ConsumerVersionSelector{ - DeployedOrReleased: true, // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment. + MainBranch: true, }, types.ConsumerVersionSelector{ - Deployed: "test", // Normally, this would not be needed, Any versions currently deployed to the specified environment. - }, - types.ConsumerVersionSelector{ - Deployed: "production", // Normally, this would not be needed, Any versions currently deployed to the specified environment. - }, - types.ConsumerVersionSelector{ - Environment: "test", // Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment. - }, - types.ConsumerVersionSelector{ - Environment: "production", // Normally, this would not be needed, Any versions currently deployed or released and supported in the specified environment. - }, + DeployedOrReleased: true, + } }, // ... }) @@ -286,6 +243,8 @@ verifier = Verifier( Dynamically determine the current branch of the provider, see if there is a matching pact for that branch. +`matchingBranch` - Returns the pacts for providers configured branch property in the verification task. Normally covered by contract_requiring_verification_published event + corresponding webhoo + { - options.ConsumerVersionSelectors(new ConsumerVersionSelector { MatchingBranch = true }, // Returns the pacts for providers configured branch property in the verification task. Normally covered by contract_requiring_verification_published event + corresponding webhook - new ConsumerVersionSelector { DeployedOrReleased = true } // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment. - new ConsumerVersionSelector { MainBranch = true }, // (recommended) - Returns the pacts for consumers configured mainBranch property + options.ConsumerVersionSelectors(new ConsumerVersionSelector { MatchingBranch = true } + new ConsumerVersionSelector { DeployedOrReleased = true } + new ConsumerVersionSelector { MainBranch = true }, ) .PublishResults(version, results => { @@ -421,13 +380,13 @@ verifier = Verifier( pact.VerifyProvider(t, types.VerifyRequest{ ConsumerVersionSelectors: []types.ConsumerVersionSelector{ types.ConsumerVersionSelector{ - MatchingBranch: true, // Returns the pacts for providers configured branch property in the verification task. Normally covered by contract_requiring_verification_published event + corresponding webhook + MatchingBranch: true, }, types.ConsumerVersionSelector{ - MainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property + MainBranch: true, }, types.ConsumerVersionSelector{ - DeployedOrReleased: true, // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment. + DeployedOrReleased: true, }, }, // ... @@ -462,13 +421,13 @@ const verificationOptions = { // .... consumerVersionSelectors: [ { - mainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property + mainBranch: true, }, { - deployed: 'test', // only the latest deployed version to test + deployed: 'test', }, { - deployedOrReleased: 'production', // all deployed or released versions in production + deployedOrReleased: 'production', consumer: 'my-mobile-consumer' }, ], }; @@ -482,9 +441,9 @@ const verificationOptions = { @au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors public static SelectorBuilder consumerVersionSelectors() { return new SelectorBuilder() - .mainBranch(); // (recommended) - Returns the pacts for consumers configured mainBranch property - .deployedTo('test'); // only the latest deployed version to test - .environment('production') // all deployed or released versions in production + .mainBranch(); + .deployedTo('test'); + .rawSelectorJson('{ "deployedOrReleased": "production", "consumer": "my-mobile-consumer" }') } ``` @@ -502,9 +461,9 @@ pact { fromPactBroker { withSelectors { - mainBranch() // (recommended) - Returns the pacts for consumers configured mainBranch property - deployedTo('test') // only the latest deployed version to test - environment('production') // all deployed or released versions in production + mainBranch() + deployedTo('test') + rawSelectorJson('{ "deployedOrReleased": "production", "consumer": "my-mobile-consumer" }') } } } @@ -521,9 +480,9 @@ Pact.service_provider "Your provider" do honours_pacts_from_pact_broker do pact_broker_base_url "..." consumer_version_selectors [ - { mainBranch: true }, # (recommended) - Returns the pacts for consumers configured mainBranch property - { deployed: "test" }, # only the latest deployed version to test - { environment: "production" } # all deployed or released versions in production + { mainBranch: true }, + { deployed: "test" }, + { deployedOrReleased: "production", consumer: "my-mobile-consumer" } ] end end @@ -538,9 +497,9 @@ verifier = Verifier( provider="Your provider", broker_url="...", consumer_version_selectors=[ - {"mainBranch": True}, # (recommended) - Returns the pacts for consumers configured mainBranch property - {"deployed": "test"}, # only the latest deployed version to test - {"environment": "production"}, # all deployed or released versions in production + {"mainBranch": True}, + {"deployed": "test"}, + {"deployedOrReleased": "production", consumer: "my-mobile-consumer"} ], # ... ) @@ -555,9 +514,9 @@ verifier = Verifier( verifier.ServiceProvider("My Provider", this.fixture.ServerUri) .WithPactBrokerSource(new Uri("https://broker.example.org"), options => { - options.ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true }, // (recommended) - Returns the pacts for consumers configured mainBranch property - new ConsumerVersionSelector { Deployed = true, Environment = "test" }, // only the latest deployed version to test - new ConsumerVersionSelector { Released = true, Deployed = true, Environment = "production" }, // all deployed or released versions in production + options.ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true }, + new ConsumerVersionSelector { Deployed = true, Environment = "test" }, + new ConsumerVersionSelector { Released = true, Deployed = true, Environment = "production", Consumer: "my-mobile-consumer" } ) .PublishResults(version, results => { @@ -577,13 +536,14 @@ verifier = Verifier( pact.VerifyProvider(t, types.VerifyRequest{ ConsumerVersionSelectors: []types.ConsumerVersionSelector{ types.ConsumerVersionSelector{ - MainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property + MainBranch: true, }, types.ConsumerVersionSelector{ Deployed: "test", // only the latest deployed version to test }, types.ConsumerVersionSelector{ - Environment: "production", // all deployed or released versions in production + DeployedOrReleased: "production", + Consumer: "my-mobile-consumer" }, }, // ... @@ -618,16 +578,16 @@ const verificationOptions = { // .... consumerVersionSelectors: [ { - mainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property + mainBranch: true, }, { - deployed: 'test', // Verify the latest deployed `test` version of all consumers + deployed: 'test', }, { - deployed: 'production', // Verify the latest deployed `production` version of all consumers + deployed: 'production', }, { - deployedOrReleased: 'production', // Verify all deployed or released `production` versions of my-mobile-consumer + deployedOrReleased: 'production', consumer: 'my-mobile-consumer' }, ], @@ -642,10 +602,10 @@ const verificationOptions = { @au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors public static SelectorBuilder consumerVersionSelectors() { return new SelectorBuilder() - .mainBranch(); // (recommended) - Returns the pacts for consumers configured mainBranch property - .deployedTo('test'); // Verify the latest deployed `test` version of all consumers - .deployedTo('production'); // Verify the latest deployed `production` version of all consumers - .rawSelectorJson('{ "deployedOrReleased": "production", "consumer": "my-mobile-consumer" }') // Verify all deployed or released `production` versions of my-mobile-consumer + .mainBranch(); + .deployedTo('test'); + .deployedTo('production'); + .rawSelectorJson('{ "deployedOrReleased": "production", "consumer": "my-mobile-consumer" }') } ``` @@ -663,10 +623,10 @@ pact { fromPactBroker { withSelectors { - mainBranch() // (recommended) - Returns the pacts for consumers configured mainBranch property - deployedTo('test') // Verify the latest deployed `test` version of all consumers - deployedTo('production') // Verify the latest deployed `production` version of all consumers - rawSelectorJson('{ "deployedOrReleased": "production", "consumer": "my-mobile-consumer" }') // Verify all deployed or released `production` versions of my-mobile-consumer + mainBranch() + deployedTo('test') + deployedTo('production') + rawSelectorJson('{ "deployedOrReleased": "production", "consumer": "my-mobile-consumer" }') } } } @@ -683,10 +643,10 @@ Pact.service_provider "Your provider" do honours_pacts_from_pact_broker do pact_broker_base_url "..." consumer_version_selectors [ - { mainBranch: true }, # (recommended) - Returns the pacts for consumers configured mainBranch property - { deployed: "test" }, # Verify the latest deployed `test` version of all consumers - { deployed: "production" }, # Verify the latest deployed `production` version of all consumers - { deployedOrReleased: "production", consumer: "my-mobile-consumer" } # Verify all deployed or released `production` versions of my-mobile-consumer + { mainBranch: true }, + { deployed: "test" }, + { deployed: "production" }, + { deployedOrReleased: "production", consumer: "my-mobile-consumer" } ] end end @@ -701,10 +661,10 @@ verifier = Verifier( provider="Your provider", broker_url="...", consumer_version_selectors=[ - {"mainBranch": True}, # (recommended) - Returns the pacts for consumers configured mainBranch property - {"deployed": "test"}, # Verify the latest deployed `test` version of all consumers - {"deployed": "production"}, # Verify the latest deployed `production` version of all consumers - {"environment": "production", "consumer": "my-mobile-consumer" }, # Verify all deployed or released `production` versions of my-mobile-consumer + {"mainBranch": True}, + {"deployed": "test"}, + {"deployed": "production"}, + {"deployedOrReleased": "production", "consumer": "my-mobile-consumer" }, ], # ... ) @@ -719,10 +679,10 @@ verifier = Verifier( verifier.ServiceProvider("My Provider", this.fixture.ServerUri) .WithPactBrokerSource(new Uri("https://broker.example.org"), options => { - options.ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true }, // (recommended) - Returns the pacts for consumers configured mainBranch property - new ConsumerVersionSelector { Deployed = true, Environment = "test" }, // Verify the latest deployed `test` version of all consumers - new ConsumerVersionSelector { Deployed = true, Environment = "production" }, // Verify the latest deployed `production` version of all consumers - new ConsumerVersionSelector { Released = true, Deployed = true, Environment = "production", Consumer = "my-mobile-consumer" }, // Verify all deployed or released `production` versions of my-mobile-consumer + options.ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true }, + new ConsumerVersionSelector { Deployed = true, Environment = "test" }, + new ConsumerVersionSelector { Deployed = true, Environment = "production" }, + new ConsumerVersionSelector { Released = true, Deployed = true, Environment = "production", Consumer = "my-mobile-consumer" }, ) .PublishResults(version, results => { @@ -742,17 +702,17 @@ verifier = Verifier( pact.VerifyProvider(t, types.VerifyRequest{ ConsumerVersionSelectors: []types.ConsumerVersionSelector{ types.ConsumerVersionSelector{ - MainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property + MainBranch: true, }, types.ConsumerVersionSelector{ - Deployed: "test", // Verify the latest deployed `test` version of all consumers + Deployed: "test", }, types.ConsumerVersionSelector{ - Deployed: "production", // Verify the latest deployed `production` version of all consumers + Deployed: "production", }, types.ConsumerVersionSelector{ - Environment: "production", // Verify all deployed or released `production` versions of my-mobile-consumer - Consumer: "my-mobile-consumer", + DeployedOrReleased: "production", + Consumer: "my-mobile-consumer", }, }, // ... @@ -794,10 +754,10 @@ const verificationOptions = { // .... consumerVersionSelectors: [ { - mainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property + mainBranch: true, }, { - deployedOrReleased: true, // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment. + deployedOrReleased: true, }, ], }; @@ -811,8 +771,8 @@ const verificationOptions = { @au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors public static SelectorBuilder consumerVersionSelectors() { return new SelectorBuilder() - .mainBranch(); // (recommended) - Returns the pacts for consumers configured mainBranch property - .deployedOrReleased(); // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment. + .mainBranch(); + .deployedOrReleased(); } ``` @@ -830,8 +790,8 @@ pact { fromPactBroker { withSelectors { - mainBranch() // (recommended) - Returns the pacts for consumers configured mainBranch property - deployedOrReleased() // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment. + mainBranch() + deployedOrReleased() } } } @@ -848,8 +808,8 @@ Pact.service_provider "Your provider" do honours_pacts_from_pact_broker do pact_broker_base_url "..." consumer_version_selectors [ - { mainBranch: true }, # (recommended) - Returns the pacts for consumers configured mainBranch property - { deployedOrReleased: true }, # (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment. + { mainBranch: true }, + { deployedOrReleased: true } ] end end @@ -864,8 +824,8 @@ verifier = Verifier( provider="Your provider", broker_url="...", consumer_version_selectors=[ - {"mainBranch": True}, # (recommended) - Returns the pacts for consumers configured mainBranch property - {"deployedOrReleased": True}, # (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment. + {"mainBranch": True}, + {"deployedOrReleased": True}, ], # ... ) @@ -880,8 +840,8 @@ verifier = Verifier( verifier.ServiceProvider("My Provider", this.fixture.ServerUri) .WithPactBrokerSource(new Uri("https://broker.example.org"), options => { - options.ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true }, // (recommended) - Returns the pacts for consumers configured mainBranch property - new ConsumerVersionSelector { DeployedOrReleased = true } // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment. + options.ConsumerVersionSelectors(new ConsumerVersionSelector { MainBranch = true }, + new ConsumerVersionSelector { DeployedOrReleased = true } ) .PublishResults(version, results => { @@ -901,10 +861,10 @@ verifier = Verifier( pact.VerifyProvider(t, types.VerifyRequest{ ConsumerVersionSelectors: []types.ConsumerVersionSelector{ types.ConsumerVersionSelector{ - MainBranch: true, // (recommended) - Returns the pacts for consumers configured mainBranch property + MainBranch: true, }, types.ConsumerVersionSelector{ - DeployedOrReleased: true, // (recommended) - Returns the pacts for all versions of the consumer that are currently deployed or released and currently supported in any environment. + DeployedOrReleased: true, }, }, // ...