mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-18 00:59:42 +01:00
d66a4f98b3
* update channel arg names, add compression level arg support, add compression level arg test * switch to temp test demonstrating bug in grpc 0.15.0 * memset op array to 0 * switch examples back * Switch to newer `grpc` and enable tests in `release.nix` * Split out `simple-server` test into separate shell script * Fix bash invocation * Add intermediate `./default-tests.nix` build * Add `tests.patch` to version control * Split `python` command into separate script * Provide `python` via `nix`
58 lines
1.6 KiB
Haskell
58 lines
1.6 KiB
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module GeneratedTests where
|
|
|
|
import Test.Tasty
|
|
import Test.Tasty.HUnit (testCase, (@?=))
|
|
|
|
import Data.String
|
|
import Data.Protobuf.Wire.DotProto.Generate
|
|
import qualified Data.Text as T
|
|
|
|
import Turtle
|
|
|
|
generatedTests :: TestTree
|
|
generatedTests = testGroup "Code generator tests"
|
|
[ testServerGeneration ]
|
|
|
|
testServerGeneration :: TestTree
|
|
testServerGeneration = testCase "server generation" $ do
|
|
mktree hsTmpDir
|
|
mktree pyTmpDir
|
|
|
|
compileSimpleDotProto
|
|
|
|
exitCode <- proc "tests/simple-server.sh" [hsTmpDir] empty
|
|
exitCode @?= ExitSuccess
|
|
|
|
exitCode <- proc "tests/protoc.sh" [pyTmpDir] empty
|
|
exitCode @?= ExitSuccess
|
|
|
|
runManaged $ do
|
|
serverExitCodeA <- fork (shell (hsTmpDir <> "/simple-server") empty)
|
|
clientExitCodeA <- fork
|
|
(export "PYTHONPATH" pyTmpDir >> shell "python tests/test-client.py" empty)
|
|
|
|
liftIO $ do
|
|
serverExitCode <- liftIO (wait serverExitCodeA)
|
|
clientExitCode <- liftIO (wait clientExitCodeA)
|
|
|
|
serverExitCode @?= ExitSuccess
|
|
clientExitCode @?= ExitSuccess
|
|
|
|
rmtree hsTmpDir
|
|
rmtree pyTmpDir
|
|
|
|
hsTmpDir, pyTmpDir :: IsString a => a
|
|
hsTmpDir = "tests/tmp"
|
|
pyTmpDir = "tests/py-tmp"
|
|
|
|
compileSimpleDotProto :: IO ()
|
|
compileSimpleDotProto =
|
|
do dpRes <- readDotProtoWithContext "tests/simple.proto"
|
|
case dpRes of
|
|
Left err -> fail (show err)
|
|
Right (dp, ctxt) ->
|
|
case renderHsModuleForDotProto dp ctxt of
|
|
Left err -> fail ("compileSimpleDotProto: Error compiling test.proto: " <> show err)
|
|
Right hsSrc -> writeFile (hsTmpDir ++ "/Simple.hs") hsSrc
|