summaryrefslogtreecommitdiff
path: root/tests/Network/KRPCSpec.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Network/KRPCSpec.hs')
-rw-r--r--tests/Network/KRPCSpec.hs33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/Network/KRPCSpec.hs b/tests/Network/KRPCSpec.hs
new file mode 100644
index 00000000..27148682
--- /dev/null
+++ b/tests/Network/KRPCSpec.hs
@@ -0,0 +1,33 @@
1{-# LANGUAGE OverloadedStrings #-}
2module Network.KRPCSpec (spec) where
3import Control.Monad.Reader
4import Network.Socket (SockAddr (..))
5import Network.KRPC
6import Network.KRPC.MethodSpec hiding (spec)
7import Test.Hspec
8
9servAddr :: SockAddr
10servAddr = SockAddrInet 6000 (256 * 256 * 256 + 127)
11
12handlers :: [Handler IO]
13handlers =
14 [ handler $ \ _ Ping -> return Ping
15 , handler $ \ _ (Echo a) -> return (Echo (a :: Bool))
16 , handler $ \ _ (Echo a) -> return (Echo (a :: Int))
17 ]
18
19spec :: Spec
20spec = do
21 describe "query" $ do
22 it "run handlers" $ do
23 let int = 0xabcd :: Int
24 (withManager servAddr handlers $ runReaderT $ do
25 listen
26 query servAddr (Echo int))
27 `shouldReturn` Echo int
28
29 it "throw timeout exception" $ do
30 (withManager servAddr handlers $ runReaderT $ do
31 query servAddr (Echo (0xabcd :: Int))
32 )
33 `shouldThrow` (== KError GenericError "timeout expired" "0")