Skip to content

Commit

Permalink
refactor: move java scheme generators to SchemeSpec (#944)
Browse files Browse the repository at this point in the history
* refactor: move java scheme generators to SchemeSpec

* refactor: resolve PR comments
  • Loading branch information
girdharshubham authored Feb 2, 2022
1 parent 1e8d81b commit 1ebc70f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 9 additions & 4 deletions zio-http/src/test/scala/zhttp/http/SchemeSpec.scala
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
package zhttp.http

import io.netty.handler.codec.http.HttpScheme
import io.netty.handler.codec.http.websocketx.WebSocketScheme
import zhttp.internal.HttpGen
import zio.test._

object SchemeSpec extends DefaultRunnableSpec {
def schemeSpec = suite("SchemeSpec") {
override def spec = suite("SchemeSpec") {
testM("string") {
checkAll(HttpGen.scheme) { scheme =>
assertTrue(Scheme.decode(scheme.encode).get == scheme)
}
} +
testM("java http scheme") {
checkAll(HttpGen.jHttpScheme) { jHttpScheme =>
checkAll(jHttpScheme) { jHttpScheme =>
assertTrue(Scheme.fromJScheme(jHttpScheme).flatMap(_.toJHttpScheme).get == jHttpScheme)
}
} +
testM("java websocket scheme") {
checkAll(HttpGen.jWebSocketScheme) { jWebSocketScheme =>
checkAll(jWebSocketScheme) { jWebSocketScheme =>
assertTrue(
Scheme.fromJScheme(jWebSocketScheme).flatMap(_.toWebSocketScheme).get == jWebSocketScheme,
)
}
}
}

override def spec = schemeSpec
private def jHttpScheme: Gen[Any, HttpScheme] = Gen.fromIterable(List(HttpScheme.HTTP, HttpScheme.HTTPS))

private def jWebSocketScheme: Gen[Any, WebSocketScheme] =
Gen.fromIterable(List(WebSocketScheme.WS, WebSocketScheme.WSS))
}
6 changes: 1 addition & 5 deletions zio-http/src/test/scala/zhttp/internal/HttpGen.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package zhttp.internal

import io.netty.buffer.Unpooled
import io.netty.handler.codec.http.HttpScheme
import io.netty.handler.codec.http.websocketx.WebSocketScheme
import zhttp.http.Scheme.{HTTP, HTTPS, WS, WSS}
import zhttp.http.URL.Location
import zhttp.http._
Expand Down Expand Up @@ -96,9 +94,7 @@ object HttpGen {
),
)

def scheme: Gen[Any, Scheme] = Gen.fromIterable(List(HTTP, HTTPS, WS, WSS))
def jHttpScheme: Gen[Any, HttpScheme] = Gen.fromIterable(List(HttpScheme.HTTP, HttpScheme.HTTPS))
def jWebSocketScheme: Gen[Any, WebSocketScheme] = Gen.fromIterable(List(WebSocketScheme.WS, WebSocketScheme.WSS))
def scheme: Gen[Any, Scheme] = Gen.fromIterable(List(HTTP, HTTPS, WS, WSS))

def nonEmptyHttpData[R](gen: Gen[R, List[String]]): Gen[R, HttpData] =
for {
Expand Down

1 comment on commit 1ebc70f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance Benchmark:

Concurrency: 256
Requests/sec: 917690.42

Please sign in to comment.