I\'ve just started testing out the Akka HTTP Request-Level Client-Side API (Future-Based). One thing I\'ve been struggling to figure out is how to write a unit test for this. Is
I was hoping there might be a way to leverage some sort of test actor system but in the absence of that (or some other idiomatic way) I am probably going to do something like this:
object S3Bucket {
type HttpResponder = HttpRequest => Future[HttpResponse]
def defaultResponder = Http().singleRequest(_)
def sampleTextFile(uri: Uri)(
implicit akkaSystem: ActorSystem,
akkaMaterializer: ActorMaterializer,
responder: HttpResponder = defaultResponder
): Future[String] = {
val request = responder(HttpRequest(uri = uri))
request.map { response => Unmarshal(response.entity).to[String] }
}
}
Then in my test I can just provide a mock HttpResponder
.