Skip to content

Commit

Permalink
Fix JSONSchema test assertion to correctly handle the case of invalid…
Browse files Browse the repository at this point in the history
… namespace.
  • Loading branch information
KtorZ committed Sep 1, 2021
1 parent 6eee28d commit 0f096ed
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions hydra-node/test/Hydra/JSONSchema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ prop_validateToJSON specFile namespace inputFile =
forAllBlind (vectorOf 1000 arbitrary) $
\(a :: [a]) -> monadicIO $ do
specs <- run $ Aeson.decodeFileStrict specFile
let unknownConstructors = Map.keys $ Map.filter (== 0) $ classify specs a
let knownKeys = classify specs a
let unknownConstructors = Map.keys $ Map.filter (== 0) knownKeys

when (null knownKeys) $ do
monitor $ counterexample $ "No keys found in given namespace: " <> toString namespace
assert False

unless (null unknownConstructors) $ do
let commaSeparated = intercalate ", " (toString <$> unknownConstructors)
monitor $ counterexample $ "Unimplemented constructors present in specification: " <> commaSeparated
Expand All @@ -79,7 +85,7 @@ prop_validateToJSON specFile namespace inputFile =
mempty

countMatch (strawmanGetConstr -> tag) =
Map.alter (Just . maybe 1 (+ 1)) tag
Map.adjust (+ 1) tag
in foldr countMatch knownKeys
classify _ =
error $ "Invalid specification file. Does not decode to an object: " <> show specFile
Expand Down

0 comments on commit 0f096ed

Please sign in to comment.