blob: 271486827d01b379963f475e1a9fa7302a5ede88 (
plain)
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
|
{-# LANGUAGE OverloadedStrings #-}
module Network.KRPCSpec (spec) where
import Control.Monad.Reader
import Network.Socket (SockAddr (..))
import Network.KRPC
import Network.KRPC.MethodSpec hiding (spec)
import Test.Hspec
servAddr :: SockAddr
servAddr = SockAddrInet 6000 (256 * 256 * 256 + 127)
handlers :: [Handler IO]
handlers =
[ handler $ \ _ Ping -> return Ping
, handler $ \ _ (Echo a) -> return (Echo (a :: Bool))
, handler $ \ _ (Echo a) -> return (Echo (a :: Int))
]
spec :: Spec
spec = do
describe "query" $ do
it "run handlers" $ do
let int = 0xabcd :: Int
(withManager servAddr handlers $ runReaderT $ do
listen
query servAddr (Echo int))
`shouldReturn` Echo int
it "throw timeout exception" $ do
(withManager servAddr handlers $ runReaderT $ do
query servAddr (Echo (0xabcd :: Int))
)
`shouldThrow` (== KError GenericError "timeout expired" "0")
|