diff options
author | Li Haoyi <haoyi.li@databricks.com> | 2019-09-14 16:45:39 +0800 |
---|---|---|
committer | Li Haoyi <haoyi.li@databricks.com> | 2019-09-14 17:40:26 +0800 |
commit | 4e853a9d5b9563dbe1909757bf4be4d8e7d2b36a (patch) | |
tree | 684863947658d22f91804090c81a68d012b82b6c | |
parent | 90b6806e5fb91b207f9d8e2da2a58c25928badea (diff) | |
download | cask-4e853a9d5b9563dbe1909757bf4be4d8e7d2b36a.tar.gz cask-4e853a9d5b9563dbe1909757bf4be4d8e7d2b36a.tar.bz2 cask-4e853a9d5b9563dbe1909757bf4be4d8e7d2b36a.zip |
.
57 files changed, 221 insertions, 147 deletions
@@ -50,7 +50,7 @@ object cask extends ScalaModule with PublishModule { def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", // ivy"org.xerial:sqlite-jdbc:3.18.0", // ivy"io.getquill::quill-jdbc:2.6.0" diff --git a/cask/src/cask/endpoints/FormEndpoint.scala b/cask/src/cask/endpoints/FormEndpoint.scala index 471c5e5..436bed4 100644 --- a/cask/src/cask/endpoints/FormEndpoint.scala +++ b/cask/src/cask/endpoints/FormEndpoint.scala @@ -44,13 +44,13 @@ object FormReader{ } } class postForm(val path: String, override val subpath: Boolean = false) extends Endpoint { - type Output = Response + type InnerReturned = Response.Raw val methods = Seq("post") type Input = Seq[FormEntry] type InputParser[T] = FormReader[T] def wrapFunction(ctx: Request, - delegate: Map[String, Input] => Router.Result[Output]): Router.Result[Response] = { + delegate: Delegate): Router.Result[Response.Raw] = { try { val formData = FormParserFactory.builder().build().createParser(ctx.exchange).parseBlocking() delegate( @@ -62,7 +62,8 @@ class postForm(val path: String, override val subpath: Boolean = false) extends ) } catch{case e: Exception => Router.Result.Success(cask.model.Response( - "Unable to parse form data: " + e + "\n" + Util.stackTraceString(e) + "Unable to parse form data: " + e + "\n" + Util.stackTraceString(e), + statusCode = 400 )) } } diff --git a/cask/src/cask/endpoints/JsonEndpoint.scala b/cask/src/cask/endpoints/JsonEndpoint.scala index e0d1257..edf0c46 100644 --- a/cask/src/cask/endpoints/JsonEndpoint.scala +++ b/cask/src/cask/endpoints/JsonEndpoint.scala @@ -1,11 +1,11 @@ package cask.endpoints -import java.io.ByteArrayOutputStream +import java.io.{ByteArrayOutputStream, InputStream, OutputStream, OutputStreamWriter} import cask.internal.{Router, Util} import cask.main.Endpoint import cask.model.{Request, Response} - +import collection.JavaConverters._ sealed trait JsReader[T] extends Router.ArgReader[ujson.Value, T, cask.model.Request] object JsReader{ @@ -26,13 +26,25 @@ object JsReader{ } } } +trait JsonData extends Response.Data +object JsonData{ + implicit class JsonDataImpl[T: upickle.default.Writer](t: T) extends JsonData{ + def write(out: OutputStream) = { + val writer = new OutputStreamWriter(out) + implicitly[upickle.default.Writer[T]].write(new ujson.BaseRenderer(writer), t) + writer.flush() + } + } +} + class postJson(val path: String, override val subpath: Boolean = false) extends Endpoint{ - type Output = Response + type InnerReturned = Response[JsonData] val methods = Seq("post") - type Input = ujson.Js.Value + type Input = ujson.Value type InputParser[T] = JsReader[T] + override type OuterReturned = Router.Result[Response.Raw] def wrapFunction(ctx: Request, - delegate: Map[String, Input] => Router.Result[Output]): Router.Result[Response] = { + delegate: Delegate): Router.Result[Response.Raw] = { val obj = for{ str <- try { @@ -41,21 +53,42 @@ class postJson(val path: String, override val subpath: Boolean = false) extends Right(new String(boas.toByteArray)) } catch{case e: Throwable => Left(cask.model.Response( - "Unable to deserialize input JSON text: " + e + "\n" + Util.stackTraceString(e) + "Unable to deserialize input JSON text: " + e + "\n" + Util.stackTraceString(e), + statusCode = 400 ))} json <- try Right(ujson.read(str)) catch{case e: Throwable => Left(cask.model.Response( - "Input text is invalid JSON: " + e + "\n" + Util.stackTraceString(e) + "Input text is invalid JSON: " + e + "\n" + Util.stackTraceString(e), + statusCode = 400 ))} obj <- try Right(json.obj) - catch {case e: Throwable => Left(cask.model.Response("Input JSON must be a dictionary"))} + catch {case e: Throwable => Left(cask.model.Response( + "Input JSON must be a dictionary", + statusCode = 400 + ))} } yield obj.toMap obj match{ - case Left(r) => Router.Result.Success(r) - case Right(params) => delegate(params) + case Left(r) => Router.Result.Success(r.map(Response.Data.StringData)) + case Right(params) => delegate(params).map(_.data) } } - def wrapPathSegment(s: String): Input = ujson.Js.Str(s) + def wrapPathSegment(s: String): Input = ujson.Str(s) } + +class getJson(val path: String, override val subpath: Boolean = false) extends Endpoint{ + type InnerReturned = Response[JsonData] + val methods = Seq("get") + type Input = Seq[String] + type InputParser[T] = QueryParamReader[T] + override type OuterReturned = Router.Result[Response.Raw] + def wrapFunction(ctx: Request, + delegate: Delegate): Router.Result[Response.Raw] = { + + val res = delegate(WebEndpoint.buildMapFromQueryParams(ctx)) + + res.map(_.data) + } + def wrapPathSegment(s: String) = Seq(s) +}
\ No newline at end of file diff --git a/cask/src/cask/endpoints/StaticEndpoints.scala b/cask/src/cask/endpoints/StaticEndpoints.scala index fd194ca..401f845 100644 --- a/cask/src/cask/endpoints/StaticEndpoints.scala +++ b/cask/src/cask/endpoints/StaticEndpoints.scala @@ -4,12 +4,12 @@ import cask.main.Endpoint import cask.model.Request class staticFiles(val path: String) extends Endpoint{ - type Output = String + type InnerReturned = String val methods = Seq("get") type Input = Seq[String] type InputParser[T] = QueryParamReader[T] override def subpath = true - def wrapFunction(ctx: Request, delegate: Delegate): Returned = { + def wrapFunction(ctx: Request, delegate: Delegate): OuterReturned = { delegate(Map()).map(t => cask.model.StaticFile( (cask.internal.Util.splitPath(t) ++ ctx.remainingPathSegments) @@ -23,12 +23,12 @@ class staticFiles(val path: String) extends Endpoint{ } class staticResources(val path: String, resourceRoot: ClassLoader = getClass.getClassLoader) extends Endpoint{ - type Output = String + type InnerReturned = String val methods = Seq("get") type Input = Seq[String] type InputParser[T] = QueryParamReader[T] override def subpath = true - def wrapFunction(ctx: Request, delegate: Delegate): Returned = { + def wrapFunction(ctx: Request, delegate: Delegate): OuterReturned = { delegate(Map()).map(t => cask.model.StaticResource( (cask.internal.Util.splitPath(t) ++ ctx.remainingPathSegments) diff --git a/cask/src/cask/endpoints/WebEndpoints.scala b/cask/src/cask/endpoints/WebEndpoints.scala index ab3b480..7cac4f5 100644 --- a/cask/src/cask/endpoints/WebEndpoints.scala +++ b/cask/src/cask/endpoints/WebEndpoints.scala @@ -8,12 +8,17 @@ import collection.JavaConverters._ trait WebEndpoint extends Endpoint{ - type Output = Response + type InnerReturned = Response.Raw type Input = Seq[String] type InputParser[T] = QueryParamReader[T] def wrapFunction(ctx: Request, - delegate: Map[String, Input] => Router.Result[Output]): Router.Result[Response] = { - + delegate: Delegate): Router.Result[Response.Raw] = { + delegate(WebEndpoint.buildMapFromQueryParams(ctx)) + } + def wrapPathSegment(s: String) = Seq(s) +} +object WebEndpoint{ + def buildMapFromQueryParams(ctx: Request) = { val b = Map.newBuilder[String, Seq[String]] val queryParams = ctx.exchange.getQueryParameters for(k <- queryParams.keySet().iterator().asScala){ @@ -22,9 +27,8 @@ trait WebEndpoint extends Endpoint{ deque.toArray(arr) b += (k -> (arr: Seq[String])) } - delegate(b.result()) + b.result() } - def wrapPathSegment(s: String) = Seq(s) } class get(val path: String, override val subpath: Boolean = false) extends WebEndpoint{ val methods = Seq("get") diff --git a/cask/src/cask/endpoints/WebSocketEndpoint.scala b/cask/src/cask/endpoints/WebSocketEndpoint.scala index f747341..5f35832 100644 --- a/cask/src/cask/endpoints/WebSocketEndpoint.scala +++ b/cask/src/cask/endpoints/WebSocketEndpoint.scala @@ -3,22 +3,25 @@ package cask.endpoints import cask.internal.Router import cask.model.Request import io.undertow.websockets.WebSocketConnectionCallback - +import collection.JavaConverters._ sealed trait WebsocketResult object WebsocketResult{ - implicit class Response(val value: cask.model.Response) extends WebsocketResult + implicit class Response[T](value0: cask.model.Response[T]) + (implicit f: T => cask.model.Response.Data) extends WebsocketResult{ + def value = value0.map(f) + } implicit class Listener(val value: WebSocketConnectionCallback) extends WebsocketResult } class websocket(val path: String, override val subpath: Boolean = false) extends cask.main.BaseEndpoint{ - type Output = WebsocketResult + type InnerReturned = WebsocketResult val methods = Seq("websocket") type Input = Seq[String] type InputParser[T] = QueryParamReader[T] - type Returned = Router.Result[WebsocketResult] - def wrapFunction(ctx: Request, delegate: Delegate): Returned = delegate(Map()) + type OuterReturned = Router.Result[WebsocketResult] + def wrapFunction(ctx: Request, delegate: Delegate): OuterReturned = { + delegate(WebEndpoint.buildMapFromQueryParams(ctx)) + } def wrapPathSegment(s: String): Input = Seq(s) - - } diff --git a/cask/src/cask/internal/Util.scala b/cask/src/cask/internal/Util.scala index 3f7ab61..87e2a15 100644 --- a/cask/src/cask/internal/Util.scala +++ b/cask/src/cask/internal/Util.scala @@ -7,9 +7,14 @@ import scala.collection.mutable import java.io.OutputStream import scala.annotation.switch +import scala.concurrent.{ExecutionContext, Future, Promise} object Util { - + def firstFutureOf[T](futures: Seq[Future[T]])(implicit ec: ExecutionContext) = { + val p = Promise[T] + futures.foreach(_.foreach(p.trySuccess)) + p.future + } /** * Convert a string to a C&P-able literal. Basically * copied verbatim from the uPickle source code. diff --git a/cask/src/cask/main/Decorators.scala b/cask/src/cask/main/Decorators.scala index 7aa361f..d2fc0c7 100644 --- a/cask/src/cask/main/Decorators.scala +++ b/cask/src/cask/main/Decorators.scala @@ -5,12 +5,17 @@ import cask.internal.Router.ArgReader import cask.model.{Request, Response} +/** + * Annotates a Cask endpoint that returns a HTTP [[Response]]; similar to a + * [[Decorator]] but with additional metadata and capabilities. + */ trait Endpoint extends BaseEndpoint { - type Returned = Router.Result[Response] + type OuterReturned = Router.Result[Response.Raw] } + /** - * Used to annotate a single Cask endpoint function; similar to a [[Decorator]] - * but with additional metadata and capabilities. + * An [[Endpoint]] that may return something else than a HTTP response, e.g. + * a websocket endpoint which may instead return a websocket event handler */ trait BaseEndpoint extends BaseDecorator{ /** @@ -31,7 +36,7 @@ trait BaseEndpoint extends BaseDecorator{ */ def subpath: Boolean = false - def convertToResultType(t: Output): Output = t + def convertToResultType(t: InnerReturned): InnerReturned = t /** * [[Endpoint]]s are unique among decorators in that they alone can bind @@ -44,13 +49,16 @@ trait BaseEndpoint extends BaseDecorator{ } +/** + * A [[Decorator]] that may deal with values other than HTTP [[Response]]s + */ trait BaseDecorator{ type Input type InputParser[T] <: ArgReader[Input, T, Request] - type Output - type Delegate = Map[String, Input] => Router.Result[Output] - type Returned <: Router.Result[Any] - def wrapFunction(ctx: Request, delegate: Delegate): Returned + type InnerReturned + type Delegate = Map[String, Input] => Router.Result[InnerReturned] + type OuterReturned <: Router.Result[Any] + def wrapFunction(ctx: Request, delegate: Delegate): OuterReturned def getParamParser[T](implicit p: InputParser[T]) = p } @@ -66,9 +74,9 @@ trait BaseDecorator{ * lists (if any). */ trait Decorator extends BaseDecorator{ - type Returned = Router.Result[Response] + type OuterReturned = Router.Result[Response.Raw] type Input = Any - type Output = Response + type InnerReturned = Response.Raw type InputParser[T] = NoOpParser[Input, T] } diff --git a/cask/src/cask/main/Main.scala b/cask/src/cask/main/Main.scala index 88d7a61..7128006 100644 --- a/cask/src/cask/main/Main.scala +++ b/cask/src/cask/main/Main.scala @@ -48,7 +48,7 @@ abstract class BaseMain{ ) }.toMap - def writeResponse(exchange: HttpServerExchange, response: Response) = { + def writeResponse(exchange: HttpServerExchange, response: Response.Raw) = { response.headers.foreach{case (k, v) => exchange.getResponseHeaders.put(new HttpString(k), v) } @@ -58,7 +58,7 @@ abstract class BaseMain{ response.data.write(exchange.getOutputStream) } - def handleNotFound(): Response = { + def handleNotFound(): Response.Raw = { Response( s"Error 404: ${Status.codesToStatus(404).reason}", statusCode = 404 @@ -68,19 +68,20 @@ abstract class BaseMain{ def defaultHandler = new BlockingHandler( new HttpHandler() { - def handleRequest(exchange: HttpServerExchange): Unit = { + def handleRequest(exchange: HttpServerExchange): Unit = try { +// println("Handling Request: " + exchange.getRequestPath) val (effectiveMethod, runner) = if (exchange.getRequestHeaders.getFirst("Upgrade") == "websocket") { "websocket" -> ((r: Any) => r.asInstanceOf[WebsocketResult] match{ case l: WebsocketResult.Listener => io.undertow.Handlers.websocket(l.value).handleRequest(exchange) - case r: WebsocketResult.Response => + case r: WebsocketResult.Response[_] => writeResponseHandler(r).handleRequest(exchange) } - ) + ) } else ( exchange.getRequestMethod.toString.toLowerCase(), - (r: Any) => writeResponse(exchange, r.asInstanceOf[Response]) + (r: Any) => writeResponse(exchange, r.asInstanceOf[Response.Raw]) ) routeTries(effectiveMethod).lookup(Util.splitPath(exchange.getRequestPath).toList, Map()) match { @@ -93,7 +94,7 @@ abstract class BaseMain{ case head :: rest => head.wrapFunction( ctx, - args => rec(rest, args :: bindings).asInstanceOf[Router.Result[head.Output]] + args => rec(rest, args :: bindings).asInstanceOf[Router.Result[head.InnerReturned]] ) case Nil => @@ -116,16 +117,21 @@ abstract class BaseMain{ rec((metadata.decorators ++ routes.decorators ++ mainDecorators).toList, Nil)match{ case Router.Result.Success(res) => runner(res) case e: Router.Result.Error => - writeResponse(exchange, handleEndpointError(exchange, routes, metadata, e)) + writeResponse( + exchange, + handleEndpointError(exchange, routes, metadata, e).map(Response.Data.StringData) + ) None } } - +// println("Completed Request: " + exchange.getRequestPath) + }catch{case e: Throwable => + e.printStackTrace() } } ) - def writeResponseHandler(r: WebsocketResult.Response) = new BlockingHandler( + def writeResponseHandler(r: WebsocketResult.Response[_]) = new BlockingHandler( new HttpHandler { def handleRequest(exchange: HttpServerExchange): Unit = { writeResponse(exchange, r.value) @@ -142,15 +148,15 @@ abstract class BaseMain{ case _: Router.Result.Error.InvalidArguments => 400 case _: Router.Result.Error.MismatchedArguments => 400 } - Response( + val str = if (!debugMode) s"Error $statusCode: ${Status.codesToStatus(statusCode).reason}" else ErrorMsgs.formatInvokeError( routes, metadata.entryPoint.asInstanceOf[EntryPoint[cask.main.Routes, _]], e - ), - statusCode = statusCode - ) + ) + println(str) + Response(str, statusCode = statusCode) } diff --git a/cask/src/cask/model/Response.scala b/cask/src/cask/model/Response.scala index 59b44c9..5b51689 100644 --- a/cask/src/cask/model/Response.scala +++ b/cask/src/cask/model/Response.scala @@ -4,6 +4,7 @@ import java.io.{InputStream, OutputStream, OutputStreamWriter} import cask.internal.Util + /** * The basic response returned by a HTTP endpoint. * @@ -11,38 +12,49 @@ import cask.internal.Util * bytes, uPickle JSON-convertable types or arbitrary input streams. You can * also construct your own implementations of `Response.Data`. */ -case class Response( - data: Response.Data, +case class Response[T]( + data: T, statusCode: Int, headers: Seq[(String, String)], cookies: Seq[Cookie] -) +){ + def map[V](f: T => V) = new Response(f(data), statusCode, headers, cookies) +} object Response{ - def apply(data: Data, - statusCode: Int = 200, - headers: Seq[(String, String)] = Nil, - cookies: Seq[Cookie] = Nil) = new Response(data, statusCode, headers, cookies) + type Raw = Response[Data] + def apply[T](data: T, + statusCode: Int = 200, + headers: Seq[(String, String)] = Nil, + cookies: Seq[Cookie] = Nil) = new Response(data, statusCode, headers, cookies) - implicit def dataResponse[T](t: T)(implicit c: T => Data) = Response(t) + implicit def dataResponse[T, V](t: T)(implicit c: T => V): Response[V] = { + Response[V](t) + } + implicit def dataResponse2[T, V](t: Response[T])(implicit c: T => V): Response[V] = { + t.map(c) + } trait Data{ def write(out: OutputStream): Unit } object Data{ + implicit class UnitData(s: Unit) extends Data{ + def write(out: OutputStream) = () + } implicit class StringData(s: String) extends Data{ def write(out: OutputStream) = out.write(s.getBytes) } + implicit class NumericData[T: Numeric](s: T) extends Data{ + def write(out: OutputStream) = out.write(s.toString.getBytes) + } + implicit class BooleanData(s: Boolean) extends Data{ + def write(out: OutputStream) = out.write(s.toString.getBytes) + } implicit class BytesData(b: Array[Byte]) extends Data{ def write(out: OutputStream) = out.write(b) } implicit class StreamData(b: InputStream) extends Data{ def write(out: OutputStream) = Util.transferTo(b, out) } - implicit def JsonResponse[T: upickle.default.Writer](t: T) = new Data{ - def write(out: OutputStream) = implicitly[upickle.default.Writer[T]].write( - new ujson.BaseRenderer(new OutputStreamWriter(out)), - t - ) - } } } object Redirect{ diff --git a/cask/src/cask/package.scala b/cask/src/cask/package.scala index 405bab7..51aaaf6 100644 --- a/cask/src/cask/package.scala +++ b/cask/src/cask/package.scala @@ -1,6 +1,6 @@ package object cask { // model - type Response = model.Response + type Response[T] = model.Response[T] val Response = model.Response val Abort = model.Abort val Redirect = model.Redirect @@ -29,6 +29,7 @@ package object cask { type staticFiles = endpoints.staticFiles type staticResources = endpoints.staticResources type postJson = endpoints.postJson + type getJson = endpoints.getJson type postForm = endpoints.postForm // main diff --git a/cask/test/src/test/cask/FailureTests.scala b/cask/test/src/test/cask/FailureTests.scala index d24d52c..ac0f3d8 100644 --- a/cask/test/src/test/cask/FailureTests.scala +++ b/cask/test/src/test/cask/FailureTests.scala @@ -5,7 +5,7 @@ import utest._ object FailureTests extends TestSuite { class myDecorator extends cask.Decorator { - def wrapFunction(ctx: Request, delegate: Delegate): Returned = { + def wrapFunction(ctx: Request, delegate: Delegate): OuterReturned = { delegate(Map("extra" -> 31337)) } } diff --git a/example/compress/app/test/src/ExampleTests.scala b/example/compress/app/test/src/ExampleTests.scala index 5a4a5bf..cd4d8d0 100644 --- a/example/compress/app/test/src/ExampleTests.scala +++ b/example/compress/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests{ - 'Compress - test(Compress){ host => + test("Compress") - withServer(Compress){ host => val expected = "Hello World! Hello World! Hello World!" requests.get(s"$host").text() ==> expected assert( diff --git a/example/compress/build.sc b/example/compress/build.sc index ac96e15..5e00fc0 100644 --- a/example/compress/build.sc +++ b/example/compress/build.sc @@ -10,7 +10,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/compress2/app/test/src/ExampleTests.scala b/example/compress2/app/test/src/ExampleTests.scala index cbe3301..9f9b4b3 100644 --- a/example/compress2/app/test/src/ExampleTests.scala +++ b/example/compress2/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests{ - 'Compress2Main - test(Compress2Main) { host => + test("Compress2Main") - withServer(Compress2Main) { host => val expected = "Hello World! Hello World! Hello World!" requests.get(s"$host").text() ==> expected assert( diff --git a/example/compress2/build.sc b/example/compress2/build.sc index c0e75a7..e4c2108 100644 --- a/example/compress2/build.sc +++ b/example/compress2/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/compress3/app/test/src/ExampleTests.scala b/example/compress3/app/test/src/ExampleTests.scala index 3b013f8..88e1cbf 100644 --- a/example/compress3/app/test/src/ExampleTests.scala +++ b/example/compress3/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests{ - 'Compress3Main - test(Compress3Main){ host => + test("Compress3Main") - withServer(Compress3Main){ host => val expected = "Hello World! Hello World! Hello World!" requests.get(s"$host").text() ==> expected assert( diff --git a/example/compress3/build.sc b/example/compress3/build.sc index c0e75a7..e4c2108 100644 --- a/example/compress3/build.sc +++ b/example/compress3/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/cookies/app/test/src/ExampleTests.scala b/example/cookies/app/test/src/ExampleTests.scala index 951728b..150f59a 100644 --- a/example/cookies/app/test/src/ExampleTests.scala +++ b/example/cookies/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests{ - 'Cookies - test(Cookies){ host => + test("Cookies") - withServer(Cookies){ host => val sess = requests.Session() sess.get(s"$host/read-cookie").statusCode ==> 400 sess.get(s"$host/store-cookie") diff --git a/example/cookies/build.sc b/example/cookies/build.sc index c0e75a7..e4c2108 100644 --- a/example/cookies/build.sc +++ b/example/cookies/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/decorated/app/src/Decorated.scala b/example/decorated/app/src/Decorated.scala index f037c6a..b3f1149 100644 --- a/example/decorated/app/src/Decorated.scala +++ b/example/decorated/app/src/Decorated.scala @@ -4,12 +4,12 @@ object Decorated extends cask.MainRoutes{ override def toString = "[haoyi]" } class loggedIn extends cask.Decorator { - def wrapFunction(ctx: cask.Request, delegate: Delegate): Returned = { + def wrapFunction(ctx: cask.Request, delegate: Delegate): OuterReturned = { delegate(Map("user" -> new User())) } } class withExtra extends cask.Decorator { - def wrapFunction(ctx: cask.Request, delegate: Delegate): Returned = { + def wrapFunction(ctx: cask.Request, delegate: Delegate): OuterReturned = { delegate(Map("extra" -> 31337)) } } diff --git a/example/decorated/app/test/src/ExampleTests.scala b/example/decorated/app/test/src/ExampleTests.scala index 9aea3bc..c2c19a6 100644 --- a/example/decorated/app/test/src/ExampleTests.scala +++ b/example/decorated/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests{ - 'Decorated - test(Decorated){ host => + test("Decorated") - withServer(Decorated){ host => requests.get(s"$host/hello/woo").text() ==> "woo31337" requests.get(s"$host/internal/boo").text() ==> "boo[haoyi]" requests.get(s"$host/internal-extra/goo").text() ==> "goo[haoyi]31337" diff --git a/example/decorated/build.sc b/example/decorated/build.sc index c0e75a7..e4c2108 100644 --- a/example/decorated/build.sc +++ b/example/decorated/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/decorated2/app/src/Decorated2.scala b/example/decorated2/app/src/Decorated2.scala index 20526b7..fa4b1c5 100644 --- a/example/decorated2/app/src/Decorated2.scala +++ b/example/decorated2/app/src/Decorated2.scala @@ -4,12 +4,12 @@ object Decorated2 extends cask.MainRoutes{ override def toString = "[haoyi]" } class loggedIn extends cask.Decorator { - def wrapFunction(ctx: cask.Request, delegate: Delegate): Returned = { + def wrapFunction(ctx: cask.Request, delegate: Delegate): OuterReturned = { delegate(Map("user" -> new User())) } } class withExtra extends cask.Decorator { - def wrapFunction(ctx: cask.Request, delegate: Delegate): Returned = { + def wrapFunction(ctx: cask.Request, delegate: Delegate): OuterReturned = { delegate(Map("extra" -> 31337)) } } diff --git a/example/decorated2/app/test/src/ExampleTests.scala b/example/decorated2/app/test/src/ExampleTests.scala index 7fec82a..4343097 100644 --- a/example/decorated2/app/test/src/ExampleTests.scala +++ b/example/decorated2/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests{ - 'Decorated2 - test(Decorated2){ host => + test("Decorated2") - withServer(Decorated2){ host => requests.get(s"$host/hello/woo").text() ==> "woo31337" requests.get(s"$host/internal-extra/goo").text() ==> "goo[haoyi]31337" requests.get(s"$host/ignore-extra/boo").text() ==> "boo[haoyi]" diff --git a/example/decorated2/build.sc b/example/decorated2/build.sc index c0e75a7..e4c2108 100644 --- a/example/decorated2/build.sc +++ b/example/decorated2/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/endpoints/app/src/Endpoints.scala b/example/endpoints/app/src/Endpoints.scala index b478c80..b934769 100644 --- a/example/endpoints/app/src/Endpoints.scala +++ b/example/endpoints/app/src/Endpoints.scala @@ -2,7 +2,8 @@ package app class custom(val path: String, val methods: Seq[String]) extends cask.Endpoint{ type Output = Int - def wrapFunction(ctx: cask.Request, delegate: Delegate): Returned = { + type InnerReturned = Int + def wrapFunction(ctx: cask.Request, delegate: Delegate): OuterReturned = { delegate(Map()).map{num => cask.Response("Echo " + num, statusCode = num) } diff --git a/example/endpoints/app/test/src/ExampleTests.scala b/example/endpoints/app/test/src/ExampleTests.scala index 1302d85..3314f24 100644 --- a/example/endpoints/app/test/src/ExampleTests.scala +++ b/example/endpoints/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests{ - 'Endpoints - test(Endpoints){ host => + test("Endpoints") - withServer(Endpoints){ host => requests.get(s"$host/echo/200").text() ==> "Echo 200" requests.get(s"$host/echo/200").statusCode ==> 200 requests.get(s"$host/echo/400").text() ==> "Echo 400" diff --git a/example/endpoints/build.sc b/example/endpoints/build.sc index c0e75a7..e4c2108 100644 --- a/example/endpoints/build.sc +++ b/example/endpoints/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/formJsonPost/app/test/src/ExampleTests.scala b/example/formJsonPost/app/test/src/ExampleTests.scala index 148ebfd..4178497 100644 --- a/example/formJsonPost/app/test/src/ExampleTests.scala +++ b/example/formJsonPost/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,23 +17,23 @@ object ExampleTests extends TestSuite{ } val tests = Tests{ - 'FormJsonPost - test(FormJsonPost){ host => - requests.post(s"$host/json", data = """{"value1": true, "value2": [3]}""").text() ==> - "OK true List(3)" + test("FormJsonPost") - withServer(FormJsonPost){ host => + val response1 = requests.post(s"$host/json", data = """{"value1": true, "value2": [3]}""") + ujson.read(response1.text()) ==> ujson.Str("OK true List(3)") - requests.post( + val response2 = requests.post( s"$host/form", data = Seq("value1" -> "hello", "value2" -> "1", "value2" -> "2") - ).text() ==> - "OK FormValue(hello,null) List(1, 2)" + ) + response2.text() ==> "OK FormValue(hello,null) List(1, 2)" - val resp = requests.post( + val response3 = requests.post( s"$host/upload", data = requests.MultiPart( requests.MultiItem("image", "...", "my-best-image.txt") ) ) - resp.text() ==> "my-best-image.txt" + response3.text() ==> "my-best-image.txt" } } } diff --git a/example/formJsonPost/build.sc b/example/formJsonPost/build.sc index c0e75a7..e4c2108 100644 --- a/example/formJsonPost/build.sc +++ b/example/formJsonPost/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/httpMethods/app/test/src/ExampleTests.scala b/example/httpMethods/app/test/src/ExampleTests.scala index e14bcf5..30fa87f 100644 --- a/example/httpMethods/app/test/src/ExampleTests.scala +++ b/example/httpMethods/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests{ - 'HttpMethods - test(HttpMethods){ host => + test("HttpMethods") - withServer(HttpMethods){ host => requests.post(s"$host/login").text() ==> "do_the_login" requests.get(s"$host/login").text() ==> "show_the_login_form" } diff --git a/example/httpMethods/build.sc b/example/httpMethods/build.sc index c0e75a7..e4c2108 100644 --- a/example/httpMethods/build.sc +++ b/example/httpMethods/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/minimalApplication/app/test/src/ExampleTests.scala b/example/minimalApplication/app/test/src/ExampleTests.scala index 8c8ecb2..1cda7a6 100644 --- a/example/minimalApplication/app/test/src/ExampleTests.scala +++ b/example/minimalApplication/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests { - 'MinimalApplication - test(MinimalApplication) { host => + test("MinimalApplication") - withServer(MinimalApplication) { host => val success = requests.get(host) success.text() ==> "Hello World!" diff --git a/example/minimalApplication/build.sc b/example/minimalApplication/build.sc index c0e75a7..e4c2108 100644 --- a/example/minimalApplication/build.sc +++ b/example/minimalApplication/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/minimalApplication2/app/test/src/ExampleTests.scala b/example/minimalApplication2/app/test/src/ExampleTests.scala index 0d8f1bc..4e5621c 100644 --- a/example/minimalApplication2/app/test/src/ExampleTests.scala +++ b/example/minimalApplication2/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests{ - 'MinimalApplication2 - test(MinimalMain){ host => + test("MinimalApplication2") - withServer(MinimalMain){ host => val success = requests.get(host) success.text() ==> "Hello World!" diff --git a/example/minimalApplication2/build.sc b/example/minimalApplication2/build.sc index c0e75a7..e4c2108 100644 --- a/example/minimalApplication2/build.sc +++ b/example/minimalApplication2/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/redirectAbort/app/test/src/ExampleTests.scala b/example/redirectAbort/app/test/src/ExampleTests.scala index f095517..a4d149f 100644 --- a/example/redirectAbort/app/test/src/ExampleTests.scala +++ b/example/redirectAbort/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -18,7 +18,7 @@ object ExampleTests extends TestSuite{ val tests = Tests{ - 'RedirectAbort - test(RedirectAbort){ host => + test("RedirectAbort") - withServer(RedirectAbort){ host => val resp = requests.get(s"$host/") resp.statusCode ==> 401 resp.history.get.statusCode ==> 301 diff --git a/example/redirectAbort/build.sc b/example/redirectAbort/build.sc index c0e75a7..e4c2108 100644 --- a/example/redirectAbort/build.sc +++ b/example/redirectAbort/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/scalatags/app/test/src/ExampleTests.scala b/example/scalatags/app/test/src/ExampleTests.scala index 8eccecf..53bc1ea 100644 --- a/example/scalatags/app/test/src/ExampleTests.scala +++ b/example/scalatags/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests { - 'Scalatags - test(Scalatags) { host => + test("Scalatags") - withServer(Scalatags) { host => val body = requests.get(host).text() assert( diff --git a/example/scalatags/build.sc b/example/scalatags/build.sc index 3971d88..e95569a 100644 --- a/example/scalatags/build.sc +++ b/example/scalatags/build.sc @@ -11,7 +11,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/staticFiles/app/test/src/ExampleTests.scala b/example/staticFiles/app/test/src/ExampleTests.scala index ab67bcf..ebda8a0 100644 --- a/example/staticFiles/app/test/src/ExampleTests.scala +++ b/example/staticFiles/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -18,7 +18,7 @@ object ExampleTests extends TestSuite{ val tests = Tests{ - 'StaticFiles - test(StaticFiles){ host => + test("StaticFiles") - withServer(StaticFiles){ host => requests.get(s"$host/static/file/example.txt").text() ==> "the quick brown fox jumps over the lazy dog" diff --git a/example/staticFiles/build.sc b/example/staticFiles/build.sc index d45045d..e0f8519 100644 --- a/example/staticFiles/build.sc +++ b/example/staticFiles/build.sc @@ -11,7 +11,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) diff --git a/example/todo/app/src/TodoServer.scala b/example/todo/app/src/TodoServer.scala index 4adb55c..1a58d09 100644 --- a/example/todo/app/src/TodoServer.scala +++ b/example/todo/app/src/TodoServer.scala @@ -17,7 +17,7 @@ object TodoServer extends cask.MainRoutes{ class transactional extends cask.Decorator{ class TransactionFailed(val value: Router.Result.Error) extends Exception - def wrapFunction(pctx: cask.Request, delegate: Delegate): Returned = { + def wrapFunction(pctx: cask.Request, delegate: Delegate): OuterReturned = { try ctx.transaction( delegate(Map()) match{ case Router.Result.Success(t) => Router.Result.Success(t) diff --git a/example/todo/app/test/src/ExampleTests.scala b/example/todo/app/test/src/ExampleTests.scala index e8ca7eb..e1be23c 100644 --- a/example/todo/app/test/src/ExampleTests.scala +++ b/example/todo/app/test/src/ExampleTests.scala @@ -1,7 +1,7 @@ package app import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = io.undertow.Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -13,7 +13,7 @@ object ExampleTests extends TestSuite{ res } val tests = Tests{ - 'TodoServer - test(TodoServer){ host => + test("TodoServer") - withServer(TodoServer){ host => val page = requests.get(host).text() assert(page.contains("What needs to be done?")) } diff --git a/example/todo/build.sc b/example/todo/build.sc index beeb947..c5d5610 100644 --- a/example/todo/build.sc +++ b/example/todo/build.sc @@ -13,7 +13,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/todoApi/app/test/src/ExampleTests.scala b/example/todoApi/app/test/src/ExampleTests.scala index 5e9e11a..4e85a8e 100644 --- a/example/todoApi/app/test/src/ExampleTests.scala +++ b/example/todoApi/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests{ - 'TodoMvcApi - test(TodoMvcApi){ host => + test("TodoMvcApi") - withServer(TodoMvcApi){ host => requests.get(s"$host/list/all").text() ==> """[{"checked":true,"text":"Get started with Cask"},{"checked":false,"text":"Profit!"}]""" requests.get(s"$host/list/active").text() ==> diff --git a/example/todoApi/build.sc b/example/todoApi/build.sc index c0e75a7..e4c2108 100644 --- a/example/todoApi/build.sc +++ b/example/todoApi/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/todoDb/app/src/TodoMvcDb.scala b/example/todoDb/app/src/TodoMvcDb.scala index 7ce3c50..669b2b8 100644 --- a/example/todoDb/app/src/TodoMvcDb.scala +++ b/example/todoDb/app/src/TodoMvcDb.scala @@ -16,7 +16,7 @@ object TodoMvcDb extends cask.MainRoutes{ class transactional extends cask.Decorator{ class TransactionFailed(val value: Router.Result.Error) extends Exception - def wrapFunction(pctx: cask.Request, delegate: Delegate): Returned = { + def wrapFunction(pctx: cask.Request, delegate: Delegate): OuterReturned = { try ctx.transaction( delegate(Map()) match{ case Router.Result.Success(t) => Router.Result.Success(t) diff --git a/example/todoDb/app/test/src/ExampleTests.scala b/example/todoDb/app/test/src/ExampleTests.scala index eccd913..77cbbb3 100644 --- a/example/todoDb/app/test/src/ExampleTests.scala +++ b/example/todoDb/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests{ - 'TodoMvcDb - test(TodoMvcDb){ host => + test("TodoMvcDb") - withServer(TodoMvcDb){ host => requests.get(s"$host/list/all").text() ==> """[{"id":1,"checked":true,"text":"Get started with Cask"},{"id":2,"checked":false,"text":"Profit!"}]""" requests.get(s"$host/list/active").text() ==> diff --git a/example/todoDb/build.sc b/example/todoDb/build.sc index e2afdfc..589af39 100644 --- a/example/todoDb/build.sc +++ b/example/todoDb/build.sc @@ -12,7 +12,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/twirl/app/test/src/ExampleTests.scala b/example/twirl/app/test/src/ExampleTests.scala index 815f656..2c445fb 100644 --- a/example/twirl/app/test/src/ExampleTests.scala +++ b/example/twirl/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests { - 'Twirl - test(Twirl) { host => + test("Twirl") - withServer(Twirl) { host => val body = requests.get(host).text() assert( diff --git a/example/twirl/build.sc b/example/twirl/build.sc index 6a59f0d..de9fc20 100644 --- a/example/twirl/build.sc +++ b/example/twirl/build.sc @@ -15,7 +15,7 @@ trait AppModule extends ScalaModule with mill.twirllib.TwirlModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/variableRoutes/app/test/src/ExampleTests.scala b/example/variableRoutes/app/test/src/ExampleTests.scala index 48455fa..1755dea 100644 --- a/example/variableRoutes/app/test/src/ExampleTests.scala +++ b/example/variableRoutes/app/test/src/ExampleTests.scala @@ -4,7 +4,7 @@ import io.undertow.Undertow import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -17,7 +17,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests{ - 'VariableRoutes - test(VariableRoutes){ host => + test("VariableRoutes") - withServer(VariableRoutes){ host => val noIndexPage = requests.get(host) noIndexPage.statusCode ==> 404 diff --git a/example/variableRoutes/build.sc b/example/variableRoutes/build.sc index c0e75a7..e4c2108 100644 --- a/example/variableRoutes/build.sc +++ b/example/variableRoutes/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ) } diff --git a/example/websockets/app/test/src/ExampleTests.scala b/example/websockets/app/test/src/ExampleTests.scala index 896c051..a463824 100644 --- a/example/websockets/app/test/src/ExampleTests.scala +++ b/example/websockets/app/test/src/ExampleTests.scala @@ -8,7 +8,7 @@ import utest._ object ExampleTests extends TestSuite{ - def test[T](example: cask.main.BaseMain)(f: String => T): T = { + def withServer[T](example: cask.main.BaseMain)(f: String => T): T = { val server = io.undertow.Undertow.builder .addHttpListener(8080, "localhost") .setHandler(example.defaultHandler) @@ -21,7 +21,7 @@ object ExampleTests extends TestSuite{ } val tests = Tests{ - 'Websockets - test(Websockets){ host => + test("Websockets") - withServer(Websockets){ host => @volatile var out = List.empty[String] val client = org.asynchttpclient.Dsl.asyncHttpClient(); try{ @@ -72,7 +72,7 @@ object ExampleTests extends TestSuite{ } } - 'Websockets2000 - test(Websockets){ host => + test("Websockets2000") - withServer(Websockets){ host => @volatile var out = List.empty[String] val closed = new AtomicInteger(0) val client = org.asynchttpclient.Dsl.asyncHttpClient(); diff --git a/example/websockets/build.sc b/example/websockets/build.sc index c788216..197e285 100644 --- a/example/websockets/build.sc +++ b/example/websockets/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( - ivy"com.lihaoyi::utest::0.6.9", + ivy"com.lihaoyi::utest::0.7.1", ivy"com.lihaoyi::requests::0.2.0", ivy"org.asynchttpclient:async-http-client:2.5.2" ) |