@@ -0,0 +1,51 @@
1+{-# LANGUAGE DataKinds #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE TypeOperators #-}
4+module Servant.Utils.StaticFilesSpec where
6+import Test.Hspec hiding (pending)
11+import System.Directory
12+import Control.Exception
14+import Servant.Utils.StaticFiles
15+import Servant.API.Sub
16+import Servant.API.Raw
23+app = serve (Proxy :: Proxy Api) server
26+server = serveDirectory "static"
28+withStaticFiles :: IO () -> IO ()
29+withStaticFiles action = withSystemTempDirectory "servant-test" $ \ tmpDir ->
30+ bracket (setup tmpDir) teardown (const action)
33+ outer <- getCurrentDirectory
34+ setCurrentDirectory tmpDir
35+ createDirectory "static"
36+ writeFile "static/foo.txt" "bar"
37+ writeFile "static/index.html" "index"
41+ setCurrentDirectory outer
45+ around_ withStaticFiles $ with (return app) $
46+ describe "serveDirectory" $ do
47+ it "successfully serves files" $ do
48+ get "/static/foo.txt" `shouldRespondWith` "bar"
50+ it "serves the contents of index.html when requesting the root of a directory" $ do
51+ get "/static" `shouldRespondWith` "index"