Skip to content

Instantly share code, notes, and snippets.

@erdebee
Created August 12, 2020 12:49
Show Gist options
  • Select an option

  • Save erdebee/2fcfb552a928489d0fd69f1a899b5393 to your computer and use it in GitHub Desktop.

Select an option

Save erdebee/2fcfb552a928489d0fd69f1a899b5393 to your computer and use it in GitHub Desktop.
ZIO Test Managed in stream from iterator
import java.io.{File, FileInputStream, InputStream}
import zio.stream.Stream
import zio.test._
import zio.{Managed, Task, ZManaged}
object BugShowOff extends DefaultRunnableSpec {
private val importfileName = getClass.getClassLoader.getResource("test_import_ISO-8859-1.zip")
private val managedInputStream: ZManaged[Any, Throwable, InputStream] = Managed.makeEffect({
val file = new File(importfileName.toURI)
new FileInputStream(file)
}) (fis => Task(fis.close()).orDie)
def simpleStreamFunction(in: InputStream): Stream[Throwable, Int] = {
Stream.fromIterator(parseIS(in))
}
def parseIS(in: InputStream): Iterator[Int] = {
new Iterator[Int]{
override def hasNext: Boolean = in.available() > 0
override def next(): Int = in.read()
}
}
override def spec: ZSpec[ZTestEnv, Any] =
suite("ZManaged with Stream should")(
testM("not fail")(
assertM(
managedInputStream.use(is => simpleStreamFunction(is).runSum)
)(Assertion.anything)
)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment