File: Spec.hs

package info (click to toggle)
haskell-wai-app-file-cgi 3.1.10-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 200 kB
  • sloc: haskell: 995; sh: 18; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 1,218 bytes parent folder | download | duplicates (6)
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
{-# LANGUAGE OverloadedStrings #-}

module Main where

import ClassicSpec
import Control.Concurrent
import Control.Monad
import qualified Data.ByteString as BS
import Network.Wai
import Network.Wai.Application.Classic hiding ((</>))
import Network.Wai.Handler.Warp
import System.Directory
import System.FilePath
import Test.Hspec
import System.Posix

main :: IO ()
main = do
    void $ installHandler sigCHLD Ignore Nothing
    void $ forkIO testServer
    threadDelay 100000
    hspec spec

testServer :: IO ()
testServer = do
    dir <- getCurrentDirectory
    runSettings settings $ testApp dir
  where
    settings = setPort 2345 $ setHost "127.0.0.1" defaultSettings

testApp :: FilePath -> Application
testApp dir req
    | cgi       = cgiApp  appSpec defaultCgiAppSpec  cgiRoute  req
    | otherwise = fileApp appSpec defaultFileAppSpec fileRoute req
  where
    cgi = "/cgi-bin/" `BS.isPrefixOf` rawPathInfo req
    appSpec = defaultClassicAppSpec { softwareName = "ClassicTester" }
    cgiRoute = CgiRoute {
        cgiSrc = "/cgi-bin/"
      , cgiDst = fromString (dir </> "test/cgi-bin/")
      }
    fileRoute = FileRoute {
        fileSrc = "/"
      , fileDst = fromString (dir </> "test/html/")
      }