Skip to content

Commit

Permalink
Add launcher tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Mar 14, 2019
1 parent 380e2cc commit 877b2c7
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 0 deletions.
27 changes: 27 additions & 0 deletions app/launcher/LauncherSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Control.Monad
( forM_ )
import Launcher
import Prelude
import System.Exit
( ExitCode (..) )
import Test.Hspec

main :: IO ()
main = hspec $ do
describe "Launcher.monitor" $ do
it "node + wallet" $ do
let commands =
[ Command "./app/launcher/mock/node-exit-0.sh" []
, Command "./app/launcher/mock/wallet.sh" []
]
running <- launch commands
(ProcessHasExited name code) <- monitor running
putStrLn "killing"
forM_ running kill
putStrLn "has killed"
name `shouldBe` cmdName (commands !! 0)
code `shouldBe` ExitSuccess
-- Not quite working

it "trivial" $
True `shouldBe` True
4 changes: 4 additions & 0 deletions app/launcher/mock/node-exit-0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
echo "I'm a node (will exit 0)";
sleep $[ ( $RANDOM % 2 ) + 1 ]s;
exit 0;
4 changes: 4 additions & 0 deletions app/launcher/mock/node-exit-1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
echo "I'm a node (will exit 1)";
sleep $[ ( $RANDOM % 2 ) + 1 ]s;
exit 1;
2 changes: 2 additions & 0 deletions app/launcher/mock/node.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
while true; do echo "I'm a node"; sleep $[ ( $RANDOM % 2 ) + 1 ]s; done
4 changes: 4 additions & 0 deletions app/launcher/mock/wallet-exit-0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
echo "I'm a wallet (will exit 0)";
sleep $[ ( $RANDOM % 2 ) + 1 ]s;
exit 0;
4 changes: 4 additions & 0 deletions app/launcher/mock/wallet-exit-1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
echo "I'm a wallet (will exit 1)";
sleep $[ ( $RANDOM % 2 ) + 1 ]s;
exit 1;
2 changes: 2 additions & 0 deletions app/launcher/mock/wallet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
while true; do echo "I'm a wallet"; sleep $[ ( $RANDOM % 2 ) + 1 ]s; done
28 changes: 28 additions & 0 deletions cardano-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,34 @@ executable cardano-generate-mnemonic
main-is:
GenerateMnemonic.hs


test-suite launcher-tests
default-language:
Haskell2010
default-extensions:
NoImplicitPrelude
OverloadedStrings
ghc-options:
-threaded -rtsopts
-Wall
-O2
if (!flag(development))
ghc-options: -Werror
build-depends:
base
, hspec
, process
, async
type:
exitcode-stdio-1.0
hs-source-dirs:
app/launcher
app/cli
main-is:
LauncherSpec.hs
other-modules:
Launcher

test-suite unit
default-language:
Haskell2010
Expand Down

0 comments on commit 877b2c7

Please sign in to comment.