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)