Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor test to include IO instance #664

Merged
merged 2 commits into from
Nov 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ import munit.CatsEffectSuite

import InMemory.{Lineage, NatchezCommand}

class KleisliTest extends CatsEffectSuite {
test("span propagation") {
def prg[F[_]: Trace] =
Trace[F].span("parent")(Trace[F].span("child")(Trace[F].put("answer" -> 42)))
class SpanPropagationTest extends CatsEffectSuite {
def prg[F[_]: Trace] =
Trace[F].span("parent")(Trace[F].span("child")(Trace[F].put("answer" -> 42)))

def testPropagation[F[_]](f: Span[IO] => IO[(Trace[F], F[Unit] => IO[Unit])]) =
InMemory.EntryPoint.create.flatMap { ep =>
val traced = ep.root("root").use(prg[Kleisli[IO, Span[IO], *]].run)
val traced = ep.root("root").use { r =>
f(r).flatMap { case (traceInstance, resolve) =>
resolve(prg(traceInstance))
}
}
traced *> ep.ref.get.map { history =>
assertEquals(
history.toList,
Expand All @@ -32,5 +36,14 @@ class KleisliTest extends CatsEffectSuite {
)
}
}

test("kleisli") {
testPropagation[Kleisli[IO, Span[IO], *]](root =>
IO.pure(Trace[Kleisli[IO, Span[IO], *]] -> (k => k.run(root)))
)
}

test("io") {
testPropagation[IO](root => Trace.ioTrace(root).map(_ -> identity))
}
}