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/httpMethods | |
parent | 9bf8c31fa9321558d7d02f6a5b687cd55a924e7f (diff) | |
download | cask-fd9c399db8c1c0d86cc65d5e1c41968b42a813d1.tar.gz cask-fd9c399db8c1c0d86cc65d5e1c41968b42a813d1.tar.bz2 cask-fd9c399db8c1c0d86cc65d5e1c41968b42a813d1.zip |
auto-upload examples
Diffstat (limited to 'example/httpMethods')
-rw-r--r-- | example/httpMethods/app/src/HttpMethods.scala | 10 | ||||
-rw-r--r-- | example/httpMethods/app/test/src/ExampleTests.scala | 25 | ||||
-rw-r--r-- | example/httpMethods/build.sc | 18 |
3 files changed, 53 insertions, 0 deletions
diff --git a/example/httpMethods/app/src/HttpMethods.scala b/example/httpMethods/app/src/HttpMethods.scala new file mode 100644 index 0000000..5fcbdca --- /dev/null +++ b/example/httpMethods/app/src/HttpMethods.scala @@ -0,0 +1,10 @@ +package app +object HttpMethods extends cask.MainRoutes{ + @cask.route("/login", methods = Seq("get", "post")) + def login(request: cask.Request) = { + if (request.exchange.getRequestMethod.equalToString("post")) "do_the_login" + else "show_the_login_form" + } + + initialize() +} diff --git a/example/httpMethods/app/test/src/ExampleTests.scala b/example/httpMethods/app/test/src/ExampleTests.scala new file mode 100644 index 0000000..e14bcf5 --- /dev/null +++ b/example/httpMethods/app/test/src/ExampleTests.scala @@ -0,0 +1,25 @@ +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{ + 'HttpMethods - test(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 new file mode 100644 index 0000000..6b3ab3f --- /dev/null +++ b/example/httpMethods/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 |