Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example
- import scala.concurrent.Await
- import scala.concurrent.ExecutionContext.Implicits.global
- import scala.concurrent.duration._
- import org.scalatest._
- import akka.actor.ActorSystem
- import akka.http.scaladsl._
- import akka.http.scaladsl.model._
- import akka.http.scaladsl.model.headers.{ Accept, Host, `User-Agent` }
- import akka.stream.ActorMaterializer
- import akka.stream.scaladsl._
- import akka.stream.testkit.scaladsl.{ TestSink, TestSource }
- import akka.testkit._
- class Example extends TestKit(ActorSystem("ProxySpec")) with ImplicitSender
- with FlatSpecLike with Matchers with BeforeAndAfterAll {
- "httpOutgoingConnectionHttps" should "be able to get a git repo" in {
- val http = Http(system)
- implicit val materializer = ActorMaterializer()
- val uri = Uri("https://github.com/akka/akka-http.git/info/refs?service=git-upload-pack")
- val connFlow = http.outgoingConnectionHttps(uri.authority.host.address, uri.effectivePort)
- val (pub, sub) = TestSource.probe[HttpRequest]
- .via(connFlow)
- .toMat(TestSink.probe[HttpResponse])(Keep.both)
- .run()
- val r = HttpRequest(uri = uri).withHeaders(
- Accept(MediaRange(MediaType.customWithOpenCharset("*", "*", allowArbitrarySubtypes = true))),
- //`User-Agent`("curl/7.50.3"),
- //Host(uri.authority.host)
- )
- sub.request(n = 1)
- pub.sendNext(r)
- val res = sub.expectNext(10.seconds)
- val resBody = Await.result(res.entity.toStrict(10.seconds).map(_.data.decodeString("UTF-8")), 10.seconds)
- println(s"----> ${res.status}")
- println(s"----> ${resBody}")
- resBody should not be ("Not Found")
- res.status should be(200)
- }
- override def afterAll {
- TestKit.shutdownActorSystem(system)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement