Update tests, use localhost

This commit is contained in:
sigma-andex 2022-08-24 18:59:06 +01:00
parent ef72a4476c
commit bfaa671d1c
15 changed files with 18 additions and 18 deletions

View File

@ -30,7 +30,7 @@ router { route: SayHello } = readTextFile UTF8 filePath >>= ok
-- | Boot up the server
main :: ServerM
main =
serve { port: 8080, onStarted } { route, router }
serve { hostname: "localhost", port: 8080, onStarted } { route, router }
where
onStarted = do
log " ┌────────────────────────────────────────────┐"

View File

@ -28,7 +28,7 @@ router { body } = toBuffer body >>= sha256sum >>> ok
-- | Boot up the server
main :: ServerM
main =
serve { port: 8080, onStarted } { route, router }
serve { hostname: "localhost", port: 8080, onStarted } { route, router }
where
onStarted = do
log " ┌─────────────────────────────────────────────────────────┐"

View File

@ -33,7 +33,7 @@ router = const $ readFile filePath >>= ok' responseHeaders
-- | Boot up the server
main :: ServerM
main =
serve { port: 8080, onStarted } { route, router }
serve { hostname: "localhost", port: 8080, onStarted } { route, router }
where
onStarted = do
log " ┌──────────────────────────────────────┐"

View File

@ -34,7 +34,7 @@ router = const $ runScript "echo 'hello '; sleep 1; echo 'world!'" >>= ok
-- | Boot up the server
main :: ServerM
main =
serve { port: 8080, onStarted } { route, router }
serve { hostname: "localhost", port: 8080, onStarted } { route, router }
where
onStarted = do
log " ┌──────────────────────────────────────┐"

View File

@ -42,7 +42,7 @@ sayHello _ = do
-- | Boot up the server
main :: ServerM
main =
serve { port: 8080, onStarted } { route, router: readerMiddleware sayHello }
serve { hostname: "localhost", port: 8080, onStarted } { route, router: readerMiddleware sayHello }
where
onStarted = do
log " ┌───────────────────────────────────────┐"

View File

@ -32,7 +32,7 @@ router { headers } = ok' responseHeaders $ headers !@ "X-Input"
-- | Boot up the server
main :: ServerM
main =
serve { port: 8080, onStarted } { route, router }
serve { hostname: "localhost", port: 8080, onStarted } { route, router }
where
onStarted = do
log " ┌──────────────────────────────────────────────┐"

View File

@ -20,7 +20,7 @@ route = RD.root $ RG.sum
-- | Boot up the server
main :: ServerM
main =
serve { port: 8080, onStarted } { route, router: const $ ok "hello world!" }
serve { hostname: "localhost", port: 8080, onStarted } { route, router: const $ ok "hello world!" }
where
onStarted = do
log " ┌────────────────────────────────────────────┐"

View File

@ -46,7 +46,7 @@ testEncoder = JsonEncoder $ \{ hello } -> "{\"hello\": \"" <> hello <> "\" }"
-- | Boot up the server
main :: ServerM
main =
serve { port: 8080, onStarted } { route, router }
serve { hostname: "localhost", port: 8080, onStarted } { route, router }
where
router { route: SayHello, method: Post, body } = usingCont do
-- in your project you will want to use Argonaut.jsonDecoder from httpurple-argonaut

View File

@ -80,7 +80,7 @@ middlewareStack = loggingMiddleware <<< headerMiddleware <<< pathMiddleware
-- | Boot up the server
main :: ServerM
main =
serve { port: 8080, onStarted } { route: middlewareRoute <+> sayHelloRoute, router: middlewareStack sayHello }
serve { hostname: "localhost", port: 8080, onStarted } { route: middlewareRoute <+> sayHelloRoute, router: middlewareStack sayHello }
where
onStarted = do
log " ┌───────────────────────────────────────┐"

View File

@ -29,7 +29,7 @@ router { route: GoodBye } = ok "goodbye"
-- | Boot up the server
main :: ServerM
main =
serve { port: 8080, onStarted } { route, router }
serve { hostname: "localhost", port: 8080, onStarted } { route, router }
where
onStarted = do
log " ┌────────────────────────────────┐"

View File

@ -30,7 +30,7 @@ router { route: ManySegments elems } = ok $ show elems
-- | Boot up the server
main :: ServerM
main =
serve { port: 8080, onStarted } { route, router }
serve { hostname: "localhost", port: 8080, onStarted } { route, router }
where
onStarted = do
log " ┌───────────────────────────────────────────────┐"

View File

@ -27,7 +27,7 @@ router _ = notFound
-- | Boot up the server
main :: ServerM
main =
serve { port: 8080, onStarted } { route, router }
serve { hostname: "localhost", port: 8080, onStarted } { route, router }
where
onStarted = do
log " ┌───────────────────────────────────────────┐"

View File

@ -31,7 +31,7 @@ router _ = notFound
-- | Boot up the server
main :: ServerM
main =
serve { port: 8080, onStarted } { route, router }
serve { hostname: "localhost", port: 8080, onStarted } { route, router }
where
onStarted :: Effect Unit
onStarted = do

View File

@ -35,7 +35,7 @@ sayHello _ = ok "hello world!"
-- | Boot up the server
main :: ServerM
main =
serve { port: 8080, certFile: cert, keyFile: key, onStarted } { route, router: sayHello }
serve { hostname: "localhost", port: 8080, certFile: cert, keyFile: key, onStarted } { route, router: sayHello }
where
onStarted =
do

View File

@ -41,13 +41,13 @@ serveSpec :: Test
serveSpec =
describe "serve" do
it "boots a server on the given port" do
close <- liftEffect $ serve { port: 8080 } { route, router: mockRouter }
close <- liftEffect $ serve { hostname: "localhost", port: 8080 } { route, router: mockRouter }
out <- get 8080 empty "/test"
liftEffect $ close $ pure unit
out ?= "/test"
it "responds with a 500 upon unhandled exceptions" do
let router _ = throwError $ error "fail!"
close <- liftEffect $ serve { port: 8080 } { route, router }
close <- liftEffect $ serve { hostname: "localhost", port: 8080 } { route, router }
status <- getStatus 8080 empty "/test"
liftEffect $ close $ pure unit
status ?= 500
@ -70,14 +70,14 @@ serveSecureSpec =
it "boots a server on the given port" do
close <-
liftEffect
$ serve { port: 8080, certFile: "./test/Mocks/Certificate.cer", keyFile: "./test/Mocks/Key.key" } { route, router: mockRouter }
$ serve { hostname: "localhost", port: 8080, certFile: "./test/Mocks/Certificate.cer", keyFile: "./test/Mocks/Key.key" } { route, router: mockRouter }
out <- get' 8080 empty "/test"
liftEffect $ close $ pure unit
out ?= "/test"
describe "with invalid key and cert files" do
it "throws" do
expectError $ liftEffect
$ serve { port: 8080, certFile: "", keyFile: "" } { route, router: mockRouter }
$ serve { hostname: "localhost", port: 8080, certFile: "", keyFile: "" } { route, router: mockRouter }
serveSecure'Spec :: Test
serveSecure'Spec =