Commit 2e0bb81d authored by Iustin Pop's avatar Iustin Pop
Browse files

Add a small 'passTest' helper



This is symmetric to failTest, and allows us to use it in cases where
we need to return a property.

While replacing 'property True' with it, I saw a case where we can
simplify the use and thus reworked that check.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 9924d61e
......@@ -56,7 +56,7 @@ prop_parseISpecFail descr =
let str = intercalate "," $ map show (values::[Int])
in case CLI.parseISpecString descr str of
Types.Ok v -> failTest $ "Expected failure, got " ++ show v
_ -> property True
_ -> passTest
-- | Test parseYesNo.
prop_parseYesNo :: Bool -> Bool -> [Char] -> Property
......@@ -99,11 +99,10 @@ prop_StringArg argument =
checkEarlyExit :: String -> [CLI.OptType] -> String -> Property
checkEarlyExit name options param =
case CLI.parseOptsInner [param] name options of
Left (code, _) -> if code == 0
then property True
else failTest $ "Program " ++ name ++
" returns invalid code " ++ show code ++
" for option " ++ param
Left (code, _) ->
printTestCase ("Program " ++ name ++
" returns invalid code " ++ show code ++
" for option " ++ param) (code == 0)
_ -> failTest $ "Program " ++ name ++ " doesn't consider option " ++
param ++ " as early exit one"
......
......@@ -206,7 +206,7 @@ prop_AllocRelocate =
[(if Instance.diskTemplate inst' == Types.DTDrbd8
then Instance.sNode
else Instance.pNode) inst'] of
Types.Ok _ -> property True
Types.Ok _ -> passTest
Types.Bad msg -> failTest $ "Failed to relocate: " ++ msg
-- | Helper property checker for the result of a nodeEvac or
......
......@@ -154,7 +154,7 @@ prop_addPriFC =
let inst' = setInstanceSmallerThanNode node inst
inst'' = inst' { Instance.vcpus = Node.availCpu node + extra }
in case Node.addPri node inst'' of
Types.OpFail Types.FailCPU -> property True
Types.OpFail Types.FailCPU -> passTest
v -> failTest $ "Expected OpFail FailCPU, but got " ++ show v
-- | Check that an instance add with too high memory or disk will be
......@@ -177,7 +177,7 @@ prop_addOfflinePri (NonNegative extra_mem) (NonNegative extra_cpu) =
, Instance.mem = Node.availMem node + extra_mem
, Instance.vcpus = Node.availCpu node + extra_cpu }
in case Node.addPri node inst' of
Types.OpGood _ -> property True
Types.OpGood _ -> passTest
v -> failTest $ "Expected OpGood, but got: " ++ show v
-- | Check that an offline instance with reasonable disk size but
......@@ -192,7 +192,7 @@ prop_addOfflineSec (NonNegative extra_mem) (NonNegative extra_cpu) pdx =
, Instance.vcpus = Node.availCpu node + extra_cpu
, Instance.diskTemplate = Types.DTDrbd8 }
in case Node.addSec node inst' pdx of
Types.OpGood _ -> property True
Types.OpGood _ -> passTest
v -> failTest $ "Expected OpGood/OpGood, but got: " ++ show v
-- | Checks for memory reservation changes.
......
......@@ -50,7 +50,7 @@ prop_toArrayFail i s b =
-- poor man's instance Arbitrary JSValue
forAll (elements [J.showJSON i, J.showJSON s, J.showJSON b]) $ \item ->
case JSON.toArray item of
BasicTypes.Bad _ -> property True
BasicTypes.Bad _ -> passTest
BasicTypes.Ok result -> failTest $ "Unexpected parse, got " ++ show result
testSuite "JSON"
......
......@@ -81,6 +81,10 @@ infix 3 ==?
failTest :: String -> Property
failTest msg = printTestCase msg False
-- | A 'True' property.
passTest :: Property
passTest = property True
-- | Return the python binary to use. If the PYTHON environment
-- variable is defined, use its value, otherwise use just \"python\".
pythonCmd :: IO String
......
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