on master help sign in
adding SendFileSpec.
commitd9c6676f6ab00d44312540b4f471722cc21c81c0 authorKazu Yamamoto <kazu@iij.ad.jp> dateFri 12 Jun 2015, 10:34 (11 years ago) parent2c6ac21
2 files changed+35
warp/test/SendFileSpec.hs+34 warp/warp.cabal+1
warp/test/SendFileSpec.hsnew file+34
@@ -0,0 +1,34 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+
3+module SendFileSpec where
4+
5+import Control.Exception
6+import Data.ByteString (ByteString)
7+import Network.Wai.Handler.Warp.Buffer
8+import Network.Wai.Handler.Warp.SendFile
9+import Test.Hspec
10+
11+main :: IO ()
12+main = hspec spec
13+
14+spec :: Spec
15+spec = describe "packHeader" $ do
16+ it "returns how much the buffer is consumed (1)" $
17+ tryPackHeader 10 ["foo"] `shouldReturn` 3
18+ it "returns how much the buffer is consumed (2)" $
19+ tryPackHeader 10 ["foo", "bar"] `shouldReturn` 6
20+ it "returns how much the buffer is consumed (3)" $
21+ tryPackHeader 10 ["0123456789"] `shouldReturn` 0
22+ it "returns how much the buffer is consumed (4)" $
23+ tryPackHeader 10 ["01234", "56789"] `shouldReturn` 0
24+ it "returns how much the buffer is consumed (5)" $
25+ tryPackHeader 10 ["01234567890", "12"] `shouldReturn` 3
26+ it "returns how much the buffer is consumed (6)" $
27+ tryPackHeader 10 ["012345678901234567890123456789012", "34"] `shouldReturn` 5
28+
29+tryPackHeader :: Int -> [ByteString] -> IO Int
30+tryPackHeader siz hdrs = bracket (allocateBuffer siz) freeBuffer $ \buf ->
31+ packHeader buf siz send hook hdrs 0
32+ where
33+ send _ = return ()
34+ hook = return ()
warp/warp.cabal+1
@@ -115,6 +115,7 @@ Test-Suite spec
115115 ResponseHeaderSpec
116116 ResponseSpec
117117 RunSpec
118+ SendFileSpec
118119 Hs-Source-Dirs: test, .
119120 Type: exitcode-stdio-1.0
120121