Skip to content

Commit

Permalink
fix(Gradle): publishing pacts - default to the consumer version syste…
Browse files Browse the repository at this point in the history
…m property if it is set #1601
  • Loading branch information
uglyog authored and rholshausen committed Nov 24, 2022
1 parent d0b4051 commit bd42899
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,8 @@ open class PactBrokerClient(
}

private fun consumerVersion(config: PublishConfiguration): JsonValue {
return config.consumerVersion.ifNullOrEmpty {
lookupEnvironmentValue("pact.publish.consumer.version")
return lookupEnvironmentValue("pact.publish.consumer.version").ifNullOrEmpty {
config.consumerVersion
}.toJson()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,4 +736,60 @@ class PactBrokerClientSpec extends Specification {
then:
1 * mockHalClient.postJson(PactBrokerClient.PUBLISH_CONTRACTS_LINK, [:], jsonBody) >> new Ok(new JsonValue.Object([:]))
}

@RestoreSystemProperties
@Issue('#1601')
def 'publishing pact with new publish endpoint - defaults to the consumer version system property'() {
given:
def mockHalClient = Mock(IHalClient)
def providerName = 'provider'
def consumerName = 'consumer'
def config = new PublishConfiguration('1.0.0')
def pactText = '{}'
def jsonBody = '{"contracts":[{"consumerName":"consumer","content":"e30=","contentType":"application/json"' +
',"providerName":"provider","specification":"pact"}],"pacticipantName":"consumer",' +
'"pacticipantVersionNumber":"1.2.3.4","tags":[]}'
System.setProperty('pact.publish.consumer.version', '1.2.3.4')

when:
pactBrokerClient.publishContract(mockHalClient, providerName, consumerName, config, pactText)

then:
1 * mockHalClient.postJson(PactBrokerClient.PUBLISH_CONTRACTS_LINK, [:], jsonBody) >> new Ok(new JsonValue.Object([:]))
}

@Issue('#1525')
def 'can-i-deploy - should return verificationResultUrl when there is one'() {
given:
def halClient = Mock(IHalClient)
def config = new PactBrokerClientConfig(10, 0)
PactBrokerClient client = Spy(PactBrokerClient, constructorArgs: ['baseUrl', [:], config]) {
newHalClient() >> halClient
}
def json = JsonParser.parseString('''
|{
| "summary": {
| "deployable": true,
| "reason": "some text",
| "unknown": 0
| },
| "matrix": [{
| "verificationResult": {
| "_links": {
| "self": {
| "href": "verificationResultUrl"
| }
| }
| }
| }]
|}'''.stripMargin())

when:
def result = client.canIDeploy('test', '1.2.3', new Latest.UseLatest(true), '')

then:
1 * halClient.getJson(_, _) >> new Ok(json)
result.ok
result.verificationResultUrl == 'verificationResultUrl'
}
}

0 comments on commit bd42899

Please sign in to comment.