Skip to content

Commit

Permalink
Match on the output directly
Browse files Browse the repository at this point in the history
  • Loading branch information
v0d1ch committed Nov 27, 2023
1 parent 4be9c8a commit e607e47
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions hydra-cluster/test/Test/Hydra/Cluster/CardanoCliSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import Test.Hydra.Prelude

import Control.Lens ((^?))
import Data.Aeson (encodeFile)
import Data.Aeson.Key (toString)
import Data.Aeson.Lens (key, _String)
import Data.Text (pack, unpack)
import Hydra.API.HTTPServer (DraftCommitTxResponse (DraftCommitTxResponse))
import Hydra.Cardano.Api (Tx)
import System.Exit (ExitCode (..))
Expand All @@ -26,7 +24,10 @@ spec =

(exitCode, output, _errors) <- readCreateProcessWithExitCode (cardanoCliSign txFile) ""
exitCode `shouldBe` ExitSuccess
findInOutput "type" "Witnessed Tx BabbageEra" output
output
^? key "type" . _String `shouldSatisfy` \case
Nothing -> False
Just something -> something == "Witnessed Tx BabbageEra"
where
cardanoCliSign txFile =
proc
Expand All @@ -42,16 +43,3 @@ spec =
, "--out-file"
, "/dev/stdout"
]

findInOutput lookFor expectedString output =
case output ^? key lookFor . _String of
Nothing ->
failure $
unpack $
unlines $
[ "Failed to find key " <> pack (toString lookFor) <> " in TextEnvelope."
, "cardano-cli output:"
, pack output
]
Just foundString -> do
foundString `shouldBe` expectedString

0 comments on commit e607e47

Please sign in to comment.