Skip to content

Commit

Permalink
Tests Cleanup (#2379)
Browse files Browse the repository at this point in the history
* test aspects

* samples
  • Loading branch information
adamgfraser authored Aug 12, 2023
1 parent 70eb173 commit b1c9380
Show file tree
Hide file tree
Showing 111 changed files with 246 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import zio.test._

import zio.http.ChannelEvent.{Read, Unregistered, UserEvent, UserEventTriggered}
import zio.http.netty.server.NettyDriver
import zio.http.{Headers, Status, Version}
import zio.http.{Headers, Status, Version, ZIOHttpSpec}

object SocketContractSpec extends ZIOSpecDefault {
object SocketContractSpec extends ZIOHttpSpec {

def spec: Spec[Any, Any] =
suite("SocketOps")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import zio.test._
import zio.http.ChannelEvent.{Read, UserEvent, UserEventTriggered}
import zio.http.{Method, Status, WebSocketFrame}

object TestClientSpec extends ZIOSpecDefault {
object TestClientSpec extends ZIOHttpSpec {
def extractStatus(response: Response): Status = response.status

def spec =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import zio.test._

import zio.http.netty.server.NettyDriver

object TestServerSpec extends ZIOSpecDefault {
object TestServerSpec extends ZIOHttpSpec {
def status(response: Response): Status = response.status

def spec = suite("TestServerSpec")(
Expand Down
9 changes: 9 additions & 0 deletions zio-http-testkit/src/test/scala/zio/http/ZIOHttpSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package zio.http

import zio._
import zio.test._

trait ZIOHttpSpec extends ZIOSpecDefault {
override def aspects: Chunk[TestAspectPoly] =
Chunk(TestAspect.timeout(60.seconds), TestAspect.timed)
}
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/BodySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import zio.{Scope, durationInt}

import zio.stream.ZStream

object BodySpec extends ZIOSpecDefault {
object BodySpec extends ZIOHttpSpec {
private val testFile = new File(getClass.getResource("/TestFile.txt").getPath)

override def spec: Spec[TestEnvironment with Scope, Throwable] =
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/BoundarySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import zio.test._

import zio.http.forms.Fixtures._

object BoundarySpec extends ZIOSpecDefault {
object BoundarySpec extends ZIOHttpSpec {
val CRLF = "\r\n"

val multipartFormBytes3 = Chunk.fromArray(s"""------heythere--${CRLF}""".getBytes(StandardCharsets.UTF_8))
Expand Down
4 changes: 2 additions & 2 deletions zio-http/src/test/scala/zio/http/ClientHttpsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package zio.http

import zio.test.Assertion.{anything, equalTo, fails, hasField}
import zio.test.TestAspect.{ignore, timeout}
import zio.test.{ZIOSpecDefault, assertZIO}
import zio.test.assertZIO
import zio.{Scope, ZLayer, durationInt}

import zio.http.netty.NettyConfig
import zio.http.netty.client.NettyClientDriver

object ClientHttpsSpec extends ZIOSpecDefault {
object ClientHttpsSpec extends ZIOHttpSpec {

val sslConfig = ClientSSLConfig.FromTrustStoreResource(
trustStorePath = "truststore.jks",
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/CookieSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import zio.test._

import zio.http.Cookie.SameSite

object CookieSpec extends ZIOSpecDefault {
object CookieSpec extends ZIOHttpSpec {
override def spec =
suite("CookieSpec")(
suite("getter")(
Expand Down
4 changes: 2 additions & 2 deletions zio-http/src/test/scala/zio/http/DnsResolverSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package zio.http
import java.net.{InetAddress, UnknownHostException}

import zio._
import zio.test.{Spec, TestClock, TestEnvironment, ZIOSpecDefault, assertTrue}
import zio.test.{Spec, TestClock, TestEnvironment, assertTrue}

import zio.http.DnsResolver.ExpireAction

object DnsResolverSpec extends ZIOSpecDefault {
object DnsResolverSpec extends ZIOHttpSpec {
override def spec: Spec[TestEnvironment with Scope, Any] =
suite("DnsResolver")(
test("eventually maintains the specified max count") {
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/DynamicAppTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import zio.test._
import zio.http.netty.NettyConfig
import zio.http.netty.client.NettyClientDriver

object DynamicAppTest extends ZIOSpecDefault {
object DynamicAppTest extends ZIOHttpSpec {
def extractStatus(response: Response): Status = response.status

val httpApp1: HttpApp[Any] =
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/FormHeaderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import zio.test._

import zio.http.internal.FormAST

object FormHeaderSpec extends ZIOSpecDefault {
object FormHeaderSpec extends ZIOHttpSpec {

val contentType1 = "Content-Type: text/html; charset=utf-8".getBytes()
val contextType2 = "Content-Type: multipart/form-data; boundary=something".getBytes
Expand Down
5 changes: 3 additions & 2 deletions zio-http/src/test/scala/zio/http/FormSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import scala.annotation.nowarn

import zio._
import zio.test.Assertion._
import zio.test.TestAspect._
import zio.test._

import zio.stream.{ZStream, ZStreamAspect}

import zio.http.Header.ContentTransferEncoding
import zio.http.forms.Fixtures._

object FormSpec extends ZIOSpecDefault {
object FormSpec extends ZIOHttpSpec {
def extractStatus(response: Response): Status = response.status

val urlEncodedSuite =
Expand Down Expand Up @@ -308,7 +309,7 @@ object FormSpec extends ZIOSpecDefault {
collected.get("file").get.asInstanceOf[FormField.Binary].data == bytes,
)
}
},
} @@ samples(10),
)

def spec =
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/GetBodyAsStringSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import zio.Chunk
import zio.test.Assertion._
import zio.test._

object GetBodyAsStringSpec extends ZIOSpecDefault {
object GetBodyAsStringSpec extends ZIOHttpSpec {

def spec = suite("getBodyAsString") {
val charsetGen: Gen[Any, Charset] =
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/HandlerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import zio.test.Assertion._
import zio.test.TestAspect.timeout
import zio.test._

object HandlerSpec extends ZIOSpecDefault with ExitAssertion {
object HandlerSpec extends ZIOHttpSpec with ExitAssertion {

def spec = suite("Handler")(
suite("sandbox")(
Expand Down
4 changes: 2 additions & 2 deletions zio-http/src/test/scala/zio/http/HeaderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package zio.http

import zio.NonEmptyChunk
import zio.test.Assertion._
import zio.test.{ZIOSpecDefault, assert}
import zio.test.assert

object HeaderSpec extends ZIOSpecDefault {
object HeaderSpec extends ZIOHttpSpec {

def spec = suite("Header")(
suite("getHeader")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import zio.test._

import zio.http.Method

object HttpAppMiddlewareSpec extends ZIOSpecDefault with ExitAssertion {
object HttpAppMiddlewareSpec extends ZIOHttpSpec with ExitAssertion {

def spec: Spec[Any, Any] =
suite("HttpAppMiddleware")(
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/HttpAppSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import zio._
import zio.test.Assertion._
import zio.test._

object HttpAppSpec extends ZIOSpecDefault {
object HttpAppSpec extends ZIOHttpSpec {
def extractStatus(response: Response): Status = response.status

def spec = suite("HttpAppSpec")(
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/MediaTypeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package zio.http

import zio.test._

object MediaTypeSpec extends ZIOSpecDefault {
object MediaTypeSpec extends ZIOHttpSpec {
import MediaType._

override def spec = suite("MediaTypeSpec")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import zio.test.TestAspect.withLiveClock
import zio.test._
import zio.{Scope, ZLayer}

object NettyMaxHeaderLengthSpec extends ZIOSpecDefault {
object NettyMaxHeaderLengthSpec extends ZIOHttpSpec {
def extractStatus(response: Response): Status = response.status

private val serverConfig: Server.Config = Server.Config.default.onAnyOpenPort.copy(maxHeaderSize = 1)
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/PathSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import zio.test._

import zio.http.internal.HttpGen

object PathSpec extends ZIOSpecDefault with ExitAssertion {
object PathSpec extends ZIOHttpSpec with ExitAssertion {
import Path.Flag

val a = "a"
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/QueryParamsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import zio.test.Assertion.equalTo
import zio.test._
import zio.{Chunk, ZIO}

object QueryParamsSpec extends ZIOSpecDefault {
object QueryParamsSpec extends ZIOHttpSpec {

def spec =
suite("QueryParams")(
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/RequestSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package zio.http
import zio.Scope
import zio.test._

object RequestSpec extends ZIOSpecDefault {
object RequestSpec extends ZIOHttpSpec {

def spec: Spec[TestEnvironment with Scope, Any] = suite("Result")(
test("`#default`") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import java.io.ByteArrayInputStream
import java.nio.charset.StandardCharsets

import zio.test.TestAspect.withLiveClock
import zio.test.{ZIOSpecDefault, assertTrue}
import zio.test.assertTrue
import zio.{Chunk, Scope, ZIO, ZInputStream, ZLayer}

import zio.stream.ZStream

object ResponseCompressionSpec extends ZIOSpecDefault {
object ResponseCompressionSpec extends ZIOHttpSpec {

private val text: HttpApp[Any] =
Routes(
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/ResponseSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import zio._
import zio.test.Assertion._
import zio.test._

object ResponseSpec extends ZIOSpecDefault {
object ResponseSpec extends ZIOHttpSpec {
def extractStatus(response: Response): Status = response.status
private val location: URL = URL.decode("www.google.com").toOption.get

Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/RoutePatternSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import zio.test._
import zio.http.internal.HttpGen
import zio.http.{int => _, uuid => _, _}

object RoutePatternSpec extends ZIOSpecDefault {
object RoutePatternSpec extends ZIOHttpSpec {
import zio.http.Method
import zio.http.RoutePattern._

Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/RouteSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import scala.collection.Seq
import zio._
import zio.test._

object RouteSpec extends ZIOSpecDefault {
object RouteSpec extends ZIOHttpSpec {
def extractStatus(response: Response): Status = response.status

def spec = suite("RouteSpec")(
Expand Down
4 changes: 2 additions & 2 deletions zio-http/src/test/scala/zio/http/SSLSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package zio.http

import zio.test.Assertion.equalTo
import zio.test.TestAspect.{ignore, timeout}
import zio.test.{Gen, ZIOSpecDefault, assertZIO, check}
import zio.test.{Gen, assertZIO, check}
import zio.{Scope, ZIO, ZLayer, durationInt}

import zio.http.netty.NettyConfig
import zio.http.netty.client.NettyClientDriver

object SSLSpec extends ZIOSpecDefault {
object SSLSpec extends ZIOHttpSpec {

val sslConfig = SSLConfig.fromResource("server.crt", "server.key")
val config = Server.Config.default.port(8073).ssl(sslConfig)
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/SchemeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import zio.test._

import zio.http.internal.HttpGen

object SchemeSpec extends ZIOSpecDefault {
object SchemeSpec extends ZIOHttpSpec {
override def spec = suite("SchemeSpec")(
test("string decode") {
checkAll(HttpGen.scheme) { scheme =>
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/StatusSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import zio.test._

import zio.http.internal.HttpGen

object StatusSpec extends ZIOSpecDefault {
object StatusSpec extends ZIOHttpSpec {
private val statusGen = HttpGen.status

def spec = suite("Status")(
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/URLSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import zio.test._

import zio.http.internal.HttpGen

object URLSpec extends ZIOSpecDefault {
object URLSpec extends ZIOHttpSpec {
def extractPath(url: URL): Path = url.path
def asURL(string: String): URL = URL.decode(string).toOption.get

Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/ZClientAspectSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import zio.{Chunk, Scope, ZIO, ZLayer}

import zio.http.URL.Location

object ZClientAspectSpec extends ZIOSpecDefault {
object ZClientAspectSpec extends ZIOHttpSpec {
def extractStatus(response: Response): Status = response.status

val app: HttpApp[Any] = Handler.fromFunction[Request] { _ => Response.text("hello") }.toHttpApp
Expand Down
9 changes: 9 additions & 0 deletions zio-http/src/test/scala/zio/http/ZIOHttpSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package zio.http

import zio._
import zio.test._

trait ZIOHttpSpec extends ZIOSpecDefault {
override def aspects: Chunk[TestAspectPoly] =
Chunk(TestAspect.timeout(60.seconds), TestAspect.timed)
}
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/codec/HttpCodecSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import zio.test._

import zio.http._

object HttpCodecSpec extends ZIOSpecDefault {
object HttpCodecSpec extends ZIOHttpSpec {
val googleUrl = URL.decode("http://google.com").toOption.get
val usersUrl = URL.decode("http://mywebservice.com/users").toOption.get
val usersIdUrl = URL.decode("http://mywebservice.com/users/42").toOption.get
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zio/http/codec/PathCodecSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import zio.test._
import zio.http._
import zio.http.codec._

object PathCodecSpec extends ZIOSpecDefault {
object PathCodecSpec extends ZIOHttpSpec {
def spec =
suite("PathCodecSpec")(
suite("parsing")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ package zio.http.codec
import zio.test.Assertion.equalTo
import zio.test._

object RichTextCodecSpec extends ZIOSpecDefault {
import zio.http.ZIOHttpSpec

object RichTextCodecSpec extends ZIOHttpSpec {

def success[A](a: A): Either[String, A] = Right(a)

Expand Down
4 changes: 3 additions & 1 deletion zio-http/src/test/scala/zio/http/endpoint/DocSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ package zio.http.endpoint

import zio.test._

import zio.http.ZIOHttpSpec
import zio.http.codec.Doc
import zio.http.codec.Doc._
object DocSpec extends ZIOSpecDefault {

object DocSpec extends ZIOHttpSpec {
override def spec = suite("DocSpec")(
test("common mark rendering") {
val complexDoc = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package zio.http.endpoint
import zio._
import zio.test.Assertion._
import zio.test.TestAspect._
import zio.test.{Spec, TestResult, ZIOSpecDefault, assert}
import zio.test.{Spec, TestResult, assert}

import zio.stream.ZStream

Expand All @@ -32,7 +32,7 @@ import zio.http.codec.HttpCodec.{authorization, query}
import zio.http.codec.{Doc, HttpCodec, QueryCodec}
import zio.http.netty.server.NettyDriver

object EndpointRoundtripSpec extends ZIOSpecDefault {
object EndpointRoundtripSpec extends ZIOHttpSpec {
val testLayer: ZLayer[Any, Throwable, Server & Client & Scope] =
ZLayer.make[Server & Client & Scope](
Server.live,
Expand Down
Loading

0 comments on commit b1c9380

Please sign in to comment.