Commit 3c002a13 authored by Iustin Pop's avatar Iustin Pop
Browse files

htools: add some unittests for Types.hs


Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent cc25e437
......@@ -34,6 +34,7 @@ module Ganeti.HTools.QC
, testJobs
, testCluster
, testLoader
, testTypes
) where
import Test.QuickCheck
......@@ -265,6 +266,12 @@ instance Arbitrary SmallRatio where
v <- choose (0, 1)
return $ SmallRatio v
instance Arbitrary Types.AllocPolicy where
arbitrary = elements [minBound..maxBound]
instance Arbitrary Types.DiskTemplate where
arbitrary = elements [minBound..maxBound]
-- * Actual tests
-- ** Utils tests
......@@ -956,3 +963,22 @@ testLoader =
, run prop_Loader_assignIndices
, run prop_Loader_mergeData
]
-- ** Types tests
prop_AllocPolicy_serialisation apol =
case Types.apolFromString (Types.apolToString apol) of
Types.Ok p -> printTestCase ("invalid deserialisation " ++ show p) $
p == apol
Types.Bad s -> printTestCase ("failed to deserialise: " ++ s) False
prop_DiskTemplate_serialisation dt =
case Types.dtFromString (Types.dtToString dt) of
Types.Ok p -> printTestCase ("invalid deserialisation " ++ show p) $
p == dt
Types.Bad s -> printTestCase ("failed to deserialise: " ++ s) False
testTypes =
[ run prop_AllocPolicy_serialisation
, run prop_DiskTemplate_serialisation
]
......@@ -104,7 +104,7 @@ data AllocPolicy
-- last-resort, after the preferred groups
| AllocUnallocable -- ^ This group must not be used for new
-- allocations
deriving (Show, Read, Eq, Ord)
deriving (Show, Read, Eq, Ord, Enum, Bounded)
-- | Convert a string to an alloc policy.
apolFromString :: (Monad m) => String -> m AllocPolicy
......@@ -185,7 +185,7 @@ data DiskTemplate = DTDiskless
| DTPlain
| DTBlock
| DTDrbd8
deriving (Show, Read, Eq)
deriving (Show, Read, Eq, Enum, Bounded)
-- | Converts a DiskTemplate to String
dtToString :: DiskTemplate -> String
......
......@@ -110,6 +110,7 @@ allTests =
, ("OpCodes", fast, testOpCodes)
, ("Jobs", fast, testJobs)
, ("Loader", fast, testLoader)
, ("Types", fast, testTypes)
, ("Cluster", slow, testCluster)
]
......
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