Skip to content

Commit

Permalink
Use temp directory for serve --database test
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stachyra committed Jun 17, 2019
1 parent 785e5e6 commit 08a6c09
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions lib/core/test/integration/Test/Integration/Scenario/CLI/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,39 @@ import Prelude

import Cardano.Launcher
( Command (..), StdStream (..) )
import System.IO.Temp
( withSystemTempDirectory )
import System.Directory
( doesFileExist, removePathForcibly )
( doesFileExist )
import Test.Hspec
( SpecWith, after_, describe, it )
( SpecWith, describe, it )
import Test.Hspec.Expectations.Lifted
( shouldReturn )
import Test.Integration.Framework.DSL
( Context (..), expectCmdStarts )

spec :: SpecWith (Context t)
spec = after_ tearDown $ do
spec = do
describe "SERVER - cardano-wallet serve" $ do
it "SERVER - Can start cardano-wallet serve without --database" $ \_ -> do
it "SERVER - Can just start cardano-wallet serve" $ \_ -> do
let cardanoWalletServer = Command "stack"
[ "exec", "--", "cardano-wallet", "serve"
] (return ())
Inherit
expectCmdStarts cardanoWalletServer
doesFileExist dbFile `shouldReturn` False
doesFileExist (dbFile ++ "-shm") `shouldReturn` False
doesFileExist (dbFile ++ "-wal") `shouldReturn` False

it "SERVER - Can start cardano-wallet serve with --database" $ \_ -> do
let cardanoWalletServer = Command "stack"
[ "exec", "--", "cardano-wallet", "serve"
, "--database", dbFile
] (return ())
Inherit
expectCmdStarts cardanoWalletServer
doesFileExist dbFile `shouldReturn` True
doesFileExist (dbFile ++ "-shm") `shouldReturn` True
doesFileExist (dbFile ++ "-wal") `shouldReturn` True
where
dbFile = "./test/data/test-DB-File"
tearDown = do
removePathForcibly dbFile
removePathForcibly (dbFile ++ "-shm")
removePathForcibly (dbFile ++ "-wal")
it "SERVER - Can start cardano-wallet serve --database" $ \_ -> do
withTempDir $ \d -> do
let dbFile = d ++ "/db-file"
let cardanoWalletServer = Command "stack"
[ "exec", "--", "cardano-wallet", "serve"
, "--database", dbFile
] (return ())
Inherit
expectCmdStarts cardanoWalletServer
doesFileExist dbFile `shouldReturn` True
doesFileExist (dbFile ++ "-shm") `shouldReturn` True
doesFileExist (dbFile ++ "-wal") `shouldReturn` True

withTempDir :: (FilePath -> IO a) -> IO a
withTempDir = withSystemTempDirectory "integration-state"

0 comments on commit 08a6c09

Please sign in to comment.