blob: e73b1ec0d690d4f378563cdfc45aa21b3a2996bf (
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
34
35
36
37
38
39
40
|
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Network.KRPCSpec (spec) where
import Control.Monad.Logger
import Control.Monad.Reader
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))
]
instance MonadLogger IO where
monadLoggerLog _ _ _ _ = return ()
opts :: Options
opts = def { optQueryTimeout = 1 }
spec :: Spec
spec = do
describe "query" $ do
it "run handlers" $ do
let int = 0xabcd :: Int
(withManager opts servAddr handlers $ runReaderT $ do
listen
query servAddr (Echo int))
`shouldReturn` Echo int
it "throw timeout exception" $ do
(withManager opts servAddr handlers $ runReaderT $ do
query servAddr (Echo (0xabcd :: Int))
)
`shouldThrow` (== KError GenericError "timeout expired" "0")
|