diff options
Diffstat (limited to 'tests/Network/KRPCSpec.hs')
-rw-r--r-- | tests/Network/KRPCSpec.hs | 33 |
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 #-} | ||
2 | module Network.KRPCSpec (spec) where | ||
3 | import Control.Monad.Reader | ||
4 | import Network.Socket (SockAddr (..)) | ||
5 | import Network.KRPC | ||
6 | import Network.KRPC.MethodSpec hiding (spec) | ||
7 | import Test.Hspec | ||
8 | |||
9 | servAddr :: SockAddr | ||
10 | servAddr = SockAddrInet 6000 (256 * 256 * 256 + 127) | ||
11 | |||
12 | handlers :: [Handler IO] | ||
13 | handlers = | ||
14 | [ handler $ \ _ Ping -> return Ping | ||
15 | , handler $ \ _ (Echo a) -> return (Echo (a :: Bool)) | ||
16 | , handler $ \ _ (Echo a) -> return (Echo (a :: Int)) | ||
17 | ] | ||
18 | |||
19 | spec :: Spec | ||
20 | spec = 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") | ||