Skip to content

Commit

Permalink
BDOG-1421 Avoid making buildRequest public
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-lamed committed Sep 23, 2021
1 parent 1390b43 commit 1d15d0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ trait WSRequestBuilder extends Request {

protected def wsClient: WSClient

// TODO move to package uk.gov.hmrc.ws, then can restore `protected`
/*protected*/ def buildRequest(url: String, headers: Seq[(String, String)]): PlayWSRequest
protected def buildRequest(url: String, headers: Seq[(String, String)]): PlayWSRequest
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ import org.scalatest.OptionValues
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
import play.api.libs.ws.WSProxyServer
import play.api.test.WsTestClient
import uk.gov.hmrc.http.test.WireMockSupport
import uk.gov.hmrc.http.test.{PortFinder, WireMockSupport}

import java.util.concurrent.atomic.AtomicReference

import scala.concurrent.ExecutionContext.Implicits.global
import uk.gov.hmrc.http.HttpReads.Implicits._
Expand Down Expand Up @@ -77,10 +80,12 @@ class HttpClientImplSpec
"HttpClientImpl.withProxy" should {
val proxyProtocol = "http"
val proxyHost = "proxy.com"
val proxyPort = 1000
val proxyPort = PortFinder.findFreePort(portRange = 6001 to 7000, excluded = wireMockPort)
val proxyUsername = "u1"
val proxyPassword = "p1"

val proxyRef = new AtomicReference[Option[WSProxyServer]]

val httpClient =
new HttpClientImpl(
configuration = ConfigFactory
Expand All @@ -100,12 +105,13 @@ class HttpClientImplSpec
)

"apply proxy" in {
val proxyServer =
httpClient
.withProxy
.buildRequest(s"$wireMockUrl/", headers = Seq.empty)
.proxyServer
.value
httpClient
.withProxy
.withTransformRequest { req => proxyRef.set(req.proxyServer); req }
.GET[HttpResponse](s"$wireMockUrl/")
.failed.futureValue // it will fail since no proxy is running

val proxyServer = proxyRef.get.value

proxyServer.protocol shouldBe Some(proxyProtocol)
proxyServer.host shouldBe proxyHost
Expand Down

0 comments on commit 1d15d0f

Please sign in to comment.