Skip to content

Commit

Permalink
Add test using binary client stream type wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
FinleyMcIlwaine committed Jan 23, 2024
1 parent 270583a commit 28f6a11
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions test-grapesy/Test/Sanity/StreamingType/NonStreaming.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import Test.Tasty
import Test.Tasty.HUnit

import Network.GRPC.Client qualified as Client
import Network.GRPC.Client.StreamType qualified as Client
import Network.GRPC.Client.Binary qualified as Binary
import Network.GRPC.Common.Binary (BinaryRpc)
import Network.GRPC.Common.Compression qualified as Compr
import Network.GRPC.Server qualified as Server
import Network.GRPC.Server.Binary qualified as Binary
import Network.GRPC.Server.StreamType

Expand All @@ -24,6 +26,8 @@ tests = testGroup "Test.Sanity.StreamingType.NonStreaming" [
testGroup "increment" [
testCaseInfo "default" $
test_increment def
, testCaseInfo "default with client wrapper" $
test_increment_client_wrapper def
, testGroup "Content-Type" [
testGroup "ok" [
-- Without the +format part
Expand Down Expand Up @@ -104,6 +108,16 @@ tests = testGroup "Test.Sanity.StreamingType.NonStreaming" [

type BinaryIncrement = BinaryRpc "binary" "increment"

binaryIncrementServerHandler :: Server.RpcHandler IO
binaryIncrementServerHandler =
streamingRpcHandler (Proxy @BinaryIncrement) $
Binary.mkNonStreaming $ \(n :: Word8) ->
return (succ n)

-- | Server increments and returns a number sent by the client.
--
-- Client manually sends and receieves data using 'Binary.sendFinalInput' and
-- 'Binary.recvFinalInput'.
test_increment :: ClientServerConfig -> IO String
test_increment config = testClientServer assessCustomException $ def {
config
Expand All @@ -113,9 +127,21 @@ test_increment config = testClientServer assessCustomException $ def {
resp <- fst <$> Binary.recvFinalOutput @Word8 call
assertEqual "" 2 $ resp
, server = [
streamingRpcHandler (Proxy @BinaryIncrement) $
Binary.mkNonStreaming $ \(n :: Word8) ->
return (succ n)
binaryIncrementServerHandler
]
}

-- | Server increments and returns a number sent by the client.
--
-- Client uses the 'Binary.nonStreaming' wrapper.
test_increment_client_wrapper :: ClientServerConfig -> IO String
test_increment_client_wrapper config = testClientServer assessCustomException $ def {
config
, client = \withConn -> withConn $ \conn -> do
resp <- Binary.nonStreaming @Word8 @Word8 (Client.rpc @BinaryIncrement conn) 1
assertEqual "" 2 $ resp
, server = [
binaryIncrementServerHandler
]
}

Expand Down

0 comments on commit 28f6a11

Please sign in to comment.