Skip to content

Commit 2a46954

Browse files
author
Ronald Holshausen
committedJan 26, 2020
fix: pacticipant version is optional is latest is specified #994
1 parent e23015b commit 2a46954

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed
 

‎provider/pact-jvm-provider-gradle/src/main/groovy/au/com/dius/pact/provider/gradle/PactCanIDeployTask.groovy

+5-4
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ class PactCanIDeployTask extends DefaultTask {
3939
throw new GradleScriptException('The CanIDeploy task requires -Ppacticipant=...', null)
4040
}
4141
String pacticipant = project.property(PACTICIPANT)
42-
if (!project.hasProperty(PACTICIPANT_VERSION)) {
43-
throw new GradleScriptException('The CanIDeploy task requires -PpacticipantVersion=...', null)
44-
}
45-
String pacticipantVersion = project.property(PACTICIPANT_VERSION)
4642
Latest latest = setupLatestParam()
43+
if ((latest instanceof Latest.UseLatestTag || latest.latest == false) &&
44+
!project.hasProperty(PACTICIPANT_VERSION)) {
45+
throw new GradleScriptException('The CanIDeploy task requires -PpacticipantVersion=... or -Dlatest=true', null)
46+
}
47+
String pacticipantVersion = project.hasProperty(PACTICIPANT_VERSION) ? project.property(PACTICIPANT_VERSION) : ''
4748
String to = null
4849
if (project.hasProperty(TO)) {
4950
to = project.property(TO)

‎provider/pact-jvm-provider-gradle/src/test/groovy/au/com/dius/pact/provider/gradle/PactCanIDeployTaskSpec.groovy

+24-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class PactCanIDeployTaskSpec extends Specification {
4646
ex.message == 'The CanIDeploy task requires -Ppacticipant=...'
4747
}
4848

49-
def 'raises an exception if no pacticipantVersion is provided'() {
49+
def 'raises an exception if pacticipantVersion and latest is not provided'() {
5050
given:
5151
project.pact {
5252
broker {
@@ -61,7 +61,29 @@ class PactCanIDeployTaskSpec extends Specification {
6161

6262
then:
6363
def ex = thrown(GradleScriptException)
64-
ex.message == 'The CanIDeploy task requires -PpacticipantVersion=...'
64+
ex.message == 'The CanIDeploy task requires -PpacticipantVersion=... or -Dlatest=true'
65+
}
66+
67+
def 'pacticipantVersion can be missing if latest is provided'() {
68+
given:
69+
project.pact {
70+
broker {
71+
pactBrokerUrl = 'pactBrokerUrl'
72+
}
73+
}
74+
project.ext.pacticipant = 'pacticipant'
75+
project.ext.latest = 'true'
76+
project.evaluate()
77+
78+
task.brokerClient = Mock(PactBrokerClient) {
79+
canIDeploy(_, _, _, _) >> new CanIDeployResult(true, '', '')
80+
}
81+
82+
when:
83+
task.canIDeploy()
84+
85+
then:
86+
notThrown(GradleScriptException)
6587
}
6688

6789
def 'calls the pact broker client'() {

‎provider/pact-jvm-provider-maven/src/main/kotlin/au/com/dius/pact/provider/maven/PactCanIDeployMojo.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ open class PactCanIDeployMojo : PactBaseMojo() {
4444
if (pacticipant.isNullOrEmpty()) {
4545
throw MojoExecutionException("The can-i-deploy task requires -Dpacticipant=...", null)
4646
}
47-
if (pacticipantVersion.isNullOrEmpty()) {
48-
throw MojoExecutionException("The can-i-deploy task requires -DpacticipantVersion=...", null)
49-
}
5047

5148
val latest = setupLatestParam()
52-
val result = brokerClient!!.canIDeploy(pacticipant!!, pacticipantVersion!!, latest, to)
49+
if ((latest !is Latest.UseLatest || !latest.latest) && pacticipantVersion.isNullOrEmpty()) {
50+
throw MojoExecutionException("The can-i-deploy task requires -DpacticipantVersion=... or -Dlatest=true", null)
51+
}
52+
53+
val result = brokerClient!!.canIDeploy(pacticipant!!, pacticipantVersion.orEmpty(), latest, to)
5354
if (result.ok) {
5455
AnsiConsole.out().println(Ansi.ansi().a("Computer says yes \\o/ ").a(result.message).a("\n\n")
5556
.fg(Ansi.Color.GREEN).a(result.reason).reset())

‎provider/pact-jvm-provider-maven/src/test/groovy/au/com/dius/pact/provider/maven/PactCanIDeployMojoSpec.groovy

+17-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class PactCanIDeployMojoSpec extends Specification {
4141
ex.message == 'The can-i-deploy task requires -Dpacticipant=...'
4242
}
4343

44-
def 'throws an exception if pacticipantVersion is not provided'() {
44+
def 'throws an exception if pacticipantVersion and latest is not provided'() {
4545
given:
4646
mojo.pacticipantVersion = null
4747

@@ -50,7 +50,22 @@ class PactCanIDeployMojoSpec extends Specification {
5050

5151
then:
5252
def ex = thrown(MojoExecutionException)
53-
ex.message == 'The can-i-deploy task requires -DpacticipantVersion=...'
53+
ex.message == 'The can-i-deploy task requires -DpacticipantVersion=... or -Dlatest=true'
54+
}
55+
56+
def 'pacticipantVersion can be missing if latest is provided'() {
57+
given:
58+
mojo.pacticipantVersion = null
59+
mojo.latest = 'true'
60+
mojo.brokerClient = Mock(PactBrokerClient) {
61+
canIDeploy(_, _, _, _) >> new CanIDeployResult(true, '', '')
62+
}
63+
64+
when:
65+
mojo.execute()
66+
67+
then:
68+
notThrown(MojoExecutionException)
5469
}
5570

5671
def 'calls the pact broker client'() {

0 commit comments

Comments
 (0)
Please sign in to comment.