Skip to content

Commit

Permalink
Close sttp client in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin committed Dec 24, 2020
1 parent 46d9c57 commit f483fe2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.azavea.stac4s.api.client

import com.azavea.stac4s.testing.JsInstances

import cats.syntax.either._
import eu.timepit.refined.types.all.NonEmptyString
import io.circe.JsonObject
import io.circe.syntax._
import org.scalatest.BeforeAndAfterAll
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers
import sttp.client3.testing.SttpBackendStub
import sttp.client3.{Response, UriContext}
import sttp.monad.EitherMonad

class StacClientSpec extends AnyFunSpec with Matchers with JsInstances {
class StacClientSpec extends AnyFunSpec with Matchers with JsInstances with BeforeAndAfterAll {

lazy val backend =
SttpBackendStub(EitherMonad)
Expand Down Expand Up @@ -69,4 +69,6 @@ class StacClientSpec extends AnyFunSpec with Matchers with JsInstances {
.size should be > 0
}
}

override def afterAll(): Unit = backend.close().valueOr(throw _)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.azavea.stac4s.api.client

import com.azavea.stac4s.testing.JvmInstances

import cats.effect.{Blocker, IO}
import cats.syntax.applicative._
import cats.syntax.either._
Expand All @@ -10,15 +9,16 @@ import eu.timepit.refined.collection.Empty
import eu.timepit.refined.types.all.NonEmptyString
import io.circe.JsonObject
import io.circe.syntax._
import org.scalatest.BeforeAndAfterAll
import sttp.client3.asynchttpclient.cats.AsyncHttpClientCatsBackend
import sttp.client3.http4s.Http4sBackend
import sttp.client3.impl.cats.CatsMonadAsyncError
import sttp.client3.testing.SttpBackendStub
import sttp.client3.{Response, UriContext}

class StacClientSpec extends IOSpec with JvmInstances {
class StacClientSpec extends IOSpec with JvmInstances with BeforeAndAfterAll {

lazy val backend: SttpBackendStub[IO, Nothing] =
lazy val backend =
SttpBackendStub(new CatsMonadAsyncError[IO]())
.whenRequestMatches(_.uri.path == Seq("search"))
.thenRespondF { _ =>
Expand Down Expand Up @@ -88,4 +88,6 @@ class StacClientSpec extends IOSpec with JvmInstances {
res map (_ shouldNot be(Empty))
}
}

override def afterAll(): Unit = backend.close().unsafeRunSync()
}

0 comments on commit f483fe2

Please sign in to comment.