-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make client tests async so we can run them on JS. Move client testserver into its own sbt subproject so we can use it from the ScalaTest JS runner.
- Loading branch information
Showing
27 changed files
with
417 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
client/sttp-client/src/main/scala/sttp/tapir/client/sttp/SttpClientOptions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions
5
client/sttp-client/src/test/scala/sttp/tapir/client/sttp/SttpClientRequestTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
client/sttp-client/src/test/scalajs/sttp/tapir/client/sttp/SttpClientTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package sttp.tapir.client.sttp | ||
|
||
import cats.effect.{ContextShift, IO} | ||
|
||
import scala.concurrent.Future | ||
import sttp.tapir.{DecodeResult, Endpoint} | ||
import sttp.tapir.client.tests.ClientTests | ||
import sttp.client3._ | ||
|
||
abstract class SttpClientTests[R >: Any] extends ClientTests[R] { | ||
implicit val cs: ContextShift[IO] = IO.contextShift(executionContext) | ||
val backend: SttpBackend[Future, R] = FetchBackend() | ||
def wsToPipe: WebSocketToPipe[R] | ||
|
||
override def send[I, E, O, FN[_]](e: Endpoint[I, E, O, R], port: Port, args: I, scheme: String = "http"): IO[Either[E, O]] = { | ||
implicit val wst: WebSocketToPipe[R] = wsToPipe | ||
val response: Future[Either[E, O]] = | ||
e.toSttpRequestUnsafe(uri"$scheme://localhost:$port").apply(args).send(backend).map(_.body) | ||
IO.fromFuture(IO(response)) | ||
} | ||
|
||
override def safeSend[I, E, O, FN[_]]( | ||
e: Endpoint[I, E, O, R], | ||
port: Port, | ||
args: I | ||
): IO[DecodeResult[Either[E, O]]] = { | ||
implicit val wst: WebSocketToPipe[R] = wsToPipe | ||
def response: Future[DecodeResult[Either[E, O]]] = | ||
e.toSttpRequest(uri"http://localhost:$port").apply(args).send(backend).map(_.body) | ||
IO.fromFuture(IO(response)) | ||
} | ||
|
||
override protected def afterAll(): Unit = { | ||
backend.close() | ||
super.afterAll() | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.