blob: f5216607a05cf14fbc53ad484da2c2d0f288b92e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
package test.cask
import io.undertow.Undertow
import io.undertow.server.handlers.BlockingHandler
import utest._
object ExampleTests extends TestSuite{
def test[T](example: cask.main.MainRoutes)(f: String => T): T = {
val server = Undertow.builder
.addHttpListener(8080, "localhost")
.setHandler(new BlockingHandler(example.defaultHandler))
.build
server.start()
val res = f("http://localhost:8080")
server.stop()
res
}
val tests = Tests{
'MinimalApplication - test(MinimalApplication){ host =>
val success = requests.get(host)
success.text() ==> "Hello World!"
success.statusCode ==> 200
val failure = requests.get(host + "/doesnt-exist")
failure.text() ==> "Error 404: Not Found"
failure.statusCode ==> 404
val successInfo = requests.get(host + "/request-info?my-query-param=my-query-value")
assert(
successInfo.text().contains("my-query-param"),
successInfo.text().contains("my-query-value")
)
}
'VariableRoutes - test(VariableRoutes){ host =>
val noIndexPage = requests.get(host)
noIndexPage.statusCode ==> 404
requests.get(host + "/user/lihaoyi").text() ==> "User lihaoyi"
requests.get(host + "/user").statusCode ==> 404
requests.get(host + "/post/123?query=xyz&query=abc") ==>
"Post 123 ArrayBuffer(xyz, abc)"
requests.get(host + "/post/123").text() ==>
"""Missing argument: (query: Seq[String])
|
|Arguments provided did not match expected signature:
|
|showPost
| postId Int
| query Seq[String]
|
|""".stripMargin
requests.get(host + "/path/one/two/three").text() ==>
"Subpath List(one, two, three)"
}
}
}
|