on warp-3.3.9-conn-closed-by-pear help sign in
typeable/wai/warp/test/ConduitSpec.hs
67 lines 1.9 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2module ConduitSpec (main, spec) where
4import Network.Wai.Handler.Warp.Conduit
5import Network.Wai.Handler.Warp.Types
6import Control.Monad (replicateM)
7import Test.Hspec
8import Data.IORef as I
9import qualified Data.ByteString as S
11main :: IO ()
12main = hspec spec
14spec :: Spec
15spec = describe "conduit" $ do
16 it "IsolatedBSSource" $ do
17 ref <- newIORef $ map S.singleton [1..50]
18 src <- mkSource $ do
19 x <- readIORef ref
20 case x of
21 [] -> return S.empty
22 y:z -> do
23 writeIORef ref z
24 return y
25 isrc <- mkISource src 40
26 x <- replicateM 20 $ readISource isrc
27 S.concat x `shouldBe` S.pack [1..20]
29 y <- replicateM 40 $ readISource isrc
30 S.concat y `shouldBe` S.pack [21..40]
32 z <- replicateM 40 $ readSource src
33 S.concat z `shouldBe` S.pack [41..50]
34 it "chunkedSource" $ do
35 ref <- newIORef $ "5\r\n12345\r\n3\r\n678\r\n0\r\n\r\nBLAH"
36 src <- mkSource $ do
37 x <- readIORef ref
38 writeIORef ref S.empty
39 return x
40 csrc <- mkCSource src
42 x <- replicateM 15 $ readCSource csrc
43 S.concat x `shouldBe` "12345678"
45 y <- replicateM 15 $ readSource src
46 S.concat y `shouldBe` "BLAH"
47 it "chunk boundaries" $ do
48 ref <- newIORef
49 [ "5\r\n"
50 , "12345\r\n3\r"
51 , "\n678\r\n0\r\n"
52 , "\r\nBLAH"
53 ]
54 src <- mkSource $ do
55 x <- readIORef ref
56 case x of
57 [] -> return S.empty
58 y:z -> do
59 writeIORef ref z
60 return y
61 csrc <- mkCSource src
63 x <- replicateM 15 $ readCSource csrc
64 S.concat x `shouldBe` "12345678"
66 y <- replicateM 15 $ readSource src
67 S.concat y `shouldBe` "BLAH"