From d162857409bc01df4eb69fe402996ca933f381f7 Mon Sep 17 00:00:00 2001 From: anto Date: Wed, 10 Jun 2020 08:56:37 +0100 Subject: [PATCH] fix: #1113 verify all tags and not just the first --- .../pact/core/pactbroker/PactBrokerClient.kt | 2 +- .../pactbroker/PactBrokerClientSpec.groovy | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) 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 abc9869dd3..5e92521c5c 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 @@ -192,7 +192,7 @@ open class PactBrokerClient(val pactBrokerUrl: String, override val options: Map if (selectors.isEmpty()) { fetchConsumers(providerName) } else { - fetchConsumersWithTag(providerName, selectors.first().tag) + selectors.flatMap { fetchConsumersWithTag(providerName, it.tag) } } } } 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 a2c37db623..236fc385c8 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 @@ -116,6 +116,36 @@ class PactBrokerClientSpec extends Specification { consumers.first().source == 'http://bob.com/' } + def 'fetches consumers with more than one tag successfully'() { + given: + def halClient = Mock(IHalClient) + halClient.navigate() >> halClient + halClient.navigate(_, _) >> halClient + halClient.forAll(_, _) >> { args -> args[1].accept([name: 'bob', href: 'http://bob.com/']) } + + def client = Spy(PactBrokerClient, constructorArgs: ['http://pactBrokerUrl']) { + newHalClient() >> halClient + } + + when: + def consumers = client.fetchConsumersWithSelectors('provider', + [ new ConsumerVersionSelector('tag', true), + new ConsumerVersionSelector('anotherTag', true) ], [], false).value + + then: + consumers.size() == 2 + + consumers.first() + consumers.first().name == 'bob' + consumers.first().source == 'http://bob.com/' + consumers.first().tag == 'tag' + + consumers.last() + consumers.last().name == 'bob' + consumers.last().source == 'http://bob.com/' + consumers.last().tag == 'anotherTag' + } + def 'when fetching consumers with specified tag, sets the auth if there is any'() { given: def halClient = Mock(IHalClient)