Skip to content

Commit

Permalink
wai/test: adjusted setting of 'requestBody' to not trigger warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlix committed Oct 26, 2023
1 parent c50cf04 commit 991edb9
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions wai/test/Network/WaiSpec.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{-# LANGUAGE LambdaCase #-}
module Network.WaiSpec (spec) where

import Test.Hspec
import Test.Hspec.QuickCheck (prop)
import Network.Wai
import Data.Word (Word8)
import Data.IORef
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
Expand Down Expand Up @@ -54,29 +56,24 @@ spec = do
body `shouldBe` expected
describe "lazyRequestBody" $ do
prop "works" $ \chunks -> do
ref <- newIORef $ map S.pack $ filter (not . null) chunks
let req = defaultRequest
{ requestBody = atomicModifyIORef ref $ \bss ->
case bss of
[] -> ([], S.empty)
x:y -> (y, x)
}
req <- mkRequestFromChunks chunks
body <- lazyRequestBody req
body `shouldBe` L.fromChunks (map S.pack chunks)
it "is lazy" $ do
let req = defaultRequest
{ requestBody = error "requestBody"
}
let req = setRequestBodyChunks (error "requestBody") defaultRequest
_ <- lazyRequestBody req
return ()
describe "strictRequestBody" $ do
prop "works" $ \chunks -> do
ref <- newIORef $ map S.pack $ filter (not . null) chunks
let req = defaultRequest
{ requestBody = atomicModifyIORef ref $ \bss ->
case bss of
[] -> ([], S.empty)
x:y -> (y, x)
}
req <- mkRequestFromChunks chunks
body <- strictRequestBody req
body `shouldBe` L.fromChunks (map S.pack chunks)

mkRequestFromChunks :: [[Word8]] -> IO Request
mkRequestFromChunks chunks = do
ref <- newIORef $ map S.pack $ filter (not . null) chunks
pure $
flip setRequestBodyChunks defaultRequest $
atomicModifyIORef ref $ \case
[] -> ([], S.empty)
x:y -> (y, x)

0 comments on commit 991edb9

Please sign in to comment.