Commit 1263a102 authored by Petr Pudlak's avatar Petr Pudlak
Browse files

Add a helper test method for checking deserialization



It tests if a deserialization method fails properly when an invalid
input is given.
Signed-off-by: default avatarPetr Pudlak <pudlak@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent f3a522ff
......@@ -60,6 +60,7 @@ module Test.Ganeti.TestCommon
, genLuxiTagName
, netmask2NumHosts
, testSerialisation
, testDeserialisationFail
, resultProp
, readTestData
, genSample
......@@ -373,6 +374,16 @@ testSerialisation a =
J.Error msg -> failTest $ "Failed to deserialise: " ++ msg
J.Ok a' -> a ==? a'
-- | Checks if the deserializer doesn't accept forbidden values.
-- The first argument is ignored, it just enforces the correct type.
testDeserialisationFail :: (Eq a, Show a, J.JSON a)
=> a -> J.JSValue -> Property
testDeserialisationFail a val =
case liftM (`asTypeOf` a) $ J.readJSON val of
J.Error _ -> passTest
J.Ok x -> failTest $ "Parsed invalid value " ++ show val ++
" to: " ++ show x
-- | Result to PropertyM IO.
resultProp :: (Show a) => BasicTypes.GenericResult a b -> PropertyM IO b
resultProp (BasicTypes.Bad err) = stop . failTest $ show err
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment