From a37409b2357c83676e46224e94323c465957e332 Mon Sep 17 00:00:00 2001 From: Praveen Erode Mohanasundaram Date: Fri, 27 May 2022 22:15:52 +0100 Subject: [PATCH] fix: providerVersionBranch for pending pacts --- .../pact/core/pactbroker/PactBrokerClient.kt | 24 ++++---- .../pactbroker/PactBrokerClientSpec.groovy | 32 +++++------ .../broker/PactBrokerClientPactSpec.groovy | 10 ++-- .../provider/gradle/GradleProviderInfo.kt | 9 +-- .../gradle/PactBrokerConsumerConfig.kt | 2 +- .../gradle/GradleProviderInfoSpec.groovy | 12 ++-- .../junit/loader/PactBrokerLoaderSpec.groovy | 56 +++++++++---------- .../junitsupport/loader/PactBroker.java | 2 +- .../dius/pact/provider/PactBrokerOptions.kt | 6 +- .../au/com/dius/pact/provider/ProviderInfo.kt | 15 ++--- .../junitsupport/loader/PactBrokerLoader.kt | 19 ++++--- .../pact/provider/ProviderInfoSpec.groovy | 20 +++---- 12 files changed, 104 insertions(+), 103 deletions(-) diff --git a/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt b/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt index eb3053b098..685eb49ce3 100644 --- a/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt +++ b/core/pactbroker/src/main/kotlin/au/com/dius/pact/core/pactbroker/PactBrokerClient.kt @@ -158,7 +158,7 @@ interface IPactBrokerClient { providerName: String, selectors: List, providerTags: List = emptyList(), - providerBranches: List = emptyList(), + providerBranch: String?, enablePending: Boolean = false, includeWipPactsSince: String? ): Result, Exception> @@ -227,7 +227,7 @@ interface IPactBrokerClient { fun uploadPactFile(pactFile: File, version: String, tags: List): Result /** - * Uploads the given pact file to the broker and applies any tags/branches + * Uploads the given pact file to the broker and applies any tags/Branch */ fun uploadPactFile(pactFile: File, config: PublishConfiguration): Result } @@ -300,7 +300,7 @@ open class PactBrokerClient( providerName: String, selectors: List, providerTags: List, - providerBranches: List, + providerBranch: String?, enablePending: Boolean, includeWipPactsSince: String? ): Result, Exception> { @@ -316,9 +316,9 @@ open class PactBrokerClient( return if (pactsForVerification != null) { val selectorsRawJson = System.getProperty("pactbroker.consumerversionselectors.rawjson") if(!selectorsRawJson.isNullOrBlank()){ - fetchPactsUsingNewEndpointRaw(selectorsRawJson, enablePending, providerTags, providerBranches, includeWipPactsSince, halClient, pactsForVerification, providerName) + fetchPactsUsingNewEndpointRaw(selectorsRawJson, enablePending, providerTags, providerBranch, includeWipPactsSince, halClient, pactsForVerification, providerName) } else { - fetchPactsUsingNewEndpointTyped(selectors, enablePending, providerTags, providerBranches, includeWipPactsSince, halClient, pactsForVerification, providerName) + fetchPactsUsingNewEndpointTyped(selectors, enablePending, providerTags, providerBranch, includeWipPactsSince, halClient, pactsForVerification, providerName) } } else { handleWith { @@ -343,34 +343,34 @@ open class PactBrokerClient( selectorsTyped: List, enablePending: Boolean, providerTags: List, - providerBranches: List, + providerBranch: String?, includeWipPactsSince: String?, halClient: IHalClient, pactsForVerification: String, providerName: String ): Result, Exception> { val selectorsJson = jsonArray(selectorsTyped.map { it.toJson() }) - return fetchPactsUsingNewEndpoint(selectorsJson, enablePending, providerTags, providerBranches, includeWipPactsSince, halClient, pactsForVerification, providerName) + return fetchPactsUsingNewEndpoint(selectorsJson, enablePending, providerTags, providerBranch, includeWipPactsSince, halClient, pactsForVerification, providerName) } private fun fetchPactsUsingNewEndpointRaw( selectorsRaw: String, enablePending: Boolean, providerTags: List, - providerBranches: List, + providerBranch: String?, includeWipPactsSince: String?, halClient: IHalClient, pactsForVerification: String, providerName: String ): Result, Exception> { - return fetchPactsUsingNewEndpoint(JsonParser.parseString(selectorsRaw), enablePending, providerTags, providerBranches, includeWipPactsSince, halClient, pactsForVerification, providerName) + return fetchPactsUsingNewEndpoint(JsonParser.parseString(selectorsRaw), enablePending, providerTags, providerBranch, includeWipPactsSince, halClient, pactsForVerification, providerName) } private fun fetchPactsUsingNewEndpoint( selectorsJson: JsonValue, enablePending: Boolean, providerTags: List, - providerBranches: List, + providerBranch: String?, includeWipPactsSince: String?, halClient: IHalClient, pactsForVerification: String, @@ -384,7 +384,9 @@ open class PactBrokerClient( body["includePendingStatus"] = enablePending if (enablePending) { body["providerVersionTags"] = jsonArray(providerTags) - body["providerVersionBranches"] = jsonArray(providerBranches) + if (providerBranch.isNotEmpty()) { + body["providerVersionBranch"] = providerBranch + } if (includeWipPactsSince.isNotEmpty()) { body["includeWipPactsSince"] = includeWipPactsSince } diff --git a/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/PactBrokerClientSpec.groovy b/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/PactBrokerClientSpec.groovy index 0cf4cc5ce1..ddd50eb2af 100644 --- a/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/PactBrokerClientSpec.groovy +++ b/core/pactbroker/src/test/groovy/au/com/dius/pact/core/pactbroker/PactBrokerClientSpec.groovy @@ -95,7 +95,7 @@ class PactBrokerClientSpec extends Specification { } when: - def consumers = client.fetchConsumersWithSelectors('provider', [], [], [], false, '').value + def consumers = client.fetchConsumersWithSelectors('provider', [], [], '', false, '').value then: consumers == [] @@ -113,7 +113,7 @@ class PactBrokerClientSpec extends Specification { } when: - def consumers = client.fetchConsumersWithSelectors('provider', [], [], [], false, '').value + def consumers = client.fetchConsumersWithSelectors('provider', [], [], '', false, '').value then: consumers != [] @@ -134,7 +134,7 @@ class PactBrokerClientSpec extends Specification { when: def consumers = client.fetchConsumersWithSelectors('provider', - [ new ConsumerVersionSelector('tag', true, null, null) ], [], [], false, '').value + [ new ConsumerVersionSelector('tag', true, null, null) ], [], '', false, '').value then: consumers != [] @@ -156,7 +156,7 @@ class PactBrokerClientSpec extends Specification { when: def consumers = client.fetchConsumersWithSelectors('provider', [ new ConsumerVersionSelector('tag', true, null, null), - new ConsumerVersionSelector('anotherTag', true, null, null) ], [], [], false, '').value + new ConsumerVersionSelector('anotherTag', true, null, null) ], [], '', false, '').value then: consumers.size() == 2 @@ -185,7 +185,7 @@ class PactBrokerClientSpec extends Specification { when: def consumers = client.fetchConsumersWithSelectors('provider', - [ new ConsumerVersionSelector('tag', true, null, null) ], [], [], false, '').value + [ new ConsumerVersionSelector('tag', true, null, null) ], [], '', false, '').value then: consumers != [] @@ -206,7 +206,7 @@ class PactBrokerClientSpec extends Specification { when: def consumers = client.fetchConsumersWithSelectors('provider', - [ new ConsumerVersionSelector('tag', true, null, null) ], [], [], false, '').value + [ new ConsumerVersionSelector('tag', true, null, null) ], [], '', false, '').value then: consumers == [] @@ -399,7 +399,7 @@ class PactBrokerClientSpec extends Specification { ''') when: - def result = client.fetchConsumersWithSelectors('provider', selectors, [], [], false, '') + def result = client.fetchConsumersWithSelectors('provider', selectors, [], '', false, '') then: 1 * halClient.navigate() >> halClient @@ -432,7 +432,7 @@ class PactBrokerClientSpec extends Specification { ''') when: - def result = client.fetchConsumersWithSelectors('provider', [], [], [], false, '') + def result = client.fetchConsumersWithSelectors('provider', [], [], '', false, '') then: 1 * halClient.navigate() >> halClient @@ -450,7 +450,7 @@ class PactBrokerClientSpec extends Specification { } when: - def result = client.fetchConsumersWithSelectors('provider', [], [], [], false, '') + def result = client.fetchConsumersWithSelectors('provider', [], [], '', false, '') then: 1 * halClient.navigate() >> halClient @@ -478,7 +478,7 @@ class PactBrokerClientSpec extends Specification { } ''') when: - def result = client.fetchConsumersWithSelectors('provider', selectors, [], [], false, '2020-24-06') + def result = client.fetchConsumersWithSelectors('provider', selectors, [], '', false, '2020-24-06') then: 1 * halClient.navigate() >> halClient @@ -495,7 +495,7 @@ class PactBrokerClientSpec extends Specification { } def selectors = [ new ConsumerVersionSelector('DEV', true, null, null) ] def json = '{"consumerVersionSelectors":[{"latest":true,"tag":"DEV"}],"includePendingStatus":true,' + - '"includeWipPactsSince":"2020-24-06","providerVersionBranches":[],"providerVersionTags":[]}' + '"includeWipPactsSince":"2020-24-06","providerVersionTags":[]}' def jsonResult = JsonParser.INSTANCE.parseString(''' { "_embedded": { @@ -505,7 +505,7 @@ class PactBrokerClientSpec extends Specification { } ''') when: - def result = client.fetchConsumersWithSelectors('provider', selectors, [], [], true, '2020-24-06') + def result = client.fetchConsumersWithSelectors('provider', selectors, [], '', true, '2020-24-06') then: 1 * halClient.navigate() >> halClient @@ -524,7 +524,7 @@ class PactBrokerClientSpec extends Specification { when: def result = client.fetchConsumersWithSelectors('provider', - [ new ConsumerVersionSelector(null, true, 'consumer', null) ], [], [], false, '') + [ new ConsumerVersionSelector(null, true, 'consumer', null) ], [], '', false, '') then: 1 * halClient.navigate() >> halClient @@ -580,7 +580,7 @@ class PactBrokerClientSpec extends Specification { ] when: - def result = client.fetchConsumersWithSelectors('provider', selectors, [], [], false, '') + def result = client.fetchConsumersWithSelectors('provider', selectors, [], '', false, '') then: 1 * halClient.navigate() >> halClient @@ -604,7 +604,7 @@ class PactBrokerClientSpec extends Specification { ] when: - def result = client.fetchConsumersWithSelectors('provider', selectors, [], [], false, '') + def result = client.fetchConsumersWithSelectors('provider', selectors, [], '', false, '') then: 1 * halClient.navigate() >> { @@ -664,7 +664,7 @@ class PactBrokerClientSpec extends Specification { def expectedJson = '{"consumerVersionSelectors":[{"mainBranch":true}],"includePendingStatus":false}' when: - client.fetchConsumersWithSelectors('provider', [], [], [], false, '') + client.fetchConsumersWithSelectors('provider', [], [], '', false, '') then: 1 * halClient.postJson('pb:provider-pacts-for-verification', _, expectedJson) diff --git a/pact-publish/src/test/groovy/broker/PactBrokerClientPactSpec.groovy b/pact-publish/src/test/groovy/broker/PactBrokerClientPactSpec.groovy index 6cb707a7d2..0ff7ba40d3 100644 --- a/pact-publish/src/test/groovy/broker/PactBrokerClientPactSpec.groovy +++ b/pact-publish/src/test/groovy/broker/PactBrokerClientPactSpec.groovy @@ -918,7 +918,7 @@ class PactBrokerClientPactSpec extends Specification { def result = pactBroker.runTest { server, context -> def consumerPacts = pactBrokerClient.fetchConsumersWithSelectors('Activity Service', [ new ConsumerVersionSelector('test', true, null, null) - ], [], [], false, '') + ], [], '', false, '') assert consumerPacts instanceof Ok assert consumerPacts.value.size == 2 assert !consumerPacts.value[0].pending @@ -962,7 +962,7 @@ class PactBrokerClientPactSpec extends Specification { } ]) providerVersionTags(['tag']) - providerVersionBranches(['master']) + providerVersionBranch 'master' includePendingStatus true } willRespondWith(status: 200) @@ -1032,7 +1032,7 @@ class PactBrokerClientPactSpec extends Specification { def result = pactBroker.runTest { server, context -> def consumerPacts = pactBrokerClient.fetchConsumersWithSelectors('Activity Service', [ new ConsumerVersionSelector('test', true, null, null) - ], ['tag'], ['master'], true, '') + ], ['tag'], 'master', true, '') assert consumerPacts instanceof Ok assert consumerPacts.value.size == 2 assert !consumerPacts.value[0].pending @@ -1076,7 +1076,7 @@ class PactBrokerClientPactSpec extends Specification { } ]) providerVersionTags(['tag']) - providerVersionBranches(['master']) + providerVersionBranch 'master' includePendingStatus true includeWipPactsSince '2020-06-24' } @@ -1157,7 +1157,7 @@ class PactBrokerClientPactSpec extends Specification { def result = pactBroker.runTest { server, context -> def consumerPacts = pactBrokerClient.fetchConsumersWithSelectors('Activity Service', [ new ConsumerVersionSelector('test', true, null, null) - ], ['tag'], ['master'], true, '2020-06-24') + ], ['tag'], 'master', true, '2020-06-24') assert consumerPacts instanceof Ok assert consumerPacts.value.size == 2 assert !consumerPacts.value[0].wip diff --git a/provider/gradle/src/main/kotlin/au/com/dius/pact/provider/gradle/GradleProviderInfo.kt b/provider/gradle/src/main/kotlin/au/com/dius/pact/provider/gradle/GradleProviderInfo.kt index 3fa7cda939..20c1711ed4 100644 --- a/provider/gradle/src/main/kotlin/au/com/dius/pact/provider/gradle/GradleProviderInfo.kt +++ b/provider/gradle/src/main/kotlin/au/com/dius/pact/provider/gradle/GradleProviderInfo.kt @@ -104,12 +104,13 @@ open class GradleProviderInfo(name: String, val project: Project) : ProviderInfo ConfigureUtil.configure(closure, brokerConfig!!) val pending = brokerConfig!!.enablePending ?: false - if (pending && (brokerConfig!!.providerTags.isNullOrEmpty() || - brokerConfig!!.providerTags!!.any { it.trim().isEmpty() }) && (brokerConfig!!.providerBranches.isNullOrEmpty() || - brokerConfig!!.providerBranches!!.any { it.trim().isEmpty() })) { + if (pending + && (brokerConfig!!.providerTags.isNullOrEmpty() || brokerConfig!!.providerTags!!.any { it.trim().isEmpty() }) + && (brokerConfig!!.providerBranch.isNullOrBlank()) + ) { throw GradleScriptException( """ - |No providerTags or providerBranches: To use the pending pacts feature, you need to provide the list of provider names for the provider application version that will be published with the verification results. + |No providerTags or providerBranch: To use the pending pacts feature, you need to provide the list of provider names for the provider application version that will be published with the verification results. | |For instance: | diff --git a/provider/gradle/src/main/kotlin/au/com/dius/pact/provider/gradle/PactBrokerConsumerConfig.kt b/provider/gradle/src/main/kotlin/au/com/dius/pact/provider/gradle/PactBrokerConsumerConfig.kt index c564ae69a6..d502812cae 100644 --- a/provider/gradle/src/main/kotlin/au/com/dius/pact/provider/gradle/PactBrokerConsumerConfig.kt +++ b/provider/gradle/src/main/kotlin/au/com/dius/pact/provider/gradle/PactBrokerConsumerConfig.kt @@ -9,7 +9,7 @@ data class PactBrokerConsumerConfig @JvmOverloads constructor( var selectors: List? = listOf(), var enablePending: Boolean? = false, var providerTags: List? = listOf(), - var providerBranches: List? = listOf() + var providerBranch: String? = "" ) { companion object { @JvmStatic diff --git a/provider/gradle/src/test/groovy/au/com/dius/pact/provider/gradle/GradleProviderInfoSpec.groovy b/provider/gradle/src/test/groovy/au/com/dius/pact/provider/gradle/GradleProviderInfoSpec.groovy index cc02b05bb1..2cd5e3404e 100644 --- a/provider/gradle/src/test/groovy/au/com/dius/pact/provider/gradle/GradleProviderInfoSpec.groovy +++ b/provider/gradle/src/test/groovy/au/com/dius/pact/provider/gradle/GradleProviderInfoSpec.groovy @@ -33,16 +33,16 @@ class GradleProviderInfoSpec extends Specification { selectors = latestTags('test') enablePending = true providerTags = ['master'] - providerBranches = ['master'] + providerBranch = 'master' } then: provider.brokerConfig == new PactBrokerConsumerConfig([new ConsumerVersionSelector('test', true, null, null)], - true, ['master'], ['master']) + true, ['master'], 'master') } @Unroll - def 'fromPactBroker throws an exception if pending pacts is enabled but there are no provider tags or provider branches'() { + def 'fromPactBroker throws an exception if pending pacts is enabled but there are no provider tags or provider branch'() { given: def provider = new GradleProviderInfo('provider', Mock(Project)) @@ -51,18 +51,18 @@ class GradleProviderInfoSpec extends Specification { selectors = latestTags('test') enablePending = true providerTags = tags - providerBranches = branches + providerBranch = branch } then: def ex = thrown(GradleScriptException) - ex.message.trim().startsWith('No providerTags or providerBranches: To use the pending pacts feature, you need to provide the list of ' + + ex.message.trim().startsWith('No providerTags or providerBranch: To use the pending pacts feature, you need to provide the list of ' + 'provider names') where: tags << [null, [], ['']] - branches << [null, [], ['']] + branch << [null, ' ', ''] } def 'supports specifying a fallback tag'() { diff --git a/provider/junit/src/test/groovy/au/com/dius/pact/provider/junit/loader/PactBrokerLoaderSpec.groovy b/provider/junit/src/test/groovy/au/com/dius/pact/provider/junit/loader/PactBrokerLoaderSpec.groovy index e824539bb5..45eedbb269 100644 --- a/provider/junit/src/test/groovy/au/com/dius/pact/provider/junit/loader/PactBrokerLoaderSpec.groovy +++ b/provider/junit/src/test/groovy/au/com/dius/pact/provider/junit/loader/PactBrokerLoaderSpec.groovy @@ -42,7 +42,7 @@ class PactBrokerLoaderSpec extends Specification { private List consumers private String enablePendingPacts private List providerTags - private List providerBranches + private String providerBranch private String includeWipPactsSince private IPactBrokerClient brokerClient private Pact mockPact @@ -60,7 +60,7 @@ class PactBrokerLoaderSpec extends Specification { consumers = [] enablePendingPacts = '' providerTags = [] - providerBranches = [] + providerBranch = '' includeWipPactsSince = '' brokerClient = Mock(IPactBrokerClient) { getOptions() >> [:] @@ -75,7 +75,7 @@ class PactBrokerLoaderSpec extends Specification { pactBrokerLoader = { boolean failIfNoPactsFound = true -> IPactBrokerClient client = brokerClient def loader = new PactBrokerLoader(host, port, protocol, tags, consumerVersionSelectors, consumers, - failIfNoPactsFound, null, null, valueResolver, enablePendingPacts, providerTags, providerBranches, + failIfNoPactsFound, null, null, valueResolver, enablePendingPacts, providerTags, providerBranch, includeWipPactsSince, url, enableInsecureTls) { @Override IPactBrokerClient newPactBrokerClient(URI url, ValueResolver resolver) { @@ -299,7 +299,7 @@ class PactBrokerLoaderSpec extends Specification { then: brokerClient.getOptions() >> [:] - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) 0 * brokerClient._ result.size() == 3 } @@ -327,7 +327,7 @@ class PactBrokerLoaderSpec extends Specification { then: brokerClient.getOptions() >> [:] - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) 0 * brokerClient._ result.size() == 3 } @@ -351,7 +351,7 @@ class PactBrokerLoaderSpec extends Specification { def result = pactBrokerLoader().load('test') then: - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) result.size() == 2 } @@ -375,7 +375,7 @@ class PactBrokerLoaderSpec extends Specification { def result = pactBrokerLoader().load('test') then: - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) result.size() == 2 } @@ -389,7 +389,7 @@ class PactBrokerLoaderSpec extends Specification { then: result.size() == 1 - 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], '', false, '') >> new Ok(expected) } @SuppressWarnings('GStringExpressionWithinString') @@ -410,7 +410,7 @@ class PactBrokerLoaderSpec extends Specification { then: 1 * brokerClient.getOptions() >> [:] - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) 0 * brokerClient._ result.size() == 1 } @@ -438,7 +438,7 @@ class PactBrokerLoaderSpec extends Specification { then: 1 * brokerClient.getOptions() >> [:] - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) 0 * brokerClient._ result.size() == 1 } @@ -463,7 +463,7 @@ class PactBrokerLoaderSpec extends Specification { def result = pactBrokerLoader().load('test') then: - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) result.size() == 2 } @@ -502,7 +502,7 @@ class PactBrokerLoaderSpec extends Specification { then: brokerClient.getOptions() >> [:] - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) 0 * brokerClient._ result.size() == 3 } @@ -531,7 +531,7 @@ class PactBrokerLoaderSpec extends Specification { then: brokerClient.getOptions() >> [:] - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) 0 * brokerClient._ result.size() == 4 } @@ -559,7 +559,7 @@ class PactBrokerLoaderSpec extends Specification { then: brokerClient.getOptions() >> [:] - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) 0 * brokerClient._ result.size() == 3 } @@ -579,7 +579,7 @@ class PactBrokerLoaderSpec extends Specification { then: brokerClient.getOptions() >> [:] - 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], '', false, '') >> new Ok(expected) 0 * brokerClient._ result.size() == 4 } @@ -601,7 +601,7 @@ class PactBrokerLoaderSpec extends Specification { then: brokerClient.getOptions() >> [:] - 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], '', false, '') >> new Ok(expected) 0 * brokerClient._ result.size() == 4 } @@ -627,7 +627,7 @@ class PactBrokerLoaderSpec extends Specification { then: brokerClient.getOptions() >> [:] - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) 0 * brokerClient._ result.size() == 3 } @@ -649,7 +649,7 @@ class PactBrokerLoaderSpec extends Specification { then: brokerClient.getOptions() >> [:] - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) 0 * brokerClient._ result.size() == 3 } @@ -675,7 +675,7 @@ class PactBrokerLoaderSpec extends Specification { then: result == [] - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok([]) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok([]) } @Issue('#1208') @@ -702,7 +702,7 @@ class PactBrokerLoaderSpec extends Specification { then: valueResolver.propertyDefined('pactbroker.consumerversionselectors.tags') >> true valueResolver.resolveValue('pactbroker.consumerversionselectors.tags') >> 'one,two,three' - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) } def 'Loads pacts with consumer version selectors when consumer version selectors and tags are both present'() { @@ -722,7 +722,7 @@ class PactBrokerLoaderSpec extends Specification { then: brokerClient.getOptions() >> [:] - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) 0 * brokerClient._ result.size() == 4 } @@ -745,7 +745,7 @@ class PactBrokerLoaderSpec extends Specification { then: result == [] - 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], [], false, '') >> new Ok([]) + 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], '', false, '') >> new Ok([]) } def 'Does not loads wip pacts when pending is false'() { @@ -770,7 +770,7 @@ class PactBrokerLoaderSpec extends Specification { then: brokerClient.getOptions() >> [:] - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], [], false, '') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, [], '', false, '') >> new Ok(expected) 0 * brokerClient._ result.size() == 3 } @@ -799,7 +799,7 @@ class PactBrokerLoaderSpec extends Specification { then: brokerClient.getOptions() >> [:] - 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, ['dev'], [], true, '2020-06-25') >> new Ok(expected) + 1 * brokerClient.fetchConsumersWithSelectors('test', selectors, ['dev'], '', true, '2020-06-25') >> new Ok(expected) 0 * brokerClient._ result.size() == 3 } @@ -826,7 +826,7 @@ class PactBrokerLoaderSpec extends Specification { pactBrokerLoader().load('test') then: - 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], [], false, '') >> new Ok([]) + 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], '', false, '') >> new Ok([]) noExceptionThrown() } @@ -850,7 +850,7 @@ class PactBrokerLoaderSpec extends Specification { then: result == [] - 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], [], false, '') >> new Ok([]) + 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], '', false, '') >> new Ok([]) } def 'configured from annotation with https and no port'() { @@ -875,7 +875,7 @@ class PactBrokerLoaderSpec extends Specification { then: result == [] - 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], [], false, '') >> new Ok([]) + 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], '', false, '') >> new Ok([]) } def 'Auth: Uses no auth if no auth is provided'() { @@ -1352,7 +1352,7 @@ class PactBrokerLoaderSpec extends Specification { pactBrokerLoader().load('test') then: - 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], [], false, '') >> { + 1 * brokerClient.fetchConsumersWithSelectors('test', [], [], '', false, '') >> { throw new InvalidNavigationRequest('PKIX path building failed', new SSLHandshakeException('PKIX path building failed')) } thrown(InvalidNavigationRequest) diff --git a/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/PactBroker.java b/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/PactBroker.java index 7e18219a6b..b5674bfb3a 100644 --- a/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/PactBroker.java +++ b/provider/src/main/java/au/com/dius/pact/provider/junitsupport/loader/PactBroker.java @@ -99,7 +99,7 @@ PactBrokerAuth authentication() default @PactBrokerAuth(username = "${pactbroker /** * Provider Branches to use to evaluate pending pacts */ - String[] providerBranches() default "${pactbroker.providerBranches:}"; + String providerBranch() default "${pactbroker.providerBranch:}"; /** * The earliest date WIP pacts should be included (ex: YYYY-MM-DD). If no date is provided, WIP pacts will not be diff --git a/provider/src/main/kotlin/au/com/dius/pact/provider/PactBrokerOptions.kt b/provider/src/main/kotlin/au/com/dius/pact/provider/PactBrokerOptions.kt index 7f4df5eb6c..c7ff0eef13 100644 --- a/provider/src/main/kotlin/au/com/dius/pact/provider/PactBrokerOptions.kt +++ b/provider/src/main/kotlin/au/com/dius/pact/provider/PactBrokerOptions.kt @@ -11,14 +11,14 @@ data class PactBrokerOptions @JvmOverloads constructor( val enablePending: Boolean = false, /** - * Provider tags. Either this or providerBranches if pending pacts are enabled + * Provider tags. Either this or providerBranch if pending pacts are enabled */ val providerTags: List = listOf(), /** - * Provider branches. Either this or providerTags if pending pacts are enabled + * Provider branch. Either this or providerTags if pending pacts are enabled */ - val providerBranches: List = listOf(), + val providerBranch: String? = null, /** * Only include WIP pacts since the provided date. Dates need to be in ISO format (YYYY-MM-DD). diff --git a/provider/src/main/kotlin/au/com/dius/pact/provider/ProviderInfo.kt b/provider/src/main/kotlin/au/com/dius/pact/provider/ProviderInfo.kt index 05ce97bb31..cedc51ef95 100644 --- a/provider/src/main/kotlin/au/com/dius/pact/provider/ProviderInfo.kt +++ b/provider/src/main/kotlin/au/com/dius/pact/provider/ProviderInfo.kt @@ -78,13 +78,10 @@ open class ProviderInfo @JvmOverloads constructor ( } else { emptyList() } - val providerBranches = if (enablePending) { - options["providerBranches"] as List? - } else { - emptyList() - } + + val providerBranch = Utils.lookupInMap(options, "providerBranch", String::class.java, "") val includePactsSince = Utils.lookupInMap(options, "includeWipPactsSince", String::class.java, "") - val pactBrokerOptions = PactBrokerOptions(enablePending, providerTags.orEmpty(), providerBranches.orEmpty(), + val pactBrokerOptions = PactBrokerOptions(enablePending, providerTags.orEmpty(), providerBranch, includePactsSince, false, PactBrokerOptions.parseAuthSettings(options)) return hasPactsFromPactBrokerWithSelectors(pactBrokerUrl, selectors, pactBrokerOptions) @@ -96,14 +93,14 @@ open class ProviderInfo @JvmOverloads constructor ( selectors: List, options: PactBrokerOptions ): List { - if (options.enablePending && options.providerTags.isEmpty() && options.providerBranches.isEmpty()) { - throw RuntimeException("No providerTags or providerBranches: To use the pending pacts feature, you need to" + + if (options.enablePending && options.providerTags.isEmpty() && options.providerBranch.isNullOrBlank() ) { + throw RuntimeException("No providerTags or providerBranch: To use the pending pacts feature, you need to" + " provide the list of provider names for the provider application version that will be published with the" + " verification results") } val client = pactBrokerClient(pactBrokerUrl, options) val consumersFromBroker = client.fetchConsumersWithSelectors(name, selectors, options.providerTags, - options.providerBranches, options.enablePending, options.includeWipPactsSince) + options.providerBranch, options.enablePending, options.includeWipPactsSince) .map { results -> results.map { ConsumerInfo.from(it) } } return when (consumersFromBroker) { diff --git a/provider/src/main/kotlin/au/com/dius/pact/provider/junitsupport/loader/PactBrokerLoader.kt b/provider/src/main/kotlin/au/com/dius/pact/provider/junitsupport/loader/PactBrokerLoader.kt index 13d8eac59d..8d353fface 100644 --- a/provider/src/main/kotlin/au/com/dius/pact/provider/junitsupport/loader/PactBrokerLoader.kt +++ b/provider/src/main/kotlin/au/com/dius/pact/provider/junitsupport/loader/PactBrokerLoader.kt @@ -55,7 +55,7 @@ open class PactBrokerLoader( valueResolver: ValueResolver? = null, val enablePendingPacts: String = "false", val providerTags: List = emptyList(), - val providerBranches: List = emptyList(), + val providerBranch: String = "", val includeWipPactsSince: String = "", val pactBrokerUrl: String? = null, val enableInsecureTls: String = "false" @@ -80,7 +80,7 @@ open class PactBrokerLoader( null, pactBroker.enablePendingPacts, pactBroker.providerTags.toList(), - pactBroker.providerBranches.toList(), + pactBroker.providerBranch, pactBroker.includeWipPactsSince, pactBroker.url, pactBroker.enableInsecureTls @@ -219,12 +219,13 @@ open class PactBrokerLoader( "$selectors" } val pending = parseExpression(enablePendingPacts, DataType.BOOLEAN, resolver) as Boolean val providerTags = providerTags.flatMap { parseListExpression(it, resolver) }.filter { it.isNotEmpty() } - val providerBranches = providerBranches.flatMap { parseListExpression(it, resolver) }.filter { it.isNotEmpty() } - if (pending && providerTags.none { it.isNotEmpty() } && providerBranches.none { it.isNotEmpty() }) { - throw IllegalArgumentException("Pending pacts feature has been enabled, but no provider tags or branches have " + - "been specified. To use the pending pacts feature, you need to provide the list of provider names for the " + - "provider application version with the providerTags or providerBranches property that will be published with " + - "the verification results.") + val providerBranch = parseExpression(providerBranch, DataType.STRING, resolver) as String + + if (pending && providerTags.none { it.isNotEmpty() } && providerBranch.isNullOrBlank() ) { + throw IllegalArgumentException("Pending pacts feature has been enabled, but no provider tags or branch have" + + " been specified. To use the pending pacts feature, you need to provide the list of provider names for the" + + " provider application version with the providerTags or providerBranch property that will be published with" + + " the verification results.") } val wipSinceDate = if (pending) parseExpression(includeWipPactsSince, DataType.STRING, resolver) as String else "" @@ -233,7 +234,7 @@ open class PactBrokerLoader( val pactBrokerClient = newPactBrokerClient(uriBuilder.build(), resolver) val result = pactBrokerClient.fetchConsumersWithSelectors(providerName, selectors, providerTags, - providerBranches, pending, wipSinceDate) + providerBranch, pending, wipSinceDate) var consumers = when (result) { is Ok -> result.value is Err -> throw result.error diff --git a/provider/src/test/groovy/au/com/dius/pact/provider/ProviderInfoSpec.groovy b/provider/src/test/groovy/au/com/dius/pact/provider/ProviderInfoSpec.groovy index 3622b636da..f4a10ccf62 100644 --- a/provider/src/test/groovy/au/com/dius/pact/provider/ProviderInfoSpec.groovy +++ b/provider/src/test/groovy/au/com/dius/pact/provider/ProviderInfoSpec.groovy @@ -76,7 +76,7 @@ class ProviderInfoSpec extends Specification { def result = providerInfo.hasPactsFromPactBrokerWithSelectors(options, url, selectors) then: - pactBrokerClient.fetchConsumersWithSelectors('TestProvider', selectors, [], [], false, '') >> new Ok([ + pactBrokerClient.fetchConsumersWithSelectors('TestProvider', selectors, [], '', false, '') >> new Ok([ new PactBrokerResult('consumer', '', url, [], [], false, null, false, false, null) ]) result.size == 1 @@ -99,7 +99,7 @@ class ProviderInfoSpec extends Specification { def result = providerInfo.hasPactsFromPactBrokerWithSelectors(options, url, selectors) then: - pactBrokerClient.fetchConsumersWithSelectors('TestProvider', selectors, ['master'], [], true, '') >> new Ok([ + pactBrokerClient.fetchConsumersWithSelectors('TestProvider', selectors, ['master'], '', true, '') >> new Ok([ new PactBrokerResult('consumer', '', url, [], [], true, null, false, false, null) ]) result.size == 1 @@ -107,11 +107,11 @@ class ProviderInfoSpec extends Specification { result[0].pending } - def 'hasPactsFromPactBrokerWithSelectors - does include pending pacts if the option is present and branches are specified'() { + def 'hasPactsFromPactBrokerWithSelectors - does include pending pacts if the option is present and branch is specified'() { given: def options = [ enablePending: true, - providerBranches: ['master'] + providerBranch: 'master' ] def url = 'http://localhost:8080' def selectors = [ @@ -122,7 +122,7 @@ class ProviderInfoSpec extends Specification { def result = providerInfo.hasPactsFromPactBrokerWithSelectors(options, url, selectors) then: - pactBrokerClient.fetchConsumersWithSelectors('TestProvider', selectors, [], ['master'], true, '') >> new Ok([ + pactBrokerClient.fetchConsumersWithSelectors('TestProvider', selectors, [], 'master', true, '') >> new Ok([ new PactBrokerResult('consumer', '', url, [], [], true, null, false, false, null) ]) result.size == 1 @@ -130,7 +130,7 @@ class ProviderInfoSpec extends Specification { result[0].pending } - def 'hasPactsFromPactBrokerWithSelectors - throws an exception if the pending pacts option is present but there is no provider tags or provider branches'() { + def 'hasPactsFromPactBrokerWithSelectors - throws an exception if the pending pacts option is present but there is no provider tags or provider branch'() { given: def options = [ enablePending: true @@ -145,7 +145,7 @@ class ProviderInfoSpec extends Specification { then: def exception = thrown(RuntimeException) - exception.message == 'No providerTags or providerBranches: To use the pending pacts feature, you need to provide the list of ' + + exception.message == 'No providerTags or providerBranch: To use the pending pacts feature, you need to provide the list of ' + 'provider names for the provider application version that will be published with the verification results' } @@ -164,7 +164,7 @@ class ProviderInfoSpec extends Specification { def result = providerInfo.hasPactsFromPactBrokerWithSelectors(options, url, selectors) then: - pactBrokerClient.fetchConsumersWithSelectors('TestProvider', selectors, ['master'], [], true, '') >> new Ok([ + pactBrokerClient.fetchConsumersWithSelectors('TestProvider', selectors, ['master'], '', true, '') >> new Ok([ new PactBrokerResult('consumer', '', url, [], [], false, null, false, false, null) ]) result.size == 1 @@ -188,7 +188,7 @@ class ProviderInfoSpec extends Specification { def result = providerInfo.hasPactsFromPactBrokerWithSelectors(options, url, selectors) then: - pactBrokerClient.fetchConsumersWithSelectors('TestProvider', selectors, ['master'], [], true, '2020-05-23') >> new Ok([ + pactBrokerClient.fetchConsumersWithSelectors('TestProvider', selectors, ['master'], '', true, '2020-05-23') >> new Ok([ new PactBrokerResult('consumer', '', url, [], [], true, null, true, false, null) ]) result.size == 1 @@ -210,7 +210,7 @@ class ProviderInfoSpec extends Specification { then: providerInfo.pactBrokerClient(_, { it.auth == new Auth.BearerAuthentication('123ABC') }) >> pactBrokerClient - pactBrokerClient.fetchConsumersWithSelectors('TestProvider', selectors, [], [], false, '') >> new Ok([ + pactBrokerClient.fetchConsumersWithSelectors('TestProvider', selectors, [], '', false, '') >> new Ok([ new PactBrokerResult('consumer', '', url, [], [], true, null, true, false, null) ]) result.size == 1