Skip to content

Commit

Permalink
Additional test for cardano-wallet-launcher --state-dir <dir>, checki…
Browse files Browse the repository at this point in the history
…ng if <dir> and contents are created
  • Loading branch information
Piotr Stachyra committed Jun 14, 2019
1 parent b6b6b32 commit 24af62e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ spec :: SpecWith (Context t)
spec = after_ tearDown $ do
describe "SERVER - cardano-wallet server" $ do
it "SERVER - Can start cardano-wallet server without --database" $ \_ -> do
let cardanoWalletLauncher = Command
let cardanoWalletServer = Command
"cardano-wallet"
[ "server"
, "--random-port"
] (return ())
Inherit
expectCmdStarts cardanoWalletLauncher
expectCmdStarts cardanoWalletServer

w1 <- doesFileExist dbFile
w2 <- doesFileExist (dbFile ++ "-shm")
Expand All @@ -37,14 +37,14 @@ spec = after_ tearDown $ do
w3 `shouldBe` False

it "SERVER - Can start cardano-wallet server with --database" $ \_ -> do
let cardanoWalletLauncher = Command
let cardanoWalletServer = Command
"cardano-wallet"
[ "server"
, "--random-port"
, "--database", dbFile
] (return ())
Inherit
expectCmdStarts cardanoWalletLauncher
expectCmdStarts cardanoWalletServer

w1 <- doesFileExist dbFile
w2 <- doesFileExist (dbFile ++ "-shm")
Expand Down
72 changes: 47 additions & 25 deletions lib/http-bridge/test/integration/Cardano/LauncherSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,54 @@ module Cardano.LauncherSpec
import Prelude

import Cardano.Launcher
( Command (..), StdStream (..), launch )
import Control.Concurrent
( threadDelay )
import Control.Concurrent.Async
( async, cancel, race, wait )
( Command (..), StdStream (..) )
import Control.Monad
( void )
( when )
import System.Directory
( doesDirectoryExist, doesFileExist, removePathForcibly )
import Test.Hspec
( Spec, describe, expectationFailure, it )
( Spec, after_, describe, it )
import Test.Hspec.Expectations.Lifted
( shouldBe )
import Test.Integration.Framework.DSL
( expectCmdStarts )

spec :: Spec
spec = describe "cardano-wallet-launcher" $ do
it "Can start launcher against testnet" $ do
let cardanoWalletLauncher = Command
"cardano-wallet-launcher"
[ "--http-bridge-port", "8080"
] (return ())
Inherit
handle <- async $ void $ launch [cardanoWalletLauncher]
let fiveSeconds = 5000000
winner <- race (threadDelay fiveSeconds) (wait handle)
case winner of
Left _ -> do
cancel handle
threadDelay 1000000
Right _ ->
expectationFailure
"cardano-wallet-launcher isn't supposed to terminate. \
\Something went wrong."
spec = after_ tearDown $ do
describe "LAUNCHER - cardano-wallet-launcher" $ do
it "LAUNCHER - Can start launcher against testnet" $ do
let cardanoWalletLauncher = Command
"cardano-wallet-launcher"
[ "--http-bridge-port", "8080"
] (return ())
Inherit
expectCmdStarts cardanoWalletLauncher
d1 <- doesDirectoryExist stateDir
d1 `shouldBe` False

it "LAUNCHER - Can start launcher against testnet with --state-dir" $ do
let cardanoWalletLauncher = Command
"cardano-wallet-launcher"
[ "--http-bridge-port", "8080"
, "--state-dir", stateDir
] (return ())
Inherit
expectCmdStarts cardanoWalletLauncher

d1 <- doesDirectoryExist stateDir
d2 <- doesDirectoryExist (stateDir ++ "/testnet")
w1 <- doesFileExist (stateDir ++ "/wallet.db")
w2 <- doesFileExist (stateDir ++ "/wallet.db-shm")
w3 <- doesFileExist (stateDir ++ "/wallet.db-wal")

d1 `shouldBe` True
d2 `shouldBe` True
w1 `shouldBe` True
w2 `shouldBe` True
w3 `shouldBe` True

where
stateDir = "./test/data/tmpStateDir"
tearDown = do
d <- doesDirectoryExist stateDir
when d $ removePathForcibly stateDir

0 comments on commit 24af62e

Please sign in to comment.