Skip to content

Commit

Permalink
fix: use the Pact URL to disambiguate Pacts when accumilating results #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed Mar 27, 2021
1 parent 22cd267 commit 2a304a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ object DefaultTestResultAccumulator : TestResultAccumulator, KLogging() {
fun calculatePactHash(pact: Pact, source: PactSource?): Int {
val builder = HashCodeBuilder(91, 47).append(pact.consumer.name).append(pact.provider.name)

if (source is BrokerUrlSource && source.tag.isNotEmpty()) {
builder.append(source.tag)
if (source is BrokerUrlSource && source.url.isNotEmpty()) {
builder.append(source.url)
}

return builder.toHashCode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class TestResultAccumulatorSpec extends Specification {

@Unroll
@SuppressWarnings('LineLength')
def 'calculatePactHash includes the tag if one is available'() {
def 'calculatePactHash includes the Pact URL if one is available'() {
given:
def pact = new RequestResponsePact(new Provider('provider'), new Consumer('consumer'),
[interaction1])
Expand All @@ -300,8 +300,8 @@ class TestResultAccumulatorSpec extends Specification {
new UrlSource('http://pact.io') | calculateHash('consumer', 'provider')
new FileSource('/tmp/pact' as File) | calculateHash('consumer', 'provider')
new FileSource('/tmp/pact' as File) | calculateHash('consumer', 'provider')
new BrokerUrlSource('https://test.pact.dius.com.au', 'https://test.pact.dius.com.au', [:], [:]) | calculateHash('consumer', 'provider')
new BrokerUrlSource('https://test.pact.dius.com.au', 'https://test.pact.dius.com.au', [:], [:], 'master') | calculateHash('consumer', 'provider', 'master')
new BrokerUrlSource('https://test.pact.dius.com.au', 'https://test.pact.dius.com.au', [:], [:]) | calculateHash('consumer', 'provider', 'https://test.pact.dius.com.au')
new BrokerUrlSource('https://test.pact.dius.com.au', 'https://test.pact.dius.com.au', [:], [:], 'master') | calculateHash('consumer', 'provider', 'https://test.pact.dius.com.au')
}

private int calculateHash(String... args) {
Expand All @@ -314,7 +314,6 @@ class TestResultAccumulatorSpec extends Specification {
@SuppressWarnings(['AbcMetric', 'VariableName', 'MethodSize', 'UnnecessaryObjectReferences', 'UnnecessaryGetter'])
def 'updateTestResult - with a pending and non-pending pact'() {
given:

def provider1 = new Provider('provider1')

def consumer1 = new Consumer('consumer1')
Expand Down Expand Up @@ -343,13 +342,13 @@ class TestResultAccumulatorSpec extends Specification {

def pact1 = new MessagePact(provider1, consumer1, [interaction1_1, interaction1_2, interaction1_3, interaction1_4,
interaction1_5])
def source1 = new BrokerUrlSource('http://url1', 'http://broker', [:], [:], 'master')
def source1 = new BrokerUrlSource('http://url1', 'http://broker', [:], [:])
def pact2 = new MessagePact(provider1, consumer2, [interaction2_1, interaction2_2, interaction2_3, interaction2_4])
def source2 = new BrokerUrlSource('http://url2', 'http://broker', [:], [:], 'master')
def source2 = new BrokerUrlSource('http://url2', 'http://broker', [:], [:])
def pact3 = new MessagePact(provider1, consumer2, [interaction2_1, interaction2_2, interaction2_3, interaction2_4])
def source3 = new BrokerUrlSource('http://url3', 'http://broker', [:], [:], 'tag1')
def source3 = new BrokerUrlSource('http://url3', 'http://broker', [:], [:])
def pact4 = new MessagePact(provider1, consumer3, [interaction3_1, interaction3_2, interaction3_3, interaction3_4])
def source4 = new BrokerUrlSource('http://url4', 'http://broker', [:], [:], 'master')
def source4 = new BrokerUrlSource('http://url4', 'http://broker', [:], [:])

testResultAccumulator.testResults.clear()
def reporter = testResultAccumulator.verificationReporter
Expand Down

0 comments on commit 2a304a9

Please sign in to comment.