Skip to content
Permalink
Browse files

add exit code verification

  • Loading branch information...
piotr-iohk authored and KtorZ committed May 16, 2019
1 parent 9b88f10 commit 728db74aca18d1ddca99047c872fd71aee42fc83
Showing with 33 additions and 14 deletions.
  1. +33 −14 lib/http-bridge/test/integration/Test/Integration/Scenario/CLISpec.hs
@@ -17,8 +17,10 @@ import Data.List
( length )
import Data.Text
( Text )
import System.Exit
( ExitCode (..))
import System.Command
( Stdout (..), command )
( Exit (..), Stdout (..), command )
import Test.Hspec
( SpecWith, describe, it )
import Test.Hspec.Expectations.Lifted
@@ -40,52 +42,69 @@ import qualified Network.HTTP.Types.Status as HTTP
specNoCluster :: SpecWith ()
specNoCluster = do

it "CLI - Shows help on bad argument" $ do
(Exit c, Stdout out) <- command [] "cardano-wallet" ["--bad arg"]
out `shouldContain` "Cardano Wallet CLI"
c `shouldBe` ExitFailure 1

it "CLI - Shows help with --help" $ do
(Exit c, Stdout out) <- command [] "cardano-wallet" ["--help"]
out `shouldContain` "Cardano Wallet CLI"
c `shouldBe` ExitFailure 1

it "CLI - Shows version" $ do
Stdout out <- command [] "cardano-wallet" ["--version"]
(Exit c, Stdout out) <- command [] "cardano-wallet" ["--version"]
cabal <- readFile "../../cardano-wallet.cabal"
let cabalVersion = ( words $ (lines cabal) !! 1 ) !! 1
let returnedVersion = T.unpack $ T.dropEnd 1 (T.pack out)
returnedVersion `shouldBe` cabalVersion
c `shouldBe` ExitSuccess

it "CLI - Can generate mnemonics with default size" $ do
Stdout out <- command [] "cardano-wallet" ["mnemonic", "generate"]
(Exit c, Stdout out) <- command [] "cardano-wallet" ["mnemonic", "generate"]
length (words out) `shouldBe` 15
c `shouldBe` ExitSuccess

describe "CLI - Can generate mnemonics with different sizes" $ do
forM_ [9, 12, 15, 18, 21, 24] $ \size -> it (show size) $ do
Stdout out <- command [] "cardano-wallet"
["mnemonic", "generate", "--size", show size]
(Exit c, Stdout out) <- command [] "cardano-wallet"
["mnemonic", "generate", "--size", show size]
length (words out) `shouldBe` size
c `shouldBe` ExitSuccess

specWithCluster :: SpecWith Context
specWithCluster = do

it "CLI - Can get a wallet" $ \ctx -> do
walId <- createWallet ctx "1st CLI Wallet" mnemonics15
Stdout out <- command [] "cardano-wallet"
["wallet", "get", "--port", "1337", walId ]
(Exit c, Stdout out) <- command [] "cardano-wallet"
["wallet", "get", "--port", "1337", walId ]
out `shouldContain` "1st CLI Wallet"
c `shouldBe` ExitSuccess

it "CLI - Can list wallets" $ \ctx -> do
_ <- createWallet ctx "1st CLI Wallet" mnemonics15
_ <- createWallet ctx "2nd CLI Wallet" mnemonics18
Stdout out <- command [] "cardano-wallet"
["wallet", "list", "--port", "1337"]
(Exit c, Stdout out) <- command [] "cardano-wallet"
["wallet", "list", "--port", "1337"]
out `shouldContain` "1st CLI Wallet"
out `shouldContain` "2nd CLI Wallet"
c `shouldBe` ExitSuccess

it "CLI - Can update wallet name" $ \ctx -> do
walId <- createWallet ctx "1st CLI Wallet" mnemonics15
Stdout out <- command [] "cardano-wallet"
["wallet", "update", "--port", "1337", walId, "--name"
, "Updated name" ]
(Exit c, Stdout out) <- command [] "cardano-wallet"
["wallet", "update", "--port", "1337", walId
, "--name", "Updated name" ]
out `shouldContain` "Updated name"
c `shouldBe` ExitSuccess

it "CLI - Can delete wallet" $ \ctx -> do
walId <- createWallet ctx "CLI Wallet" mnemonics15
Stdout out <- command [] "cardano-wallet"
["wallet", "delete", "--port", "1337", walId ]
(Exit c, Stdout out) <- command [] "cardano-wallet"
["wallet", "delete", "--port", "1337", walId ]
out `shouldNotContain` "CLI Wallet"
c `shouldBe` ExitSuccess
where

createWallet :: Context -> Text -> [Text] -> IO String

0 comments on commit 728db74

Please sign in to comment.
You can’t perform that action at this time.