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 2c67425784..4dfa4aacce 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 @@ -98,6 +98,11 @@ sealed class Latest { data class UseLatestTag(val latestTag: String) : Latest() } +/** + * Specifies the target for the can-i-deploy check (tag or environment) + */ +data class To @JvmOverloads constructor(val tag: String? = null, val environment: String? = null) + /** * Model for a CanIDeploy result */ @@ -992,7 +997,7 @@ open class PactBrokerClient( pacticipant: String, pacticipantVersion: String, latest: Latest, - to: String?, + to: To?, ignore: List = emptyList() ): CanIDeployResult { val halClient = newHalClient() @@ -1109,7 +1114,7 @@ open class PactBrokerClient( pacticipant: String, pacticipantVersion: String, latest: Latest, - to: String?, + to: To?, ignore: List ): String { val escaper = urlFormParameterEscaper() @@ -1124,9 +1129,17 @@ open class PactBrokerClient( is Latest.UseLatestTag -> params.add("q[][tag]" to escaper.escape(latest.latestTag)) } - if (to.isNotEmpty()) { - params.add("latest" to "true") - params.add("tag" to escaper.escape(to)) + if (to != null) { + if (to.environment.isNotEmpty()) { + params.add("environment" to escaper.escape(to.environment)) + } + + if (to.tag.isNotEmpty()) { + params.add("latest" to "true") + params.add("tag" to escaper.escape(to.tag)) + } else if (to.environment.isNullOrEmpty()) { + params.add("latest" to "true") + } } else { params.add("latest" to "true") } 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 a58546680e..ba6e6dc94d 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 @@ -560,7 +560,7 @@ class PactBrokerClientSpec extends Specification { |}'''.stripMargin()) when: - def result = client.canIDeploy('test', '1.2.3', new Latest.UseLatest(true), '') + def result = client.canIDeploy('test', '1.2.3', new Latest.UseLatest(true), null) then: 3 * halClient.getJson(_, _) >> new Result.Ok(json1) >> new Result.Ok(json1) >> new Result.Ok(json2) @@ -677,18 +677,21 @@ class PactBrokerClientSpec extends Specification { where: - pacticipant | pacticipantVersion | latest | to | ignore || result - 'Test' | '' | new Latest.UseLatest(true) | null | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&latest=true' - 'Test' | '100' | new Latest.UseLatest(false) | null | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][version]=100&latest=true' - 'Test' | '' | new Latest.UseLatestTag('tst') | null | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][tag]=tst&latest=true' - 'Test' | '' | new Latest.UseLatest(true) | 'tst' | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&latest=true&tag=tst' - 'Test 1 2 3' | '' | new Latest.UseLatest(true) | null | [] || 'q[][pacticipant]=Test+1+2+3&latestby=cvp&q[][latest]=true&latest=true' - 'Test' | '1 0 0' | new Latest.UseLatest(false) | null | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][version]=1+0+0&latest=true' - 'Test' | '' | new Latest.UseLatestTag('tst 3/4') | null | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][tag]=tst+3%2F4&latest=true' - 'Test' | '' | new Latest.UseLatest(true) | 'tst 3/4' | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&latest=true&tag=tst+3%2F4' - 'Test' | '' | new Latest.UseLatest(true) | null | [new IgnoreSelector('bob', null)] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&latest=true&ignore[][pacticipant]=bob' - 'Test' | '' | new Latest.UseLatest(true) | null | [new IgnoreSelector('bob', '100')] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&latest=true&ignore[][pacticipant]=bob&ignore[][version]=100' - 'Test' | '' | new Latest.UseLatest(true) | null | [new IgnoreSelector('bob', null), new IgnoreSelector('fred', null)] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&latest=true&ignore[][pacticipant]=bob&ignore[][pacticipant]=fred' + pacticipant | pacticipantVersion | latest | to | ignore || result + 'Test' | '' | new Latest.UseLatest(true) | null | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&latest=true' + 'Test' | '100' | new Latest.UseLatest(false) | null | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][version]=100&latest=true' + 'Test' | '' | new Latest.UseLatestTag('tst') | null | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][tag]=tst&latest=true' + 'Test' | '' | new Latest.UseLatest(true) | new To('tst') | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&latest=true&tag=tst' + 'Test 1 2 3' | '' | new Latest.UseLatest(true) | null | [] || 'q[][pacticipant]=Test+1+2+3&latestby=cvp&q[][latest]=true&latest=true' + 'Test' | '1 0 0' | new Latest.UseLatest(false) | null | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][version]=1+0+0&latest=true' + 'Test' | '' | new Latest.UseLatestTag('tst 3/4') | null | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][tag]=tst+3%2F4&latest=true' + 'Test' | '' | new Latest.UseLatest(true) | new To('tst 3/4') | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&latest=true&tag=tst+3%2F4' + 'Test' | '' | new Latest.UseLatest(true) | null | [new IgnoreSelector('bob', null)] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&latest=true&ignore[][pacticipant]=bob' + 'Test' | '' | new Latest.UseLatest(true) | null | [new IgnoreSelector('bob', '100')] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&latest=true&ignore[][pacticipant]=bob&ignore[][version]=100' + 'Test' | '' | new Latest.UseLatest(true) | null | [new IgnoreSelector('bob', null), new IgnoreSelector('fred', null)] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&latest=true&ignore[][pacticipant]=bob&ignore[][pacticipant]=fred' + 'Test' | '' | new Latest.UseLatest(true) | new To(null, 'env1') | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&environment=env1' + 'Test' | '' | new Latest.UseLatest(true) | new To('tag1', 'env1') | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&environment=env1&latest=true&tag=tag1' + 'Test' | '' | new Latest.UseLatest(true) | new To(null, 'env 1') | [] || 'q[][pacticipant]=Test&latestby=cvp&q[][latest]=true&environment=env+1' } @Issue('#1511') @@ -784,7 +787,7 @@ class PactBrokerClientSpec extends Specification { |}'''.stripMargin()) when: - def result = client.canIDeploy('test', '1.2.3', new Latest.UseLatest(true), '') + def result = client.canIDeploy('test', '1.2.3', new Latest.UseLatest(true), null) then: 1 * halClient.getJson(_, _) >> new Result.Ok(json) diff --git a/pact-publish/src/test/groovy/broker/PactBrokerClientPactSpec.groovy b/pact-publish/src/test/groovy/broker/PactBrokerClientPactSpec.groovy index b5f394f7a7..4282ea530d 100644 --- a/pact-publish/src/test/groovy/broker/PactBrokerClientPactSpec.groovy +++ b/pact-publish/src/test/groovy/broker/PactBrokerClientPactSpec.groovy @@ -7,6 +7,7 @@ import au.com.dius.pact.core.pactbroker.Latest import au.com.dius.pact.core.pactbroker.PactBrokerClient import au.com.dius.pact.core.pactbroker.PactBrokerClientConfig import au.com.dius.pact.core.pactbroker.TestResult +import au.com.dius.pact.core.pactbroker.To import au.com.dius.pact.core.support.Result import spock.lang.Specification @@ -820,7 +821,7 @@ class PactBrokerClientPactSpec extends Specification { when: def result = pactBroker.runTest { server, context -> - pactBrokerClient.canIDeploy('Foo', '1.2.3', new Latest.UseLatest(false), 'prod') + pactBrokerClient.canIDeploy('Foo', '1.2.3', new Latest.UseLatest(false), new To('prod')) } then: diff --git a/provider/gradle/README.md b/provider/gradle/README.md index 0e4d1fbc83..1df9b75827 100644 --- a/provider/gradle/README.md +++ b/provider/gradle/README.md @@ -1143,6 +1143,9 @@ There is a `canIDeploy` Gradle task that you can use to preform a deployment saf parameters: `pacticipant` and either `pacticipantVersion` or `latest=true`. It will use the configuration from the `broker` section of your Gradle build. +**NOTE:** It is recommended to use the [Pact CLI](https://docs.pact.io/implementation_guides/cli) to execute the +Can I Deploy check, as it will always be up to date with features in the Pact broker. + ```console $ ./gradlew canideploy -Ppacticipant='Activity Service' -Platest=true @@ -1171,10 +1174,10 @@ It can happen that there are still unknown results in the Pact broker because th You can enable a retry with a wait interval to poll for the results to become available. There are two settings that can be added to the `broker` configuration to enable this: `retryCountWhileUnknown` and `retryWhileUnknownInterval`. -|Field|Description|Default| -|-----|-----------|-------| -|retryCountWhileUnknown|The amount of times to retry while there are unknown results|0| -|retryWhileUnknownInterval|The number of seconds to wait between retries|10| +| Field | Description | Default | +|---------------------------|--------------------------------------------------------------|---------| +| retryCountWhileUnknown | The amount of times to retry while there are unknown results | 0 | +| retryWhileUnknownInterval | The number of seconds to wait between retries | 10 | Example use: @@ -1188,6 +1191,10 @@ pact { } ``` +## Support for environments (4.5.0+) + +You can specify the environment into which the pacticipant(s) are to be deployed with the `toEnvironment` property. + # Verifying V4 Pact files that require plugins (version 4.3.0+) Pact files that require plugins can be verified with version 4.3.0+. For details on how plugins work, see the diff --git a/provider/gradle/src/main/groovy/au/com/dius/pact/provider/gradle/PactCanIDeployTask.groovy b/provider/gradle/src/main/groovy/au/com/dius/pact/provider/gradle/PactCanIDeployTask.groovy index ff957b43de..0d63b2689e 100644 --- a/provider/gradle/src/main/groovy/au/com/dius/pact/provider/gradle/PactCanIDeployTask.groovy +++ b/provider/gradle/src/main/groovy/au/com/dius/pact/provider/gradle/PactCanIDeployTask.groovy @@ -2,6 +2,7 @@ package au.com.dius.pact.provider.gradle import au.com.dius.pact.core.pactbroker.Latest import au.com.dius.pact.core.pactbroker.PactBrokerClient +import au.com.dius.pact.core.pactbroker.To import com.github.ajalt.mordant.TermColors import org.gradle.api.GradleScriptException import org.gradle.api.provider.Property @@ -19,6 +20,7 @@ abstract class PactCanIDeployTask extends PactCanIDeployBaseTask { static final String PACTICIPANT = 'pacticipant' static final String PACTICIPANT_VERSION = 'pacticipantVersion' static final String TO = 'toTag' + static final String TO_ENVIRONMENT = 'toEnvironment' static final String LATEST = 'latest' @Internal @@ -40,6 +42,10 @@ abstract class PactCanIDeployTask extends PactCanIDeployBaseTask { @Optional abstract Property getToProp() + @Input + @Optional + abstract Property getToEnvironment() + @Input @Optional abstract Property getLatestProp() @@ -65,10 +71,15 @@ abstract class PactCanIDeployTask extends PactCanIDeployBaseTask { throw new GradleScriptException('The CanIDeploy task requires -PpacticipantVersion=... or -Platest=true', null) } String pacticipantVersion = pacticipantVersion.orElse('').get() - String to = null + String toTag = null if (toProp.present) { - to = toProp.get() + toTag = toProp.get() + } + String environment = null + if (toEnvironment.present) { + environment = toEnvironment.get() } + def to = new To(toTag, environment) def t = new TermColors() logger.debug( "Calling canIDeploy(pacticipant=$pacticipant, pacticipantVersion=$pacticipantVersion, latest=$latest, to=$to)" diff --git a/provider/gradle/src/main/groovy/au/com/dius/pact/provider/gradle/PactPlugin.groovy b/provider/gradle/src/main/groovy/au/com/dius/pact/provider/gradle/PactPlugin.groovy index 74f5f77c7d..981778d045 100644 --- a/provider/gradle/src/main/groovy/au/com/dius/pact/provider/gradle/PactPlugin.groovy +++ b/provider/gradle/src/main/groovy/au/com/dius/pact/provider/gradle/PactPlugin.groovy @@ -39,6 +39,7 @@ class PactPlugin extends PactPluginBase { : null) toProp.set(project.hasProperty(TO) ? project.property(TO) : null) latestProp.set(project.hasProperty(LATEST) ? project.property(LATEST) : null) + toEnvironment.set(project.hasProperty(TO_ENVIRONMENT) ? project.property(TO_ENVIRONMENT) : null) } project.afterEvaluate { diff --git a/provider/gradle/src/test/groovy/au/com/dius/pact/provider/gradle/PactCanIDeployTaskSpec.groovy b/provider/gradle/src/test/groovy/au/com/dius/pact/provider/gradle/PactCanIDeployTaskSpec.groovy index 2f39f5612c..ea9eaff19e 100644 --- a/provider/gradle/src/test/groovy/au/com/dius/pact/provider/gradle/PactCanIDeployTaskSpec.groovy +++ b/provider/gradle/src/test/groovy/au/com/dius/pact/provider/gradle/PactCanIDeployTaskSpec.groovy @@ -3,11 +3,13 @@ package au.com.dius.pact.provider.gradle import au.com.dius.pact.core.pactbroker.CanIDeployResult import au.com.dius.pact.core.pactbroker.Latest import au.com.dius.pact.core.pactbroker.PactBrokerClient +import au.com.dius.pact.core.pactbroker.To import org.gradle.api.GradleScriptException import org.gradle.api.Project import org.gradle.testfixtures.ProjectBuilder import spock.lang.Specification +@SuppressWarnings('LineLength') class PactCanIDeployTaskSpec extends Specification { private PactPlugin plugin @@ -127,7 +129,7 @@ class PactCanIDeployTaskSpec extends Specification { then: notThrown(GradleScriptException) 1 * project.tasks.canIDeploy.brokerClient.canIDeploy('pacticipant', '1.0.0', - new Latest.UseLatest(true), 'prod', _) >> new CanIDeployResult(true, '', '', null, 'verificationResultUrl') + new Latest.UseLatest(true), new To('prod'), _) >> new CanIDeployResult(true, '', '', null, 'verificationResultUrl') } def 'passes optional parameters to the pact broker client'() { @@ -151,7 +153,31 @@ class PactCanIDeployTaskSpec extends Specification { then: notThrown(GradleScriptException) 1 * project.tasks.canIDeploy.brokerClient.canIDeploy('pacticipant', '1.0.0', - new Latest.UseLatest(true), 'prod', _) >> new CanIDeployResult(true, '', '', null, null) + new Latest.UseLatest(true), new To('prod'), _) >> new CanIDeployResult(true, '', '', null, null) + } + + def 'passes toEnvironment parameter to the pact broker client'() { + given: + project.pact { + broker { + pactBrokerUrl = 'pactBrokerUrl' + } + } + project.ext.pacticipant = 'pacticipant' + project.ext.pacticipantVersion = '1.0.0' + project.ext.latest = 'true' + project.ext.toEnvironment = 'prod' + project.evaluate() + + project.tasks.canIDeploy.brokerClient = Mock(PactBrokerClient) + + when: + project.tasks.canIDeploy.canIDeploy() + + then: + notThrown(GradleScriptException) + 1 * project.tasks.canIDeploy.brokerClient.canIDeploy('pacticipant', '1.0.0', + new Latest.UseLatest(true), new To(null, 'prod'), _) >> new CanIDeployResult(true, '', '', null, null) } def 'throws an exception if the pact broker client says no'() { diff --git a/provider/maven/README.md b/provider/maven/README.md index d07afe0cf7..f38edb006f 100644 --- a/provider/maven/README.md +++ b/provider/maven/README.md @@ -1138,6 +1138,9 @@ There is a `can-i-deploy` goal that you can use to preform a deployment safety c parameters: `pacticipant` and either `pacticipantVersion` or `latest=true`. It will use the broker configuration values from the your POM. +**NOTE:** It is recommended to use the [Pact CLI](https://docs.pact.io/implementation_guides/cli) to execute the +Can I Deploy check, as it will always be up to date with features in the Pact broker. + ```console $ mvn pact:can-i-deploy -Dpacticipant='Activity Service' -Dlatest=true [INFO] Scanning for projects... @@ -1165,10 +1168,10 @@ It can happen that there are still unknown results in the Pact broker because th You can enable a retry with a wait interval to poll for the results to become available. There are two settings that can be added to the configuration in the POM to enable this: `retriesWhenUnknown` and `retryInterval`. -|Field|Description|Default| -|-----|-----------|-------| -|retriesWhenUnknown|The amount of times to retry while there are unknown results|0| -|retryInterval|The number of seconds to wait between retries|10| +| Field | Description | Default | +|--------------------|--------------------------------------------------------------|---------| +| retriesWhenUnknown | The amount of times to retry while there are unknown results | 0 | +| retryInterval | The number of seconds to wait between retries | 10 | ## Ignoring pacticipant by name and version (4.1.28+, 4.2.13+) @@ -1202,6 +1205,10 @@ To configure it in the POM file, add an ignore section to the `configuration` el Or add it to the command line using the format `-Dignore=:?,:?,...`. For example, `-Dignore=bob,fred:1.2.3` to ignore pacticipant named Bob and pacticipant name Fred with version 1.2.3. +## Support for environments (4.5.0+) + +You can specify the environment into which the pacticipant(s) are to be deployed with the `toEnvironment` property. + # Verifying V4 Pact files that require plugins (version 4.3.0+) Pact files that require plugins can be verified with version 4.3.0+. For details on how plugins work, see the diff --git a/provider/maven/build.gradle b/provider/maven/build.gradle index 2854ff1c89..cfaa9c3a11 100644 --- a/provider/maven/build.gradle +++ b/provider/maven/build.gradle @@ -19,6 +19,7 @@ dependencies { testRuntimeOnly 'net.bytebuddy:byte-buddy' testRuntimeOnly 'org.objenesis:objenesis:3.1' + testRuntimeOnly 'ch.qos.logback:logback-classic' } import org.apache.tools.ant.taskdefs.condition.Os @@ -47,29 +48,29 @@ task generatePom(type: GenerateMavenPom, dependsOn: [":provider:publishToMavenLo } } -if (System.env.CI != 'true') { - task pluginDescriptor(type: Exec, dependsOn: generatePom) { - if (isWindows()) { - try { - // check if mvn.bat exists - def proc = new ProcessBuilder('mvn.bat', '-v') - proc.start().waitFor() - - commandLine 'mvn.bat', '-f', "${buildDir}/poms/pom.xml", '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor' - } catch(Exception e) { - commandLine 'mvn.cmd', '-f', "${buildDir}/poms/pom.xml", '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor' - } - } else { - commandLine 'sh', '-c', "mvn -f ${buildDir}/poms/pom.xml -e -B org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor" - } - - doLast { - final dir = project.compileKotlin.destinationDirectory.dir('META-INF/maven').get() - final pluginDescriptor = dir.file('plugin.xml').getAsFile() - assert pluginDescriptor.exists(), "[$pluginDescriptor.canonicalPath] was not created" - } - } - - pluginDescriptor.shouldRunAfter project.jar - project.jar.dependsOn pluginDescriptor -} +//if (System.env.CI != 'true') { +// task pluginDescriptor(type: Exec, dependsOn: generatePom) { +// if (isWindows()) { +// try { +// // check if mvn.bat exists +// def proc = new ProcessBuilder('mvn.bat', '-v') +// proc.start().waitFor() +// +// commandLine 'mvn.bat', '-f', "${buildDir}/poms/pom.xml", '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor' +// } catch(Exception e) { +// commandLine 'mvn.cmd', '-f', "${buildDir}/poms/pom.xml", '-e', '-B', 'org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor' +// } +// } else { +// commandLine 'sh', '-c', "mvn -f ${buildDir}/poms/pom.xml -e -B org.apache.maven.plugins:maven-plugin-plugin:3.6.1:descriptor" +// } +// +// doLast { +// final dir = project.compileKotlin.destinationDirectory.dir('META-INF/maven').get() +// final pluginDescriptor = dir.file('plugin.xml').getAsFile() +// assert pluginDescriptor.exists(), "[$pluginDescriptor.canonicalPath] was not created" +// } +// } +// +// pluginDescriptor.shouldRunAfter project.jar +// project.jar.dependsOn pluginDescriptor +//} diff --git a/provider/maven/src/main/kotlin/au/com/dius/pact/provider/maven/PactCanIDeployMojo.kt b/provider/maven/src/main/kotlin/au/com/dius/pact/provider/maven/PactCanIDeployMojo.kt index d21eff07ea..675a5f0498 100644 --- a/provider/maven/src/main/kotlin/au/com/dius/pact/provider/maven/PactCanIDeployMojo.kt +++ b/provider/maven/src/main/kotlin/au/com/dius/pact/provider/maven/PactCanIDeployMojo.kt @@ -3,6 +3,7 @@ package au.com.dius.pact.provider.maven import au.com.dius.pact.core.pactbroker.IgnoreSelector import au.com.dius.pact.core.pactbroker.Latest import au.com.dius.pact.core.pactbroker.PactBrokerClient +import au.com.dius.pact.core.pactbroker.To import au.com.dius.pact.core.support.isNotEmpty import com.github.ajalt.mordant.TermColors import org.apache.maven.plugin.MojoExecutionException @@ -27,7 +28,10 @@ open class PactCanIDeployMojo : PactBaseMojo() { private var latest: String? = "" @Parameter(property = "toTag", defaultValue = "") - private var to: String? = "" + private var toTag: String? = "" + + @Parameter(property = "toEnvironment", defaultValue = "") + private var toEnvironment: String? = "" @Parameter(property = "ignore") private var ignore: Array = emptyArray() @@ -52,6 +56,7 @@ open class PactCanIDeployMojo : PactBaseMojo() { throw MojoExecutionException("The can-i-deploy task requires -DpacticipantVersion=... or -Dlatest=true", null) } + val to = To(toTag, toEnvironment) val result = brokerClient!!.canIDeploy(pacticipant!!, pacticipantVersion.orEmpty(), latest, to, ignore.asList()) if (result.ok) { println("Computer says yes \\o/ ${result.message}\n\n${t.green(result.reason)}") diff --git a/provider/maven/src/test/groovy/au/com/dius/pact/provider/maven/PactCanIDeployMojoSpec.groovy b/provider/maven/src/test/groovy/au/com/dius/pact/provider/maven/PactCanIDeployMojoSpec.groovy index 996c0659b6..d3611fb18a 100644 --- a/provider/maven/src/test/groovy/au/com/dius/pact/provider/maven/PactCanIDeployMojoSpec.groovy +++ b/provider/maven/src/test/groovy/au/com/dius/pact/provider/maven/PactCanIDeployMojoSpec.groovy @@ -4,6 +4,7 @@ import au.com.dius.pact.core.pactbroker.CanIDeployResult import au.com.dius.pact.core.pactbroker.IgnoreSelector import au.com.dius.pact.core.pactbroker.Latest import au.com.dius.pact.core.pactbroker.PactBrokerClient +import au.com.dius.pact.core.pactbroker.To import org.apache.maven.plugin.MojoExecutionException import spock.lang.Specification @@ -85,7 +86,7 @@ class PactCanIDeployMojoSpec extends Specification { def 'passes optional parameters to the pact broker client'() { given: mojo.latest = 'true' - mojo.to = 'prod' + mojo.toTag = 'prod' mojo.brokerClient = Mock(PactBrokerClient) when: @@ -94,7 +95,22 @@ class PactCanIDeployMojoSpec extends Specification { then: notThrown(MojoExecutionException) 1 * mojo.brokerClient.canIDeploy('test', '1234', - new Latest.UseLatest(true), 'prod', _) >> new CanIDeployResult(true, '', '', null, null) + new Latest.UseLatest(true), new To('prod', ''), _) >> new CanIDeployResult(true, '', '', null, null) + } + + def 'passes toEnvironment parameter to the pact broker client'() { + given: + mojo.latest = 'true' + mojo.toEnvironment = 'prod' + mojo.brokerClient = Mock(PactBrokerClient) + + when: + mojo.execute() + + then: + notThrown(MojoExecutionException) + 1 * mojo.brokerClient.canIDeploy('test', '1234', + new Latest.UseLatest(true), new To('', 'prod'), _) >> new CanIDeployResult(true, '', '', null, null) } def 'passes ignore parameters to the pact broker client'() { @@ -110,7 +126,7 @@ class PactCanIDeployMojoSpec extends Specification { then: notThrown(MojoExecutionException) 1 * mojo.brokerClient.canIDeploy('test', '1234', - new Latest.UseLatest(true), '', selectors) >> new CanIDeployResult(true, '', '', null, null) + new Latest.UseLatest(true), new To('', ''), selectors) >> new CanIDeployResult(true, '', '', null, null) } def 'prints verification results url when pact broker client returns one'() { @@ -119,6 +135,7 @@ class PactCanIDeployMojoSpec extends Specification { mojo.latest = 'true' mojo.ignore = selectors mojo.brokerClient = Mock(PactBrokerClient) + def to = new To('', '') when: mojo.execute() @@ -126,7 +143,7 @@ class PactCanIDeployMojoSpec extends Specification { then: notThrown(MojoExecutionException) 1 * mojo.brokerClient.canIDeploy('test', '1234', - new Latest.UseLatest(true), '', selectors) >> new CanIDeployResult(true, '', '', null, 'verificationResultUrl') + new Latest.UseLatest(true), to, selectors) >> new CanIDeployResult(true, '', '', null, 'verificationResultUrl') } def 'throws an exception if the pact broker client says no'() { diff --git a/provider/maven/src/test/resources/logback.groovy b/provider/maven/src/test/resources/logback.groovy new file mode 100644 index 0000000000..0e153f5334 --- /dev/null +++ b/provider/maven/src/test/resources/logback.groovy @@ -0,0 +1,8 @@ +import ch.qos.logback.classic.encoder.PatternLayoutEncoder + +appender("STDOUT", ConsoleAppender) { + encoder(PatternLayoutEncoder) { + pattern = "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" + } +} +root(DEBUG, ["STDOUT"])