-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix a problem where the provider version trim property is ignored (
#1156) * fix: fix a problem where the provider version trim property is ignored * fix: use ProviderVersion in TestResultAccumulator * fix: linting Co-authored-by: anto <[email protected]>
- Loading branch information
Showing
11 changed files
with
104 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
provider/src/main/kotlin/au/com/dius/pact/provider/ProviderVersion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package au.com.dius.pact.provider | ||
|
||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import java.util.function.Supplier | ||
|
||
/** | ||
* Should always wrap a provider version string with this Supplier in order to avoid repeating any logic. | ||
*/ | ||
class ProviderVersion(val source: () -> String?) : Supplier<String> { | ||
|
||
companion object { | ||
const val FALLBACK_VALUE = "0.0.0" | ||
const val SNAPSHOT_DEFINITION_STRING = "-SNAPSHOT" | ||
val snapshotRegex = Regex(".*($SNAPSHOT_DEFINITION_STRING)") | ||
val logger: Logger = LoggerFactory.getLogger(ProviderVersion::class.java) | ||
} | ||
|
||
override fun get(): String { | ||
val version = source() ?: FALLBACK_VALUE | ||
|
||
if (version == FALLBACK_VALUE) { | ||
logger.warn("Provider version not set, defaulting to '$FALLBACK_VALUE'") | ||
} | ||
|
||
val trimSnapshotProperty = System.getProperty(ProviderVerifier.PACT_PROVIDER_VERSION_TRIM_SNAPSHOT) | ||
val isTrimSnapshot = if (trimSnapshotProperty.isNullOrBlank()) false else trimSnapshotProperty.toBoolean() | ||
return if (isTrimSnapshot) trimSnapshot(version) else version | ||
} | ||
|
||
private fun trimSnapshot(providerVersion: String): String { | ||
if (providerVersion.contains(SNAPSHOT_DEFINITION_STRING)) { | ||
return providerVersion.removeRange(snapshotRegex.find(providerVersion)!!.groups[1]!!.range) | ||
} | ||
return providerVersion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
provider/src/test/groovy/au/com/dius/pact/provider/ProviderVersionSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package au.com.dius.pact.provider | ||
|
||
import org.spockframework.lang.Wildcard | ||
import spock.lang.Specification | ||
|
||
class ProviderVersionSpec extends Specification { | ||
|
||
def cleanup() { | ||
System.clearProperty(ProviderVerifier.PACT_PROVIDER_VERSION_TRIM_SNAPSHOT) | ||
} | ||
|
||
def 'provider version respects the property pact.provider.version.trimSnapshot'() { | ||
|
||
given: | ||
if (propertyValue != Wildcard.INSTANCE) { | ||
System.setProperty(ProviderVerifier.PACT_PROVIDER_VERSION_TRIM_SNAPSHOT, propertyValue as String) | ||
} | ||
|
||
expect: | ||
new ProviderVersion({ projectVersion }).get() == result | ||
|
||
where: | ||
propertyValue | projectVersion | result | ||
'true' | '1.0.0-NOT-A-SNAPSHOT-abc-SNAPSHOT' | '1.0.0-NOT-A-SNAPSHOT-abc' | ||
'true' | '1.0.0-NOT-A-SNAPSHOT-abc-SNAPSHOT-re234hj' | '1.0.0-NOT-A-SNAPSHOT-abc-re234hj' | ||
'true' | '1.0.0-SNAPSHOT-re234hj' | '1.0.0-re234hj' | ||
'false' | '1.0.0-SNAPSHOT-re234hj' | '1.0.0-SNAPSHOT-re234hj' | ||
'aweirdstring' | '1.0.0-SNAPSHOT-re234hj' | '1.0.0-SNAPSHOT-re234hj' | ||
'true' | null | '0.0.0' | ||
'false' | null | '0.0.0' | ||
_ | '1.0.0-SNAPSHOT-re234hj' | '1.0.0-SNAPSHOT-re234hj' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters