summaryrefslogtreecommitdiff
path: root/cask/test/src/test/cask
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-08-09 00:36:25 +0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-08-09 00:36:25 +0800
commitfe17f0a465a49433867ea4917fd4938a7d2b6609 (patch)
tree04f04f15df5c33325d7da24fad8085587c465895 /cask/test/src/test/cask
parentb1969928a179bfa833cab528d544a1f77cf24987 (diff)
downloadcask-fe17f0a465a49433867ea4917fd4938a7d2b6609.tar.gz
cask-fe17f0a465a49433867ea4917fd4938a7d2b6609.tar.bz2
cask-fe17f0a465a49433867ea4917fd4938a7d2b6609.zip
Add `@cask.decorators.compress` utility
Allow for decorators to be applied across `cask.Routes` or `cask.Main`
Diffstat (limited to 'cask/test/src/test/cask')
-rw-r--r--cask/test/src/test/cask/Compress.scala12
-rw-r--r--cask/test/src/test/cask/Compress2.scala14
-rw-r--r--cask/test/src/test/cask/Compress3.scala15
-rw-r--r--cask/test/src/test/cask/Decorated2.scala38
-rw-r--r--cask/test/src/test/cask/ExampleTests.scala32
-rw-r--r--cask/test/src/test/cask/FailureTests.scala14
6 files changed, 116 insertions, 9 deletions
diff --git a/cask/test/src/test/cask/Compress.scala b/cask/test/src/test/cask/Compress.scala
new file mode 100644
index 0000000..1a027d6
--- /dev/null
+++ b/cask/test/src/test/cask/Compress.scala
@@ -0,0 +1,12 @@
+package test.cask
+
+object Compress extends cask.MainRoutes{
+
+ @cask.decorators.compress
+ @cask.get("/")
+ def hello() = {
+ "Hello World! Hello World! Hello World!"
+ }
+
+ initialize()
+}
diff --git a/cask/test/src/test/cask/Compress2.scala b/cask/test/src/test/cask/Compress2.scala
new file mode 100644
index 0000000..0f2d01f
--- /dev/null
+++ b/cask/test/src/test/cask/Compress2.scala
@@ -0,0 +1,14 @@
+package test.cask
+
+object Compress2 extends cask.Routes{
+ override def decorators = Seq(new cask.decorators.compress())
+
+ @cask.get("/")
+ def hello() = {
+ "Hello World! Hello World! Hello World!"
+ }
+
+ initialize()
+}
+
+object Compress2Main extends cask.Main(Compress2) \ No newline at end of file
diff --git a/cask/test/src/test/cask/Compress3.scala b/cask/test/src/test/cask/Compress3.scala
new file mode 100644
index 0000000..1c8da25
--- /dev/null
+++ b/cask/test/src/test/cask/Compress3.scala
@@ -0,0 +1,15 @@
+package test.cask
+
+object Compress3 extends cask.Routes{
+
+ @cask.get("/")
+ def hello() = {
+ "Hello World! Hello World! Hello World!"
+ }
+
+ initialize()
+}
+
+object Compress3Main extends cask.Main(Compress3){
+ override def mainDecorators = Seq(new cask.decorators.compress())
+} \ No newline at end of file
diff --git a/cask/test/src/test/cask/Decorated2.scala b/cask/test/src/test/cask/Decorated2.scala
new file mode 100644
index 0000000..0d11952
--- /dev/null
+++ b/cask/test/src/test/cask/Decorated2.scala
@@ -0,0 +1,38 @@
+package test.cask
+
+object Decorated2 extends cask.MainRoutes{
+ class User{
+ override def toString = "[haoyi]"
+ }
+ class loggedIn extends cask.Decorator {
+ def wrapFunction(ctx: cask.ParamContext, delegate: Delegate): Returned = {
+ delegate(Map("user" -> new User()))
+ }
+ }
+ class withExtra extends cask.Decorator {
+ def wrapFunction(ctx: cask.ParamContext, delegate: Delegate): Returned = {
+ delegate(Map("extra" -> 31337))
+ }
+ }
+
+ override def decorators = Seq(new withExtra())
+
+ @cask.get("/hello/:world")
+ def hello(world: String)(extra: Int) = {
+ world + extra
+ }
+
+ @loggedIn()
+ @cask.get("/internal-extra/:world")
+ def internalExtra(world: String)(user: User)(extra: Int) = {
+ world + user + extra
+ }
+
+ @loggedIn()
+ @cask.get("/ignore-extra/:world")
+ def ignoreExtra(world: String)(user: User)(extra: Int) = {
+ world + user
+ }
+
+ initialize()
+}
diff --git a/cask/test/src/test/cask/ExampleTests.scala b/cask/test/src/test/cask/ExampleTests.scala
index 36e0387..6784b1e 100644
--- a/cask/test/src/test/cask/ExampleTests.scala
+++ b/cask/test/src/test/cask/ExampleTests.scala
@@ -103,6 +103,12 @@ object ExampleTests extends TestSuite{
requests.get(s"$host/internal-extra/goo").text() ==> "goo[haoyi]31337"
}
+ 'Decorated2 - test(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]"
+
+ }
'TodoMvcApi - test(TodoMvcApi){ host =>
requests.get(s"$host/list/all").text() ==>
"""[{"checked":true,"text":"Get started with Cask"},{"checked":false,"text":"Profit!"}]"""
@@ -155,5 +161,31 @@ object ExampleTests extends TestSuite{
requests.get(s"$host/list/active").text() ==>
"""[]"""
}
+
+ 'Compress - test(Compress){ host =>
+ val expected = "Hello World! Hello World! Hello World!"
+ requests.get(s"$host").text() ==> expected
+ assert(
+ requests.get(s"$host", autoDecompress = false).text().length < expected.length
+ )
+
+ }
+
+ 'Compress2Main - test(Compress2Main) { host =>
+ val expected = "Hello World! Hello World! Hello World!"
+ requests.get(s"$host").text() ==> expected
+ assert(
+ requests.get(s"$host", autoDecompress = false).text().length < expected.length
+ )
+ }
+
+ 'Compress3Main - test(Compress3Main){ host =>
+ val expected = "Hello World! Hello World! Hello World!"
+ requests.get(s"$host").text() ==> expected
+ assert(
+ requests.get(s"$host", autoDecompress = false).text().length < expected.length
+ )
+
+ }
}
}
diff --git a/cask/test/src/test/cask/FailureTests.scala b/cask/test/src/test/cask/FailureTests.scala
index 9e28c0b..62eb946 100644
--- a/cask/test/src/test/cask/FailureTests.scala
+++ b/cask/test/src/test/cask/FailureTests.scala
@@ -11,16 +11,12 @@ object FailureTests extends TestSuite {
}
}
val tests = Tests{
-
'mismatchedDecorators - {
- utest.compileError("""
- object Decorated extends cask.MainRoutes{
- @cask.get("/hello/:world")
- def hello(world: String)(extra: Int) = world + extra
- initialize()
- }
- """).msg ==>
- "Endpoint hello's number of parameter lists (2) cannot be more than the number of decorators (1)"
+ object Decorated extends cask.MainRoutes{
+ @cask.get("/hello/:world")
+ def hello(world: String)(extra: Int) = world + extra
+ initialize()
+ }
utest.compileError("""
object Decorated extends cask.MainRoutes{