diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-08-12 22:18:39 +0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-08-12 22:18:39 +0800 |
commit | fd9c399db8c1c0d86cc65d5e1c41968b42a813d1 (patch) | |
tree | 8e8fc2875cb1c26f309384a9ca0ad72e1fa893f3 /example/minimalApplication2 | |
parent | 9bf8c31fa9321558d7d02f6a5b687cd55a924e7f (diff) | |
download | cask-fd9c399db8c1c0d86cc65d5e1c41968b42a813d1.tar.gz cask-fd9c399db8c1c0d86cc65d5e1c41968b42a813d1.tar.bz2 cask-fd9c399db8c1c0d86cc65d5e1c41968b42a813d1.zip |
auto-upload examples
Diffstat (limited to 'example/minimalApplication2')
-rw-r--r-- | example/minimalApplication2/app/src/MinimalApplication2.scala | 16 | ||||
-rw-r--r-- | example/minimalApplication2/app/test/src/ExampleTests.scala | 33 | ||||
-rw-r--r-- | example/minimalApplication2/build.sc | 18 |
3 files changed, 67 insertions, 0 deletions
diff --git a/example/minimalApplication2/app/src/MinimalApplication2.scala b/example/minimalApplication2/app/src/MinimalApplication2.scala new file mode 100644 index 0000000..01b4aa5 --- /dev/null +++ b/example/minimalApplication2/app/src/MinimalApplication2.scala @@ -0,0 +1,16 @@ +package app + +object MinimalRoutes extends cask.Routes{ + @cask.get("/") + def hello() = { + "Hello World!" + } + + @cask.post("/do-thing") + def doThing(request: cask.Request) = { + new String(request.data.readAllBytes()).reverse + } + + initialize() +} +object MinimalMain extends cask.Main(MinimalRoutes)
\ No newline at end of file diff --git a/example/minimalApplication2/app/test/src/ExampleTests.scala b/example/minimalApplication2/app/test/src/ExampleTests.scala new file mode 100644 index 0000000..0d8f1bc --- /dev/null +++ b/example/minimalApplication2/app/test/src/ExampleTests.scala @@ -0,0 +1,33 @@ +package app +import io.undertow.Undertow + +import utest._ + +object ExampleTests extends TestSuite{ + def test[T](example: cask.main.BaseMain)(f: String => T): T = { + val server = Undertow.builder + .addHttpListener(8080, "localhost") + .setHandler(example.defaultHandler) + .build + server.start() + val res = + try f("http://localhost:8080") + finally server.stop() + res + } + + val tests = Tests{ + 'MinimalApplication2 - test(MinimalMain){ host => + val success = requests.get(host) + + success.text() ==> "Hello World!" + success.statusCode ==> 200 + + requests.get(s"$host/doesnt-exist").statusCode ==> 404 + + requests.post(s"$host/do-thing", data = "hello").text() ==> "olleh" + + requests.get(s"$host/do-thing").statusCode ==> 404 + } + } +} diff --git a/example/minimalApplication2/build.sc b/example/minimalApplication2/build.sc new file mode 100644 index 0000000..6b3ab3f --- /dev/null +++ b/example/minimalApplication2/build.sc @@ -0,0 +1,18 @@ +import mill._, scalalib._ + + +trait AppModule extends ScalaModule{ + def scalaVersion = "2.12.6" + def ivyDeps = Agg( + ivy"com.lihaoyi::cask:0.0.1", + ) + + object test extends Tests{ + def testFrameworks = Seq("utest.runner.Framework") + def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( + ivy"com.lihaoyi::utest::0.6.3", + ivy"com.lihaoyi::requests::0.1.2", + ) + } +}
\ No newline at end of file |