-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat(zio): support Native #432
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
package sttp.capabilities.fs2 | ||
|
||
import cats.effect.IO | ||
import cats.effect.unsafe.implicits.global | ||
import cats.effect.unsafe | ||
import fs2._ | ||
import org.scalatest.flatspec.AsyncFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import sttp.capabilities.StreamMaxLengthExceededException | ||
|
||
class Fs2StreamsTest extends AsyncFlatSpec with Matchers { | ||
|
||
implicit val runtime: unsafe.IORuntime = unsafe.IORuntime( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect this is different from the default - could you add a comment how it is different, and why the change is made? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the scalatest suites have an implicit |
||
executionContext, | ||
executionContext, | ||
unsafe.IORuntime.global.scheduler, | ||
unsafe.IORuntime.global.shutdown, | ||
unsafe.IORuntime.global.config | ||
) | ||
|
||
behavior of "Fs2Streams" | ||
|
||
it should "Pass all bytes if limit is not exceeded" in { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,44 @@ | ||
package sttp.capabilities.zio | ||
|
||
import org.scalatest.flatspec.AsyncFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import sttp.capabilities.StreamMaxLengthExceededException | ||
import zio._ | ||
import zio.stream.ZStream | ||
|
||
class ZioStreamsTest extends AsyncFlatSpec with Matchers { | ||
behavior of "ZioStreams" | ||
|
||
implicit val r: Runtime[Any] = Runtime.default | ||
|
||
it should "Pass all bytes if limit is not exceeded" in { | ||
// given | ||
val inputByteCount = 8192 | ||
val maxBytes = 8192L | ||
val inputStream = ZStream.fromIterator(Iterator.fill[Byte](inputByteCount)('5'.toByte)) | ||
|
||
// when | ||
val stream = ZioStreams.limitBytes(inputStream, maxBytes) | ||
|
||
// then | ||
Unsafe.unsafe(implicit u => | ||
r.unsafe.runToFuture(stream.runFold(0L)((acc, _) => acc + 1).map { count => | ||
count shouldBe inputByteCount | ||
}) | ||
) | ||
} | ||
|
||
it should "Fail stream if limit is exceeded" in { | ||
// given | ||
val inputByteCount = 8192 | ||
val maxBytes = 8191L | ||
val inputStream = ZStream.fromIterator(Iterator.fill[Byte](inputByteCount)('5'.toByte)) | ||
|
||
// when | ||
val stream = ZioStreams.limitBytes(inputStream, maxBytes) | ||
|
||
// then | ||
Unsafe.unsafe(implicit u => | ||
r.unsafe.runToFuture( | ||
stream.runLast | ||
.flatMap(_ => ZIO.succeed(fail("Unexpected end of stream"))) | ||
.catchSome { | ||
import zio.test._ | ||
|
||
object ZioStreamsTest extends ZIOSpecDefault { | ||
def spec: Spec[TestEnvironment, Any] = suite("ZioStreams")( | ||
test("should Pass all bytes if limit is not exceeded") { | ||
// given | ||
val inputByteCount = 8192 | ||
val maxBytes = 8192L | ||
val inputStream = ZStream.fromIterator(Iterator.fill[Byte](inputByteCount)('5'.toByte)) | ||
|
||
// when | ||
val stream = ZioStreams.limitBytes(inputStream, maxBytes) | ||
|
||
// then | ||
for { | ||
count <- stream.runFold(0L)((acc, _) => acc + 1) | ||
} yield assertTrue(count == inputByteCount) | ||
}, | ||
test("should Fail stream if limit is exceeded") { | ||
val inputByteCount = 8192 | ||
val maxBytes = 8191L | ||
val inputStream = ZStream.fromIterator(Iterator.fill[Byte](inputByteCount)('5'.toByte)) | ||
|
||
// when | ||
val stream = ZioStreams.limitBytes(inputStream, maxBytes) | ||
|
||
// then | ||
for { | ||
limit <- stream.runLast.flip | ||
.flatMap { | ||
case StreamMaxLengthExceededException(limit) => | ||
ZIO.succeed(limit shouldBe maxBytes) | ||
ZIO.succeed(limit) | ||
case other => | ||
ZIO.succeed(fail(s"Unexpected failure cause: $other")) | ||
ZIO.fail(s"Unexpected failure cause: $other") | ||
} | ||
) | ||
) | ||
} | ||
} yield assertTrue(limit == maxBytes) | ||
} | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that why JS tests were not executed? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes