Skip to content

Commit b8a114a

Browse files
committed
feat(zio): support Native
1 parent ecd89b8 commit b8a114a

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed

build.sbt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def dependenciesFor(version: String)(deps: (Option[(Long, Long)] => ModuleID)*):
2727
val commonSettings = commonSmlBuildSettings ++ ossPublishSettings ++ Seq(
2828
organization := "com.softwaremill.sttp.shared",
2929
libraryDependencies ++= Seq(
30-
"org.scalatest" %% "scalatest" % scalaTestVersion % Test
30+
"org.scalatest" %%% "scalatest" % scalaTestVersion % Test
3131
),
3232
mimaPreviousArtifacts := Set.empty,
3333
versionScheme := Some("semver-spec")
@@ -59,14 +59,15 @@ val commonJsSettings = commonSettings ++ Seq(
5959
}
6060
},
6161
libraryDependencies ++= Seq(
62-
"org.scala-js" %%% "scalajs-dom" % "2.8.0"
62+
"org.scala-js" %%% "scalajs-dom" % "2.8.0",
63+
"io.github.cquiroz" %%% "scala-java-time" % "2.6.0" % Test
6364
)
6465
)
6566

6667
val commonNativeSettings = commonSettings ++ Seq(
6768
ideSkipProject := true,
6869
libraryDependencies ++= Seq(
69-
"org.scala-native" %%% "test-interface" % nativeVersion
70+
"io.github.cquiroz" %%% "scala-java-time" % "2.6.0" % Test
7071
)
7172
)
7273

@@ -231,7 +232,12 @@ lazy val zio1 = (projectMatrix in file("zio1"))
231232
lazy val zio = (projectMatrix in file("zio"))
232233
.settings(
233234
name := "zio",
234-
libraryDependencies ++= Seq("dev.zio" %%% "zio-streams" % zio2Version, "dev.zio" %%% "zio" % zio2Version)
235+
libraryDependencies ++= Seq("dev.zio" %%% "zio-streams" % zio2Version, "dev.zio" %%% "zio" % zio2Version) ++
236+
Seq(
237+
"dev.zio" %%% "zio-test" % zio2Version % Test,
238+
"dev.zio" %%% "zio-test-sbt" % zio2Version % Test
239+
),
240+
testFrameworks += TestFrameworks.ZIOTest
235241
)
236242
.jvmPlatform(
237243
scalaVersions = scala2 ++ scala3,
@@ -241,6 +247,10 @@ lazy val zio = (projectMatrix in file("zio"))
241247
scalaVersions = scala2alive ++ scala3,
242248
settings = commonJsSettings ++ browserChromeTestSettings
243249
)
250+
.nativePlatform(
251+
scalaVersions = scala3,
252+
settings = commonNativeSettings
253+
)
244254
.dependsOn(core)
245255

246256
lazy val vertx = (projectMatrix in file("vertx"))
Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,44 @@
11
package sttp.capabilities.zio
22

3-
import org.scalatest.flatspec.AsyncFlatSpec
4-
import org.scalatest.matchers.should.Matchers
53
import sttp.capabilities.StreamMaxLengthExceededException
64
import zio._
75
import zio.stream.ZStream
8-
9-
class ZioStreamsTest extends AsyncFlatSpec with Matchers {
10-
behavior of "ZioStreams"
11-
12-
implicit val r: Runtime[Any] = Runtime.default
13-
14-
it should "Pass all bytes if limit is not exceeded" in {
15-
// given
16-
val inputByteCount = 8192
17-
val maxBytes = 8192L
18-
val inputStream = ZStream.fromIterator(Iterator.fill[Byte](inputByteCount)('5'.toByte))
19-
20-
// when
21-
val stream = ZioStreams.limitBytes(inputStream, maxBytes)
22-
23-
// then
24-
Unsafe.unsafe(implicit u =>
25-
r.unsafe.runToFuture(stream.runFold(0L)((acc, _) => acc + 1).map { count =>
26-
count shouldBe inputByteCount
27-
})
28-
)
29-
}
30-
31-
it should "Fail stream if limit is exceeded" in {
32-
// given
33-
val inputByteCount = 8192
34-
val maxBytes = 8191L
35-
val inputStream = ZStream.fromIterator(Iterator.fill[Byte](inputByteCount)('5'.toByte))
36-
37-
// when
38-
val stream = ZioStreams.limitBytes(inputStream, maxBytes)
39-
40-
// then
41-
Unsafe.unsafe(implicit u =>
42-
r.unsafe.runToFuture(
43-
stream.runLast
44-
.flatMap(_ => ZIO.succeed(fail("Unexpected end of stream")))
45-
.catchSome {
6+
import zio.test._
7+
8+
object ZioStreamsTest extends ZIOSpecDefault {
9+
def spec: Spec[TestEnvironment, Any] = suite("ZioStreams")(
10+
test("should Pass all bytes if limit is not exceeded") {
11+
// given
12+
val inputByteCount = 8192
13+
val maxBytes = 8192L
14+
val inputStream = ZStream.fromIterator(Iterator.fill[Byte](inputByteCount)('5'.toByte))
15+
16+
// when
17+
val stream = ZioStreams.limitBytes(inputStream, maxBytes)
18+
19+
// then
20+
for {
21+
count <- stream.runFold(0L)((acc, _) => acc + 1)
22+
} yield assertTrue(count == inputByteCount)
23+
},
24+
test("should Fail stream if limit is exceeded") {
25+
val inputByteCount = 8192
26+
val maxBytes = 8191L
27+
val inputStream = ZStream.fromIterator(Iterator.fill[Byte](inputByteCount)('5'.toByte))
28+
29+
// when
30+
val stream = ZioStreams.limitBytes(inputStream, maxBytes)
31+
32+
// then
33+
for {
34+
limit <- stream.runLast.flip
35+
.flatMap {
4636
case StreamMaxLengthExceededException(limit) =>
47-
ZIO.succeed(limit shouldBe maxBytes)
37+
ZIO.succeed(limit)
4838
case other =>
49-
ZIO.succeed(fail(s"Unexpected failure cause: $other"))
39+
ZIO.fail(s"Unexpected failure cause: $other")
5040
}
51-
)
52-
)
53-
}
41+
} yield assertTrue(limit == maxBytes)
42+
}
43+
)
5444
}

0 commit comments

Comments
 (0)