Skip to content

Commit 65f61b3

Browse files
author
jbwheatley
authored
update broker integration tests to check for tag publishing (#209)
* update broker integration tests to check for tag publishing
1 parent d5614b5 commit 65f61b3

File tree

19 files changed

+33
-14
lines changed

19 files changed

+33
-14
lines changed

pending-pact-tests/consumer/src/test/scala/consumer/ProviderClientSpec.scala renamed to broker-integration-tests/consumer/src/test/scala/consumer/ProviderClientSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import scala.io.{BufferedSource, Source}
99

1010
class ProviderClientSpec extends PactForgerSuite with FunSpecLike with Matchers {
1111

12-
val CONSUMER = "scala-pact-pending-test-consumer"
13-
val PROVIDER = "scala-pact-pending-test-provider"
12+
val CONSUMER = "scala-pact-integration-test-consumer"
13+
val PROVIDER = "scala-pact-integration-test-provider"
1414

1515
describe("Connecting to the Provider service") {
1616

pending-pact-tests/provider/build.sbt renamed to broker-integration-tests/provider/build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ libraryDependencies ++= {
1717
"org.slf4j" % "slf4j-simple" % "1.6.4",
1818
"org.scalatest" %% "scalatest" % "3.0.8" % "test",
1919
"com.itv" %% "scalapact-scalatest-suite" % pactVersion % "test",
20+
"org.scalaj" %% "scalaj-http" % "2.4.2" % "test",
2021
"io.circe" %% "circe-parser" % "0.13.0"
2122
)
2223
}

pending-pact-tests/provider/pact.sbt renamed to broker-integration-tests/provider/pact.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ pactBrokerAddress := "https://test.pact.dius.com.au"
66
pactBrokerCredentials := ("dXfltyFMgNOFZAxr8io9wJ37iUpY42M", "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1")
77
consumerVersionSelectors := Seq(ConsumerVersionSelector("test", latest = true))
88
providerVersionTags := List("master")
9-
providerName := "scala-pact-pending-test-provider"
9+
providerName := "scala-pact-integration-test-provider"
1010
pactBrokerClientTimeout := 5.seconds

pending-pact-tests/provider/src/test/scala/provider/VerifyContractsSpec.scala renamed to broker-integration-tests/provider/src/test/scala/provider/VerifyContractsSpec.scala

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@ package provider
22

33
import org.scalatest.{BeforeAndAfterAll, FunSpec, Matchers}
44
import com.itv.scalapact.PactVerifySuite
5-
import com.itv.scalapact.shared.{ConsumerVersionSelector, PactBrokerAuthorization, PendingPactSettings}
5+
import com.itv.scalapact.shared.{BrokerPublishData, ConsumerVersionSelector, PactBrokerAuthorization, PendingPactSettings}
6+
import scalaj.http._
67

78
import scala.concurrent.duration._
89

910
class VerifyContractsSpec extends FunSpec with Matchers with BeforeAndAfterAll with PactVerifySuite {
1011
val serverAllocated =
1112
AlternateStartupApproach.serverResource.allocated.unsafeRunSync()
1213

14+
val providerVersion = "0.0.1"
15+
val providerTag = "provider-tag"
16+
val providerName = "scala-pact-integration-test-provider"
17+
val brokerAuth = PactBrokerAuthorization(pactBrokerCredentials = ("dXfltyFMgNOFZAxr8io9wJ37iUpY42M", "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1"), "")
18+
19+
val tagRequest = {
20+
val authHeader = brokerAuth.map(_.asHeader).get
21+
Http(
22+
s"https://test.pact.dius.com.au/pacticipants/$providerName/versions/$providerVersion/tags/$providerTag"
23+
).header(authHeader._1, authHeader._2)
24+
}
1325
override def beforeAll(): Unit = {
26+
val _ = tagRequest.method("DELETE").asString
1427
()
1528
}
1629

@@ -29,18 +42,23 @@ class VerifyContractsSpec extends FunSpec with Matchers with BeforeAndAfterAll w
2942
.withPactSource(
3043
pactBrokerWithVersionSelectors(
3144
"https://test.pact.dius.com.au",
32-
"scala-pact-pending-test-provider",
45+
providerName,
3346
consumers,
34-
List("master"),
47+
List(providerTag),
3548
pendingPactSettings = PendingPactSettings.PendingEnabled,
36-
None,
49+
Some(BrokerPublishData(providerVersion, None)),
3750
//again, these are publicly known creds for a test pact-broker
38-
PactBrokerAuthorization(pactBrokerCredentials = ("dXfltyFMgNOFZAxr8io9wJ37iUpY42M", "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1"), ""),
51+
brokerAuth,
3952
Some(5.seconds)
4053
)
4154
)
4255
.noSetupRequired
4356
.runVerificationAgainst("localhost", 8080, 10.seconds)
57+
58+
val fetchTag = tagRequest.asString
59+
60+
//check tag exists in broker
61+
fetchTag.code shouldBe 200
4462
}
4563
}
4664

scalapact-core/src/main/scala/com/itv/scalapactcore/common/PactBrokerClient.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class PactBrokerClient(implicit
272272
SimpleRequest(
273273
baseUrl = providerUrl + "/versions/" + providerVersion + "/tags/" + URLEncoder.encode(tag, "UTF-8"),
274274
endPoint = "",
275-
method = HttpMethod.POST,
275+
method = HttpMethod.PUT,
276276
headers = Map("Content-Type" -> "application/json; charset=UTF-8") ++ pactBrokerAuthorization
277277
.map(_.asHeader)
278278
.toList,

scalapact-core/src/test/scala/com/itv/scalapactcore/common/PactBrokerClientSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class PactBrokerClientSpec extends FunSpec with Matchers with BeforeAndAfter {
131131
val successfulTagRequest = SimpleRequest(
132132
baseUrl = getProviderUrl(brokerPublishData.providerVersion, providerVersionTags.head),
133133
endPoint = "",
134-
method = HttpMethod.POST,
134+
method = HttpMethod.PUT,
135135
headers = Map("Content-Type" -> "application/json; charset=UTF-8"),
136136
body = None,
137137
sslContextName = None

scripts/test-pending-pacts.sh renamed to scripts/broker-integration-tests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ set -e
44

55
source scripts/test-header.sh
66

7-
echo "Checking pending pacts tests"
7+
echo "Checking broker integration tests"
88
echo "***********************"
99

10-
cd pending-pact-tests/consumer
10+
cd broker-integration-tests/consumer
1111
sbt clean update
1212
sbt "pactPublish --clientTimeout 5"
1313
cd ..
1414

1515
cd provider
1616
sbt clean update test
1717

18-
echo "Testing using the CLI with --includeWipPactsSince"
18+
echo "Testing pending pacts using the CLI with --includeWipPactsSince"
1919
sbt run &
2020
echo "warming things up..."
2121
simple_countdown 10

scripts/local-build-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ bash scripts/test-verifier.sh
3838
echo "Taking a breather... (3)"
3939
simple_countdown 5
4040

41-
bash scripts/test-pending-pacts.sh
41+
bash scripts/broker-integration-tests.sh
4242

4343
echo "Taking a breather... (4)"
4444
simple_countdown 5

0 commit comments

Comments
 (0)