Skip to content

Commit

Permalink
Feat: Support consumer version selectors DSL for JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
uglyog committed Jul 5, 2022
1 parent 3932b24 commit f37c137
Show file tree
Hide file tree
Showing 10 changed files with 402 additions and 240 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package au.com.dius.pact.provider.gradle

import au.com.dius.pact.core.pactbroker.ConsumerVersionSelectors
import au.com.dius.pact.provider.junitsupport.loader.SelectorBuilder
import mu.KLogging
import org.gradle.api.Action
import org.gradle.api.model.ObjectFactory
Expand Down Expand Up @@ -44,95 +45,4 @@ open class PactBrokerConsumerConfig @Inject constructor(
}
}

open class ConsumerVersionSelectorConfig {
val selectors: MutableList<ConsumerVersionSelectors> = mutableListOf()

/**
* The latest version from the main branch of each consumer, as specified by the consumer's mainBranch property.
*/
fun mainBranch() {
selectors.add(ConsumerVersionSelectors.MainBranch)
}

/**
* The latest version from a particular branch of each consumer, or for a particular consumer if the second
* parameter is provided. If fallback is provided, falling back to the fallback branch if none is found from the
* specified branch.
*
* @param name - Branch name
* @param consumer - Consumer name (optional)
* @param fallback - Fall back to this branch if none is found from the specified branch (optional)
*/
@JvmOverloads
fun branch(name: String, consumer: String? = null, fallback: String? = null) {
selectors.add(ConsumerVersionSelectors.Branch(name, consumer, fallback))
}

/**
* All the currently deployed and currently released and supported versions of each consumer.
*/
fun deployedOrReleased() {
selectors.add(ConsumerVersionSelectors.DeployedOrReleased)
}

/**
* The latest version from any branch of the consumer that has the same name as the current branch of the provider.
* Used for coordinated development between consumer and provider teams using matching feature branch names.
*/
fun matchingBranch() {
selectors.add(ConsumerVersionSelectors.MatchingBranch)
}

/**
* Any versions currently deployed to the specified environment
*/
fun deployedTo(environment: String) {
selectors.add(ConsumerVersionSelectors.DeployedTo(environment))
}

/**
* Any versions currently released and supported in the specified environment
*/
fun releasedTo(environment: String) {
selectors.add(ConsumerVersionSelectors.ReleasedTo(environment))
}

/**
* any versions currently deployed or released and supported in the specified environment
*/
fun environment(environment: String) {
selectors.add(ConsumerVersionSelectors.Environment(environment))
}

/**
* All versions with the specified tag
*/
@Deprecated("Tags are deprecated in favor of branches", ReplaceWith("branch"))
fun tag(name: String) {
selectors.add(ConsumerVersionSelectors.Tag(name))
}

/**
* The latest version for each consumer with the specified tag
*/
@Deprecated("Tags are deprecated in favor of branches", ReplaceWith("branch"))
fun latestTag(name: String) {
selectors.add(ConsumerVersionSelectors.LatestTag(name))
}

/**
* Generic selector.
*
* * With just the tag name, returns all versions with the specified tag.
* * With latest, returns the latest version for each consumer with the specified tag.
* * With a fallback tag, returns the latest version for each consumer with the specified tag, falling back to the
* fallbackTag if non is found with the specified tag.
* * With a consumer name, returns the latest version for a specified consumer with the specified tag.
* * With only latest, returns the latest version for each consumer. NOT RECOMMENDED as it suffers from race
* conditions when pacts are published from multiple branches.
*/
@Deprecated("Tags are deprecated in favor of branches", ReplaceWith("branch"))
fun selector(tagName: String?, latest: Boolean?, fallbackTag: String?, consumer: String?) {
selectors.add(ConsumerVersionSelectors.Selector(tagName, latest, consumer, fallbackTag))
}
}
open class ConsumerVersionSelectorConfig: SelectorBuilder()
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package au.com.dius.pact.provider.junit

import au.com.dius.pact.core.model.Interaction
import au.com.dius.pact.core.model.Pact
import au.com.dius.pact.core.support.expressions.SystemPropertyResolver
import au.com.dius.pact.core.support.json.JsonException
Expand Down Expand Up @@ -171,7 +170,7 @@ open class PactRunner(private val clazz: Class<*>) : ParentRunner<InteractionRun

val (pactSource, annotation) = pactSources.first()
return try {
val loader = instantiatePactLoader(pactSource, clazz.javaClass, annotation)
val loader = instantiatePactLoader(pactSource, clazz.javaClass, null, annotation)
checkForOverriddenPactUrl(loader, findAnnotation(clazz.javaClass, AllowOverridePactUrl::class.java),
consumerInfo)
loader
Expand Down
Loading

0 comments on commit f37c137

Please sign in to comment.