From a82d2651ca4a9b8c2871c79c2c51652c8c39b91f Mon Sep 17 00:00:00 2001 From: Piotr Stachyra Date: Mon, 17 Jun 2019 17:36:04 +0200 Subject: [PATCH] Use temp directory for serve --database test --- .../Test/Integration/Scenario/CLI/Server.hs | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/lib/core/test/integration/Test/Integration/Scenario/CLI/Server.hs b/lib/core/test/integration/Test/Integration/Scenario/CLI/Server.hs index 226466c7255..44395818327 100644 --- a/lib/core/test/integration/Test/Integration/Scenario/CLI/Server.hs +++ b/lib/core/test/integration/Test/Integration/Scenario/CLI/Server.hs @@ -7,40 +7,38 @@ import Prelude import Cardano.Launcher ( Command (..), StdStream (..) ) import System.Directory - ( doesFileExist, removePathForcibly ) + ( doesFileExist ) +import System.IO.Temp + ( withSystemTempDirectory ) 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"