From 2c839b1cbcd75e5cb8205ceef365963770c44322 Mon Sep 17 00:00:00 2001 From: Iain Dunning Date: Tue, 26 Aug 2014 22:49:14 -0400 Subject: [PATCH] Improve test coverage, close #10 --- test/REQUIRE | 3 ++- test/runtests.jl | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/test/REQUIRE b/test/REQUIRE index b61b7dd..5d7e2cc 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1 +1,2 @@ -FactCheck \ No newline at end of file +FactCheck +Requests \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index bda47ae..b698eb7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,6 @@ using HttpCommon using FactCheck -import HttpServer +using HttpServer facts("HttpServer utility functions") do context("HttpServer.write does sensible things") do @@ -19,3 +19,28 @@ facts("HttpServer utility functions") do @fact grep(vals, "Hello") => "Hello World!" end end + +import Requests + +facts("HttpServer run") do + context("HttpServer can run the example") do + http = HttpHandler() do req::Request, res::Response + Response( ismatch(r"^/hello/",req.resource) ? string("Hello ", split(req.resource,'/')[3], "!") : 404 ) + end + http.events["error"] = (client, err) -> println(err) + http.events["listen"] = (port ) -> println("Listening on $port...") + + server = Server(http) + @async run(server, 8000) + sleep(1.0) + + ret = Requests.get("http://localhost:8000/hello/travis") + @fact ret.data => "Hello travis!" + @fact ret.status => 200 + + ret = Requests.get("http://localhost:8000/bad") + @fact ret.data => "" + @fact ret.status => 404 + end +end +