I have an interpreter for an algebra and I would like to write a unit test for it.
The interpreter is as follows:
final case class LiveDbConnector[F[_] : MonadError[*[_], Throwable]](env: Environment[F]) extends DbConnector[F] {
override def read(url: DbUrl, user: DbUser, pw: DbPw): F[DbParams] =
(for {
a <- OptionT(env.get(EnvVariable(url.v)))
b <- OptionT(env.get(EnvVariable(user.v)))
c <- OptionT(env.get(EnvVariable(pw.v)))
} yield DbParams(DbUrl(a.v), DbUser(b.v), DbPw(c.v)))
.value
.flatMap {
case Some(v) => v.pure[F]
case None => DbSettingError.raiseError[F, DbParams]
}
}
the algebra is as follows:
trait DbConnector[F[_]] {
def read(url: DbUrl, user: DbUser, pw: DbPw): F[DbParams]
}
the implementation is as follows:
final case class DbParams(url: DbUrl, user: DbUser, pw: DbPw)
object DbConnector {
def impl[F[_] : MonadError[*[_], Throwable]](env: Environment[F])
: DbConnector[F] =
new LiveDbConnector[F](env)
}
I use the test framework https://scalameta.org/munit/.
How to write unit test for my above algebra?
Aucun commentaire:
Enregistrer un commentaire