Skip to content

Commit

Permalink
test: use consumer version selectors in java not gradle props
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Oct 15, 2024
1 parent 9397e05 commit db73c5d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test {

// required variables for fetching dynamic pacts, & publishing verification results
systemProperty("pact.provider.version", System.getenv("GIT_COMMIT") == null ? "" : System.getenv("GIT_COMMIT"))
systemProperty("pact.provider.branch", System.getenv("GIT_BRANCH") == null ? "" : System.getenv("GIT_BRANCH"))
// systemProperty("pact.provider.branch", System.getenv("GIT_BRANCH") == null ? "" : System.getenv("GIT_BRANCH"))

// only publish verification results from CI allowing developers to run tests locally and debug, without affecting broker results
// only verification results from a known source (such at a commit in a VCS and a reproducible environment such as CI) should be published
Expand All @@ -54,15 +54,15 @@ test {
// Consumer version selectors for dynamically fetching pacts
// https://docs.pact.io/implementation_guides/jvm/provider/junit#selecting-the-pacts-to-verify-with-consumer-version-selectors-4314
// Runs when the provider code changes
systemProperty("pactbroker.consumerversionselectors.rawjson", "[{\"mainBranch\":true},{\"deployedOrReleased\":true},{\"matchingBranch\":true}]")
// systemProperty("pactbroker.consumerversionselectors.rawjson", "[{\"mainBranch\":true},{\"deployedOrReleased\":true},{\"matchingBranch\":true}]")
// Allow just the changed pact triggered by webhook, to be verified, ignoring the consumer version selectors above
// https://docs.pact.io/implementation_guides/jvm/provider/junit#allowing-just-the-changed-pact-specified-in-a-webhook-to-be-verified-406
// Runs when the consumer contract changes
systemProperty("pact.filter.pacturl", System.getenv("PACT_URL") == null ? null : System.getenv("PACT_URL"))
systemProperty("pact.filter.consumers", System.getenv("PACT_URL") == null ? null : System.getenv("PACT_URL").split("/consumer/")[1])

// pending pacts
systemProperty("pactbroker.enablePending", true)
// // pending pacts
// systemProperty("pactbroker.enablePending", true)

// work in progress pacts
systemProperty("pactbroker.includeWipPactsSince", java.time.LocalDate.now().minusMonths(6).format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd")))
Expand Down
20 changes: 19 additions & 1 deletion src/test/java/com/example/springboot/ProductsPactTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,27 @@
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@Provider("pactflow-example-provider-springboot")
@AllowOverridePactUrl
@PactBroker(scheme = "https", host = "${PACT_BROKER_HOST}",providerBranch = "${GIT_COMMIT}", authentication = @PactBrokerAuth(token = "${PACT_BROKER_TOKEN}"))
@PactBroker(
scheme = "https",
host = "${PACT_BROKER_HOST}",
authentication = @PactBrokerAuth(token = "${PACT_BROKER_TOKEN}"),
providerBranch = "${GIT_BRANCH}",
enablePendingPacts = "true"
)
class ProductsPactTest {

@au.com.dius.pact.provider.junitsupport.loader.PactBrokerConsumerVersionSelectors
public static SelectorBuilder consumerVersionSelectors() {
// Consumer version selectors for dynamically fetching pacts
// https://docs.pact.io/implementation_guides/jvm/provider/junit#selecting-the-pacts-to-verify-with-consumer-version-selectors-4314
// Runs when the provider code changes
return new SelectorBuilder()
.deployedOrReleased()
.matchingBranch()
.mainBranch()
;
}

@Autowired
ProductRepository repository;

Expand Down

0 comments on commit db73c5d

Please sign in to comment.